features.install 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the features module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function features_install() {
  10. _features_install_menu();
  11. db_update('system')
  12. ->fields(array('weight' => 20))
  13. ->condition('name', 'features')
  14. ->condition('type', 'module')
  15. ->execute();
  16. }
  17. /**
  18. * Implements hook_uninstall().
  19. */
  20. function features_uninstall() {
  21. variable_del('features_codecache');
  22. variable_del('features_semaphore');
  23. variable_del('features_ignored_orphans');
  24. db_delete('menu_custom')
  25. ->condition('menu_name', 'features')
  26. ->execute();
  27. db_delete('menu_links')
  28. ->condition('module', 'features')
  29. ->execute();
  30. }
  31. /**
  32. * Create menu. See menu.install for an example.
  33. */
  34. function _features_install_menu() {
  35. if (db_table_exists('menu_custom') && !db_query("SELECT menu_name FROM {menu_custom} WHERE menu_name = :menu_name", array(':menu_name' => 'features'))->fetchField()) {
  36. $t = get_t();
  37. $id = db_insert('menu_custom')
  38. ->fields(array(
  39. 'menu_name' => 'features',
  40. 'title' => $t('Features'),
  41. 'description' => $t('Menu items for any enabled features.'),
  42. ))
  43. ->execute();
  44. }
  45. }
  46. /**
  47. * Update 6100: Set module on all feature node types to 'features'.
  48. * This update can be re-run as needed to repair any node types that are not
  49. * removed after disabling the associated feature.
  50. *
  51. * Any feature implementing a node component that was exported prior to this
  52. * version of the features.module will need to have its 'module' declaration
  53. * in hook_node_info() changed from 'node' to 'features'.
  54. */
  55. function features_update_6100() {
  56. $ret = array();
  57. foreach (features_get_features(NULL, TRUE) as $feature) {
  58. if (module_exists($feature->name) && $types = module_invoke($feature->name, 'node_info')) {
  59. foreach ($types as $type => $type_data) {
  60. $sql = "SELECT COUNT(*) FROM {node_type} WHERE module = 'node' AND type = '%s'";
  61. // Only update if the hook_node_info type's module is 'features' and the db type's
  62. // module is 'node'.
  63. if (($type_data['module'] == 'features') && db_query($sql, $type)->fetchField()) {
  64. $ret[] = update_sql("UPDATE {node_type} SET module = 'features' WHERE type = '$type'");
  65. }
  66. }
  67. }
  68. }
  69. return $ret;
  70. }
  71. /**
  72. * Update 6101: Set codestate signature for all features.
  73. *
  74. * This update generates a codestate for all feature/component pairs which
  75. * have been installed prior to this version of Features. This prevents
  76. * automatic rebuilds from occurring against any rebuildable components
  77. * that have been overridden.
  78. */
  79. function features_update_6101() {
  80. // Ensure all of our own API functions still exist in in this version
  81. // of Features. It's possible that the "future me" will not have these
  82. // functions, so I should check.
  83. module_load_include('inc', 'features', "features.export");
  84. $functions = array(
  85. 'features_include',
  86. 'features_hook',
  87. 'features_get_components',
  88. 'features_get_features',
  89. 'features_get_signature',
  90. 'features_set_signature',
  91. );
  92. $doit = TRUE;
  93. foreach ($functions as $function) {
  94. $doit = $doit && function_exists($function);
  95. }
  96. if ($doit) {
  97. features_include();
  98. $features = array_keys(features_get_features(NULL, TRUE));
  99. $components = array_keys(features_get_components());
  100. foreach ($features as $feature) {
  101. if (module_exists($feature)) {
  102. foreach ($components as $component) {
  103. if (features_hook($component, 'features_rebuild') && features_get_signature('cache', $feature, $component) === FALSE) {
  104. features_set_signature($feature, $component, -1);
  105. }
  106. }
  107. }
  108. }
  109. }
  110. return array();
  111. }