features.install 4.1 KB

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