You are here

function backup_migrate_update_7300 in Backup and Migrate 8.3

Same name and namespace in other branches
  1. 7.3 backup_migrate.install \backup_migrate_update_7300()

Uninstall backup migrate files if it's installed

File

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

Code

function backup_migrate_update_7300() {
  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',
    ),
  );
  if (!db_table_exists('backup_migrate_sources')) {
    db_create_table('backup_migrate_sources', $schema['backup_migrate_sources']);
  }

  // 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',
    ));
  }
}