features.install 4.5 KB

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