| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Deploy command implementation
|
| 5 |
*
|
| 6 |
* This command when called will
|
| 7 |
* 1. Extract the backup that is being deployed to the target folder in the sites directory.
|
| 8 |
* 2. Import the drushrc.php details.
|
| 9 |
* 3. Do some diagnostics to make sure all the needed packages are available.
|
| 10 |
* 4. Create a new database, belonging to the site's user, and import the database dump.
|
| 11 |
* 5. Regenerate configuration files to show new db settings.
|
| 12 |
* 6. Call the drush 'updatedb' command to update the database if neccesary.
|
| 13 |
* 7. Update the file paths to the new sites directory.
|
| 14 |
* 8. Rebuild the site's package manifest.
|
| 15 |
* 9. Save the new drushrc.php with the newly generated settings.
|
| 16 |
*/
|
| 17 |
|
| 18 |
/**
|
| 19 |
* Make sure we have a valid site being deployd, and that the file being deployd from exists
|
| 20 |
*/
|
| 21 |
function drush_provision_drupal_provision_deploy_validate($url = null, $backup_file = null) {
|
| 22 |
_provision_drupal_url_required();
|
| 23 |
|
| 24 |
$exists = provision_path("exists", $backup_file, TRUE,
|
| 25 |
dt("Deploying site from @path"),
|
| 26 |
dt("Could not find backup file @path"),
|
| 27 |
'PROVISION_BACKUP_NOT_FOUND');
|
| 28 |
if ($exists) {
|
| 29 |
drush_set_option('backup_file', $backup_file);
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
/**
|
| 34 |
* Make a backup before making any changes, and add extract the file we are restoring from
|
| 35 |
*/
|
| 36 |
function drush_provision_drupal_pre_provision_deploy($url, $backup_file) {
|
| 37 |
// the url is likely to have changed in the deployment
|
| 38 |
drush_set_option('site_url', $url);
|
| 39 |
$extracted = provision_path("extract", drush_get_option('backup_file'), drush_get_option('sites_path') ."/$url",
|
| 40 |
dt('Successfully extracted the contents of @path'),
|
| 41 |
dt('Failed to extract the contents of @path'),
|
| 42 |
'PROVISION_BACKUP_EXTRACTION_FAILED');
|
| 43 |
if ($extracted) {
|
| 44 |
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
|
| 45 |
|
| 46 |
$site_packages = drush_get_option('packages', array(), 'site');
|
| 47 |
$profiles = array_keys($site_packages['profiles']);
|
| 48 |
$profile = $profiles[0];
|
| 49 |
|
| 50 |
$drupal_packages = drush_get_option('packages', array(), 'drupal');
|
| 51 |
|
| 52 |
$merged_modules = array_merge($drupal_packages['base']['modules'], $drupal_packages['profiles'][$profile]['modules']);
|
| 53 |
foreach ($site_packages['modules'] as $name => $module) {
|
| 54 |
if ($module['status'] == 1) {
|
| 55 |
if (!array_key_exists($name, $merged_modules)) {
|
| 56 |
drush_log(dt("Could not find a version of the !name module", array('!name' => $name)), 'warning');
|
| 57 |
}
|
| 58 |
else {
|
| 59 |
if (($merged_modules[$name]['schema_version'] > 0) && ($module['schema_version'] > $merged_modules[$name]['schema_version'])) {
|
| 60 |
drush_set_error('PROVISION_SCHEMA_UPGRADE_FAILURE',
|
| 61 |
dt("The version of the !name module found on this platform has a lower Schema version than the one the site has installed",
|
| 62 |
array('!name' => $name)));
|
| 63 |
}
|
| 64 |
else {
|
| 65 |
drush_log(dt("Found a valid version of the !name module with schema version !schema_version",
|
| 66 |
array('!name' => $name, '!schema_version' => $merged_modules[$name]['schema_version'])));
|
| 67 |
}
|
| 68 |
}
|
| 69 |
}
|
| 70 |
}
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
/**
|
| 75 |
* Remove the extracted site directory
|
| 76 |
*/
|
| 77 |
function drush_provision_drupal_pre_provision_deploy_rollback($url) {
|
| 78 |
if ($site_root = drush_get_context('DRUSH_DRUPAL_SITE_ROOT')) {
|
| 79 |
_provision_recursive_delete($site_root);
|
| 80 |
}
|
| 81 |
}
|
| 82 |
|
| 83 |
function drush_provision_drupal_provision_deploy($url) {
|
| 84 |
_provision_drupal_maintain_aliases($url);
|
| 85 |
}
|
| 86 |
|
| 87 |
|
| 88 |
function drush_provision_drupal_post_provision_deploy($url) {
|
| 89 |
_provision_drupal_create_settings_file($url);
|
| 90 |
// call the drush updatedb command.
|
| 91 |
drush_backend_invoke("updatedb", array('uri' => "http://$url"));
|
| 92 |
// We should be able to fully load Drupal now.
|
| 93 |
if (drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
|
| 94 |
drush_include_engine('drupal', 'deploy');
|
| 95 |
drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site');
|
| 96 |
_provision_drupal_rebuild_caches();
|
| 97 |
}
|
| 98 |
}
|