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

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

7 8
function drush_db_pre_provision_restore() {
  provision_service('db')->create_site_database();
9 10
}

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


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

  $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.
32
function drush_db_post_provision_restore() {
drumm's avatar
drumm committed
33
  provision_service('file')->unlink(d()->root . '/sites/' . d()->uri . '/database.sql')
34 35
    ->succeed('Removed dump file @path after restoring from it')
    ->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR');
36

37
  provision_service('db')->destroy_site_database();
38 39 40 41 42 43 44 45 46 47 48

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