locationmap.install 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the locationmap module.
  5. *
  6. */
  7. /**
  8. * Rename 5.x-1.0 permission "admin gmaplocation", 6.x-1.0 permission
  9. * "edit gmaplocation", and 6.x-2.0 permission "administer gmaplocation"
  10. * to "Administer location map".
  11. */
  12. function locationmap_update_104() {
  13. // Location map module is the Drupal 7 successor to gmaplocation module.
  14. // If role permissions exist from gmaplocation, these are updated for Location map.
  15. // Set up the $replace array which holds strings both the old and new permissions.
  16. $replace = array(
  17. 'admin gmaplocation' => 'administer locationmap',
  18. 'edit gmaplocation' => 'administer locationmap',
  19. 'administer gmaplocation' => 'administer locationmap'
  20. );
  21. // Loop over all the changes, performing necessary updates.
  22. foreach ($replace as $old_permission => $new_permission) {
  23. db_update('role_permission')
  24. ->fields(array('permission' => $new_permission, 'module' => 'locationmap'))
  25. ->condition('rid', 3, '<>')
  26. ->condition('permission', $old_permission)
  27. ->execute();
  28. }
  29. // Update any URL aliases previously set for gmaplocation to point to locationmap.
  30. db_update('url_alias')
  31. ->fields(array('source' => 'locationmap'))
  32. ->condition('source', 'gmaplocation')
  33. ->execute();
  34. // Create locationmap variables. If gmaplocation variables exist, set to those values.
  35. variable_set('locationmap_address', variable_get('gmaplocation_address'));
  36. variable_set('locationmap_block_text_top', variable_get('gmaplocation_block_text_top'));
  37. variable_set('locationmap_body', variable_get('gmaplocation_body'));
  38. variable_set('locationmap_footer', variable_get('gmaplocation_footer'));
  39. variable_set('locationmap_height', variable_get('gmaplocation_height'));
  40. variable_set('locationmap_info', variable_get('gmaplocation_info'));
  41. variable_set('locationmap_key', variable_get('gmaplocation_key'));
  42. variable_set('locationmap_lat', variable_get('gmaplocation_lat'));
  43. variable_set('locationmap_lng', variable_get('gmaplocation_lng'));
  44. variable_set('locationmap_title', variable_get('gmaplocation_title'));
  45. variable_set('locationmap_type', variable_get('gmaplocation_type'));
  46. variable_set('locationmap_width', variable_get('gmaplocation_width'));
  47. variable_set('locationmap_zoom', variable_get('gmaplocation_zoom'));
  48. // Remove redundant gmaplocation variables.
  49. variable_del('gmaplocation_address');
  50. variable_del('gmaplocation_block_text_top');
  51. variable_del('gmaplocation_body');
  52. variable_del('gmaplocation_footer');
  53. variable_del('gmaplocation_height');
  54. variable_del('gmaplocation_info');
  55. variable_del('gmaplocation_key');
  56. variable_del('gmaplocation_lat');
  57. variable_del('gmaplocation_lng');
  58. variable_del('gmaplocation_title');
  59. variable_del('gmaplocation_type');
  60. variable_del('gmaplocation_width');
  61. variable_del('gmaplocation_zoom');
  62. // hook_update_N() no longer returns a $ret array. Instead, return
  63. // nothing or a translated string indicating the update ran successfully.
  64. // See http://drupal.org/node/224333#update_sql.
  65. return t('Upgraded any legacy permissions and variables from gmaplocation module to locationmap.');
  66. }
  67. /**
  68. * Change maps API v2 variables to v3 values.
  69. * Unset the API key var, as it's not required any more.
  70. */
  71. function locationmap_update_105() {
  72. $locationmap_type = variable_get('locationmap_type', '');
  73. // Only do anything if this is set
  74. if ($locationmap_type) {
  75. // Maps old values to new values:
  76. $locationmap_type_new = array(
  77. 'G_NORMAL_MAP' => 'google.maps.MapTypeId.ROADMAP',
  78. 'G_SATELLITE_MAP' => 'google.maps.MapTypeId.SATELLITE',
  79. 'G_HYBRID_MAP' => 'google.maps.MapTypeId.HYBRID',
  80. );
  81. // Only reset this if it's a value we can translate:
  82. if (isset($locationmap_type_new[$locationmap_type])) {
  83. variable_set('locationmap_type', $locationmap_type_new[$locationmap_type]);
  84. }
  85. }
  86. // We don't need this any more
  87. variable_del('locationmap_key');
  88. }
  89. /**
  90. * Implementation of hook_uninstall.
  91. * @see http://drupal.org/node/1354
  92. */
  93. function locationmap_uninstall() {
  94. variable_del('locationmap_address');
  95. variable_del('locationmap_block_text_top');
  96. variable_del('locationmap_body');
  97. variable_del('locationmap_footer');
  98. variable_del('locationmap_height');
  99. variable_del('locationmap_info');
  100. variable_del('locationmap_key');
  101. variable_del('locationmap_lat');
  102. variable_del('locationmap_lng');
  103. variable_del('locationmap_title');
  104. variable_del('locationmap_type');
  105. variable_del('locationmap_width');
  106. variable_del('locationmap_zoom');
  107. }