You are here

function skinr_context_update_7200 in Skinr 7.2

Same name and namespace in other branches
  1. 8.2 skinr_context/skinr_context.install \skinr_context_update_7200()

Add machine names to Skinr Configuration Groups.

File

skinr_context/skinr_context.install, line 144
Contains install, update, and uninstall functions for Skinr Context.

Code

function skinr_context_update_7200() {
  db_change_field('skinr_groups', 'gid', 'gid', array(
    'type' => 'varchar',
    'length' => 96,
    'not null' => TRUE,
    'description' => 'Primary Key: Unique machine readable name for this skin configuration group.',
  ));
  db_drop_index('skinr_group_skins', 'gid');
  db_change_field('skinr_group_skins', 'gid', 'gid', array(
    'type' => 'varchar',
    'length' => 96,
    'not null' => TRUE,
    'description' => 'The skin configuration group ID.',
  ));
  db_add_index('skinr_group_skins', 'gid', array(
    'gid',
  ));

  // Generate a machine name for all existing groups.
  $machine_names = array();
  $result = db_query("SELECT * FROM {skinr_groups}");
  foreach ($result as $group) {
    $suggested_machine_name = $group->module . ':' . $group->element . ':' . strtolower($group->title);
    $machine_name = $suggested_machine_name;
    while (isset($machine_names[$machine_name])) {
      $machine_name = $suggested_machine_name . '_' . $i++;
    }
    $machine_names[$machine_name] = $group->gid;
  }
  foreach ($machine_names as $machine_name => $gid) {
    db_update('skinr_groups')
      ->fields(array(
      'gid' => $machine_name,
    ))
      ->condition('gid', $gid)
      ->execute();
    db_update('skinr_group_skins')
      ->fields(array(
      'gid' => $machine_name,
    ))
      ->condition('gid', $gid)
      ->execute();
  }
}