migrate.provision.inc 3.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php

/**
 * Restore command implementation
 *
 * This command when called will 
 *   1. Make a backup of the current site, before modifications are made.
 *   2. Temporarily disable the site by causing apache to redirect to a help page. Restarting apache is required.
 *   3. Extract the backup that is being migrated to to a temporary folder in the sites directory.
 *   4. Create a new database, belonging to the site's user, and switch it around with the current site's database.
 *   5. Import the old database and site.php details.
 *   6. Switch around the sites directory of the current site and the backup being migrated.
 *   7. Regenerate configuration files.
 *   8. TODO: diagnostic to test that everything is ok?
 *   9. Remove the temporary redirect and restart apache so the previous site is available again.
 *   10. Remove the extranuous db and duplicate site directory.
 *
 * If at any time an error occurs, before step 9. It should reverse all the changes it has made,
 * and leave the current site directory and database in the right place, and remove all cruft that
 * was created by this process.
 */

/**
 * Make sure we have a valid site being migrated, and that the file being migrated from exists
 */
26
function drush_provision_drupal_provision_migrate_validate($platform = null) {
27
  drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
28 29 30 31 32
}

/**
 * Make a backup before making any changes, and add extract the file we are restoring from
 */
33
function drush_provision_drupal_pre_provision_migrate($platform = null) {
34 35 36 37
  /* Set offline mode to true and re-generate the settings.php. This will write a 
   * $conf['site_offline'] = 1; to the settings.php
   */
  drush_log(dt("Putting site under maintenance"));
38
  drush_set_option('site_offline', 1);
39
  _provision_drupal_create_settings_file();
40
  drush_invoke('provision-backup');
41 42 43 44
}

/**
 * Remove the extracted site directory
45
 * Restore the vhost conf per the original platform
46
 */
47
function drush_provision_drupal_pre_provision_migrate_rollback($platform = null) {
48 49
  // Set site_offline to false and regenerate the config 
  drush_log(dt("Bringing site out of maintenance"));
Adrian Rossouw's avatar
Adrian Rossouw committed
50
  drush_set_option('site_offline', 0);
51
  _provision_drupal_create_settings_file();
52 53 54
  $success =  provision_service('file')->unlink(drush_get_option('backup_file'))
    ->succeed('Removed unused migration site package')
    ->fail('Could not remove unused migration site package');
55
  provision_service('http')->create_site_config();
56
  _provision_apache_restart_apache();
57 58 59 60 61
}

/**
 * Switch the migrate directories around now that we have the new db installed
 */
62 63
function drush_provision_drupal_provision_migrate($platform) {
  drush_backend_invoke('provision-deploy', array(drush_get_option('backup_file'), 'root' => $platform, 
drumm's avatar
drumm committed
64
    'web_host' => drush_get_option('web_host'), 
65
    'db_host' => drush_get_option('db_host'), 'profile' => drush_get_option('profile')));
66 67 68 69 70 71
}


/**
 * Delete the old site directory and recreate the settings file
 */
72
function drush_provision_drupal_post_provision_migrate() {
73
  drush_set_option('installed', FALSE);
74 75 76
  // we remove the aliases even if redirection is enabled as a precaution
  // if redirection is enabled, keep silent about errors
  _provision_drupal_delete_aliases(drush_get_option('aliases', array()), drush_get_option('redirection'));
drumm's avatar
drumm committed
77
  _provision_recursive_delete(d()->root . '/sites/' . d()->uri);
78 79 80
}