You are here

function locationmap_update_104 in Location Map 7.2

Same name and namespace in other branches
  1. 8.2 locationmap.install \locationmap_update_104()
  2. 7 locationmap.install \locationmap_update_104()

Rename 5.x-1.0 permission "admin gmaplocation", 6.x-1.0 permission "edit gmaplocation", and 6.x-2.0 permission "administer gmaplocation" to "Administer location map".

File

./locationmap.install, line 13
Install, update and uninstall functions for the locationmap module.

Code

function locationmap_update_104() {

  // Location map module is the Drupal 7 successor to gmaplocation module.
  // If role permissions exist from gmaplocation, these are updated for Location map.
  // Set up the $replace array which holds strings both the old and new permissions.
  $replace = array(
    'admin gmaplocation' => 'administer locationmap',
    'edit gmaplocation' => 'administer locationmap',
    'administer gmaplocation' => 'administer locationmap',
  );

  // Loop over all the changes, performing necessary updates.
  foreach ($replace as $old_permission => $new_permission) {
    db_update('role_permission')
      ->fields(array(
      'permission' => $new_permission,
      'module' => 'locationmap',
    ))
      ->condition('rid', 3, '<>')
      ->condition('permission', $old_permission)
      ->execute();
  }

  // Update any URL aliases previously set for gmaplocation to point to locationmap.
  db_update('url_alias')
    ->fields(array(
    'source' => 'locationmap',
  ))
    ->condition('source', 'gmaplocation')
    ->execute();

  // Create locationmap variables. If gmaplocation variables exist, set to those values.
  variable_set('locationmap_address', variable_get('gmaplocation_address'));
  variable_set('locationmap_block_text_top', variable_get('gmaplocation_block_text_top'));
  variable_set('locationmap_body', variable_get('gmaplocation_body'));
  variable_set('locationmap_footer', variable_get('gmaplocation_footer'));
  variable_set('locationmap_height', variable_get('gmaplocation_height'));
  variable_set('locationmap_info', variable_get('gmaplocation_info'));
  variable_set('locationmap_key', variable_get('gmaplocation_key'));
  variable_set('locationmap_lat', variable_get('gmaplocation_lat'));
  variable_set('locationmap_lng', variable_get('gmaplocation_lng'));
  variable_set('locationmap_title', variable_get('gmaplocation_title'));
  variable_set('locationmap_type', variable_get('gmaplocation_type'));
  variable_set('locationmap_width', variable_get('gmaplocation_width'));
  variable_set('locationmap_zoom', variable_get('gmaplocation_zoom'));

  // Remove redundant gmaplocation variables.
  variable_del('gmaplocation_address');
  variable_del('gmaplocation_block_text_top');
  variable_del('gmaplocation_body');
  variable_del('gmaplocation_footer');
  variable_del('gmaplocation_height');
  variable_del('gmaplocation_info');
  variable_del('gmaplocation_key');
  variable_del('gmaplocation_lat');
  variable_del('gmaplocation_lng');
  variable_del('gmaplocation_title');
  variable_del('gmaplocation_type');
  variable_del('gmaplocation_width');
  variable_del('gmaplocation_zoom');

  // hook_update_N() no longer returns a $ret array. Instead, return
  // nothing or a translated string indicating the update ran successfully.
  // See http://drupal.org/node/224333#update_sql.
  return t('Upgraded any legacy permissions and variables from gmaplocation module to locationmap.');
}