hierarchical_select.install 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the Hierarchical Select module.
  5. */
  6. /**
  7. * Implements hook_uninstall().
  8. */
  9. function hierarchical_select_uninstall() {
  10. db_delete('variable')
  11. ->condition('name', 'hs_config_%', 'LIKE')
  12. ->execute();
  13. db_delete('variable')
  14. ->condition('name', 'hierarchical_select_%', 'LIKE')
  15. ->execute();
  16. }
  17. //----------------------------------------------------------------------------
  18. // Updates.
  19. /**
  20. * Update Hierarchical Select to Drupal 7. Basically remove a lot of cruft.
  21. */
  22. function hierarchical_select_update_7001() {
  23. // Drop Hierarchical Select's cache table, which is now obsolete.
  24. db_drop_table('cache_hierarchical_select');
  25. // Undo Hierarchical Select module weight changes, because they're no longer
  26. // necessary.
  27. db_update('system')
  28. ->fields(array(
  29. 'weight' => 0,
  30. ))
  31. ->condition('name', 'hierarchical_select')
  32. ->execute();
  33. }
  34. /**
  35. * Update Hierarchical Select config to support improved "entity count".
  36. */
  37. function hierarchical_select_update_7002() {
  38. module_load_include('inc', 'hierarchical_select', 'includes/common');
  39. // Retrieve all information items.
  40. $info_items = array();
  41. foreach (module_implements('hierarchical_select_config_info') as $module) {
  42. $info_items = array_merge_recursive($info_items, module_invoke($module, 'hierarchical_select_config_info'));
  43. }
  44. foreach ($info_items as $info_item) {
  45. // Load config.
  46. $config = hierarchical_select_common_config_get($info_item['config_id']);
  47. // Move old settings to new location.
  48. $config['entity_count'] = array(
  49. 'enabled' => $config['entity_count'],
  50. 'require_entity' => $config['require_entity'],
  51. );
  52. // Remove old setting.
  53. unset($config['require_entity']);
  54. // Add entity types settings.
  55. $entity_info = entity_get_info();
  56. foreach ($entity_info as $entity => $entity_info) {
  57. if (!empty($entity_info['bundles']) && $entity_info['fieldable'] === TRUE) {
  58. foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
  59. if ($entity == 'node') {
  60. $config['entity_count']['settings']['entity_types'][$entity]['count_' . $entity][$bundle] = $bundle;
  61. }
  62. else {
  63. $config['entity_count']['settings']['entity_types'][$entity]['count_' . $entity][$bundle] = 0;
  64. }
  65. }
  66. }
  67. }
  68. // Save new config.
  69. hierarchical_select_common_config_set($info_item['config_id'], $config);
  70. }
  71. }