You are here

function backup_migrate_update_7305 in Backup and Migrate 7.3

Fix schema mismatch after upgrade.

File

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

Code

function backup_migrate_update_7305() {

  // Fix the 'machine_name' table fields.
  $field_spec = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '0',
  );
  foreach (array(
    'backup_migrate_profiles',
    'backup_migrate_destinations',
    'backup_migrate_sources',
    'backup_migrate_schedules',
  ) as $table) {
    if (!db_field_exists($table, 'machine_name')) {
      try {
        db_add_field($table, 'machine_name', $field_spec);
      } catch (\Exception $e) {
        db_change_field($table, 'machine_name', 'machine_name', $field_spec);
      }
    }
    else {
      db_change_field($table, 'machine_name', 'machine_name', $field_spec);
    }
  }

  // Fix the 'cron' table field.
  $field_spec = array(
    'type' => 'varchar',
    'length' => 32,
    'not null' => TRUE,
    'default' => 'builtin',
  );
  if (!db_field_exists('backup_migrate_schedules', 'cron')) {
    try {
      db_add_field('backup_migrate_schedules', 'cron', $field_spec);
    } catch (\Exception $e) {
      db_change_field('backup_migrate_schedules', 'cron', 'cron', $field_spec);
    }
  }
  else {
    db_change_field('backup_migrate_schedules', 'cron', 'cron', $field_spec);
  }
}