features.install 3.8 KB

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