You are here

function backup_migrate_update_2005 in Backup and Migrate 6.3

Same name and namespace in other branches
  1. 8.2 backup_migrate.install \backup_migrate_update_2005()
  2. 8.3 backup_migrate.install \backup_migrate_update_2005()
  3. 6.2 backup_migrate.install \backup_migrate_update_2005()
  4. 7.3 backup_migrate.install \backup_migrate_update_2005()
  5. 7.2 backup_migrate.install \backup_migrate_update_2005()

Change the default database id to something friendlier 2009-08-08

File

./backup_migrate.install, line 418
Install hooks for Backup and Migrate.

Code

function backup_migrate_update_2005() {
  require_once './' . drupal_get_path('module', 'backup_migrate') . '/includes/crud.inc';
  require_once './' . drupal_get_path('module', 'backup_migrate') . '/includes/profiles.inc';
  $ret = array();

  // Change the destination ids of the defined database sources mostly to make using them with drush friendlier.
  // Change the db_url:default id to simply 'db'
  $ret[] = update_sql("UPDATE {backup_migrate_profiles} SET source_id = 'db' WHERE source_id = 'db_url:default'");
  $ret[] = update_sql("UPDATE {backup_migrate_schedules} SET destination_id = 'db' WHERE destination_id = 'db_url:default'");

  // Change the defined db keys from db_url:key to db:key.
  $ret[] = update_sql("UPDATE {backup_migrate_profiles} SET source_id = REPLACE(source_id, 'db_url:', 'db:')");
  $ret[] = update_sql("UPDATE {backup_migrate_schedules} SET destination_id = REPLACE(destination_id, 'db_url:', 'db:')");

  // Add the source field to the schedule
  if (!db_column_exists('backup_migrate_schedules', 'source_id')) {
    db_add_field($ret, 'backup_migrate_schedules', 'source_id', array(
      'description' => t('The db source to backup from.'),
      'type' => 'varchar',
      'length' => 255,
      'default' => 'db',
      'not null' => TRUE,
    ));
  }

  // Copy source data from profiles to schedules.
  $result = db_query('SELECT p.source_id, s.schedule_id FROM {backup_migrate_schedules} s LEFT JOIN {backup_migrate_profiles} p ON s.profile_id = p.profile_id');
  while ($schedule = db_fetch_array($result)) {
    if (!$schedule['source_id']) {
      $schedule['source_id'] = 'db';
    }
    $ret[] = update_sql("UPDATE {backup_migrate_schedules} SET source_id = '" . $schedule['source_id'] . "' WHERE schedule_id = '" . $schedule['profile_id'] . "'");
  }
  if (db_column_exists('backup_migrate_profiles', 'source_id')) {
    db_drop_field($ret, 'backup_migrate_profiles', 'source_id');
  }

  // Copy the no-data and exclude tables settings into the 'filter' field.
  $result = db_query('SELECT * FROM {backup_migrate_profiles}');
  while ($item = db_fetch_array($result)) {
    if (isset($item['nodata_tables']) && isset($item['exclude_tables'])) {
      $profile = backup_migrate_get_profile($item['profile_id']);
      $profile->filters['nodata_tables'] = unserialize($item['nodata_tables']);
      $profile->filters['exclude_tables'] = unserialize($item['exclude_tables']);
      $profile
        ->save();
    }
  }
  if (db_column_exists('backup_migrate_profiles', 'nodata_tables')) {
    db_drop_field($ret, 'backup_migrate_profiles', 'nodata_tables');
  }
  if (db_column_exists('backup_migrate_profiles', 'exclude_tables')) {
    db_drop_field($ret, 'backup_migrate_profiles', 'exclude_tables');
  }
  return $ret;
}