features.install 4.0 KB

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