You are here

function backup_migrate_update_6300 in Backup and Migrate 6.3

Uninstall backup migrate files if it's installed

File

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

Code

function backup_migrate_update_6300() {
  $ret = array();
  if (module_exists('backup_migrate_files')) {
    module_disable(array(
      'backup_migrate_files',
    ));
    $ret[] = array(
      'success' => true,
      'query' => 'Disabled the Backup and Migrate Files module',
    );
  }
  if (module_exists('nodesquirrel')) {
    module_disable(array(
      'nodesquirrel',
    ));
    $ret[] = array(
      'success' => true,
      'query' => 'Disabled the NodeSquirrel module',
    );
  }

  // Add sources to the schema.
  $schema['backup_migrate_sources'] = array(
    'fields' => array(
      'source_id' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '0',
        'description' => t('The primary identifier for a source.'),
      ),
      'name' => array(
        'description' => t('The name of the source.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => t('The type of the source.'),
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ),
      'location' => array(
        'description' => t('The the location string of the source.'),
        'type' => 'text',
        'not null' => TRUE,
      ),
      'settings' => array(
        'description' => t('Other settings for the source.'),
        'type' => 'text',
        'not null' => TRUE,
        'serialize' => TRUE,
        'serialized default' => 'a:0:{}',
      ),
    ),
    'primary key' => array(
      'source_id',
    ),
  );
  $ret = array();
  if (!db_table_exists('backup_migrate_sources')) {
    db_create_table($ret, 'backup_migrate_sources', $schema['backup_migrate_sources']);
  }
  if (db_column_exists('backup_migrate_schedules', 'last_run')) {
    db_drop_field($ret, 'backup_migrate_schedules', 'last_run');
  }

  // Move custom destinations to sources.
  $result = db_query("SELECT * FROM {backup_migrate_destinations} WHERE type in ('filesource', 'db')", array(), array(
    'fetch' => PDO::FETCH_ASSOC,
  ));
  foreach ($result as $item) {
    $item['source_id'] = $item['destination_id'];
    drupal_write_record('backup_migrate_source', $item);
  }

  // Change 'destination' settings to 'source' settings
  $result = db_query('SELECT * FROM {backup_migrate_profiles}', array(), array(
    'fetch' => PDO::FETCH_ASSOC,
  ));
  foreach ($result as $item) {
    $item['filters'] = unserialize($item['filters']);
    $item['filters']['sources'] = $item['filters']['destinations'];
    unset($item['filters']['destinations']);
    drupal_write_record('backup_migrate_profiles', $item, array(
      'profile_id',
    ));
  }
  return $ret;
}