restore.provision.inc 1.91 KB
Newer Older
1 2
<?php

3 4
function drush_db_provision_restore_validate() {
  provision_service('db')->connect();
5 6
}

7
function drush_db_pre_provision_restore() {
Adrian Rossouw's avatar
Adrian Rossouw committed
8 9
  drush_set_option('old_db_creds', provision_service('db')->fetch_site_credentials());

10
  provision_service('db')->create_site_database();
11 12
}

13
function drush_db_provision_restore() {
Adrian Rossouw's avatar
Adrian Rossouw committed
14
  provision_service('db')->import_site_database(d()->root . '/sites/' . d()->uri . '.restore/database.sql');
15 16 17
}


18 19
function drush_db_pre_provision_restore_rollback() {
  provision_service('db')->destroy_site_database();
20 21 22 23 24 25 26 27 28 29 30 31 32 33

  $keys = array('db_name', 'db_passwd', 'db_user', 'db_host');

  //Restore the original database credentials of the site.
  // They were never truly lost, but the options in the 'process' context
  // were overriding them. By unsetting the temporary options, the originals
  // are automatically restored.
  foreach ($keys as $key) {
    drush_unset_option($key, 'process');
  }
}

// Rollback doesn't apply here yet. Unless we trigger a restore of the first dump
// made. Which could go on infinitely if something is really long.
34
function drush_db_post_provision_restore() {
drumm's avatar
drumm committed
35
  provision_service('file')->unlink(d()->root . '/sites/' . d()->uri . '/database.sql')
36 37
    ->succeed('Removed dump file @path after restoring from it')
    ->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR');
38

Adrian Rossouw's avatar
Adrian Rossouw committed
39
  provision_service('db')->destroy_site_database(drush_get_option('old_db_creds'));
40 41 42 43 44 45 46 47 48 49 50

  // TODO - test this .. it's probably horribly broken .. deleting the newly restored db instead of the old one.

  // The new database credentials will be saved against the site now.
  drush_set_option('db_name', drush_get_option('db_name'), 'site');
  drush_set_option('db_type', drush_get_option('db_type'), 'site');
  drush_set_option('db_user', drush_get_option('db_user'), 'site');
  drush_set_option('db_host', drush_get_option('db_host'), 'site');
  drush_set_option('db_passwd', drush_get_option('db_passwd'), 'site');
}