| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Restore command implementation
|
| 5 |
*
|
| 6 |
* This command when called will
|
| 7 |
* 1. Make a backup of the current site, before modifications are made.
|
| 8 |
* 2. Temporarily disable the site by causing apache to redirect to a help page. Restarting apache is required.
|
| 9 |
* 3. Extract the backup that is being restored to to a temporary folder in the sites directory.
|
| 10 |
* 4. Create a new database, belonging to the site's user, and switch it around with the current site's database.
|
| 11 |
* 5. Import the old database and site.php details.
|
| 12 |
* 6. Switch around the sites directory of the current site and the backup being restored.
|
| 13 |
* 7. Regenerate configuration files.
|
| 14 |
* 8. TODO: diagnostic to test that everything is ok?
|
| 15 |
* 9. Remove the temporary redirect and restart apache so the previous site is available again.
|
| 16 |
* 10. Remove the extranuous db and duplicate site directory.
|
| 17 |
*
|
| 18 |
* If at any time an error occurs, before step 9. It should reverse all the changes it has made,
|
| 19 |
* and leave the current site directory and database in the right place, and remove all cruft that
|
| 20 |
* was created by this process.
|
| 21 |
*/
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Make sure we have a valid site being restored, and that the file being restored from exists
|
| 25 |
*/
|
| 26 |
function drush_provision_drupal_provision_restore_validate($url = null, $restore_file = null) {
|
| 27 |
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
|
| 28 |
|
| 29 |
$exists = provision_path("exists", $restore_file, TRUE,
|
| 30 |
dt("Restoring site from @path"),
|
| 31 |
dt("Could not find backup file @path"),
|
| 32 |
'PROVISION_BACKUP_NOT_FOUND');
|
| 33 |
if ($exists) {
|
| 34 |
drush_set_option('restore_file', $restore_file);
|
| 35 |
}
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Make a backup before making any changes, and add extract the file we are restoring from
|
| 40 |
*/
|
| 41 |
function drush_provision_drupal_pre_provision_restore($url, $restore_file) {
|
| 42 |
drush_invoke('provision backup', $url);
|
| 43 |
|
| 44 |
provision_path("extract", drush_get_option('restore_file'), drush_get_option('sites_path') ."/$url.restore",
|
| 45 |
dt('Successfully extracted the contents of @path'),
|
| 46 |
dt('Failed to extract the contents of @path'),
|
| 47 |
'PROVISION_BACKUP_EXTRACTION_FAILED');
|
| 48 |
}
|
| 49 |
|
| 50 |
/**
|
| 51 |
* Remove the extracted site directory
|
| 52 |
*/
|
| 53 |
function drush_provision_drupal_pre_provision_restore_rollback($url) {
|
| 54 |
_provision_recursive_delete(drush_get_option('sites_path') ."/$url.restore");
|
| 55 |
}
|
| 56 |
|
| 57 |
/**
|
| 58 |
* Switch the restore directories around now that we have the new db installed
|
| 59 |
*/
|
| 60 |
function drush_provision_drupal_provision_restore($url) {
|
| 61 |
$old = drush_get_option('sites_path') ."/$url.restore";
|
| 62 |
$new = drush_get_option('sites_path') ."/$url";
|
| 63 |
provision_path("switch_paths", $old, $new ,
|
| 64 |
dt('Swapping out the @path and @confirm directories was successful.'),
|
| 65 |
dt('Swapping the @path and @confirm directories has failed.'),
|
| 66 |
'DRUSH_PERM_ERROR');
|
| 67 |
// make sure it has the latest site data available
|
| 68 |
_provision_drupal_create_settings_file($url);
|
| 69 |
provision_save_site_data($url);
|
| 70 |
}
|
| 71 |
|
| 72 |
// Luckily this is reversable =)
|
| 73 |
function drush_provision_drupal_provision_restore_rollback($url) {
|
| 74 |
drush_provision_drupal_provision_restore($url);
|
| 75 |
}
|
| 76 |
|
| 77 |
/**
|
| 78 |
* Delete the old site directory and recreate the settings file
|
| 79 |
*/
|
| 80 |
function drush_provision_drupal_post_provision_restore($url) {
|
| 81 |
_provision_recursive_delete(drush_get_option('sites_path') ."/$url.restore");
|
| 82 |
// This is the actual drupal provisioning requirements.
|
| 83 |
_provision_drupal_create_directories($url);
|
| 84 |
_provision_drupal_create_settings_file($url);
|
| 85 |
}
|
| 86 |
|
| 87 |
|