Commit 5b3da29a authored by Adrian Rossouw's avatar Adrian Rossouw

Committed path 11 from #736706 - thanks drumm

This gets rid of the path function, and introduces method chaining for the file service, which results in far cleaner code.
parent 15d8e38f
...@@ -6,8 +6,9 @@ function drush_db_pre_provision_backup($url = NULL) { ...@@ -6,8 +6,9 @@ function drush_db_pre_provision_backup($url = NULL) {
} }
function drush_db_pre_provision_backup_rollback($url = NULL) { function drush_db_pre_provision_backup_rollback($url = NULL) {
provision_service('file')->path("unlink", drush_get_option('sites_path') . "/$url/database.sql", TRUE, dt("Deleted mysql dump from sites directory"), provision_service('file')->unlink(drush_get_option('sites_path') . '/' . $url . '/database.sql')
dt("Could not delete mysql dump from sites directory")); ->succeed('Deleted mysql dump from sites directory')
->fail('Could not delete mysql dump from sites directory');
} }
function drush_db_post_provision_backup($url = NULL) { function drush_db_post_provision_backup($url = NULL) {
......
...@@ -194,14 +194,15 @@ class provisionService_db extends provisionService { ...@@ -194,14 +194,15 @@ class provisionService_db extends provisionService {
$creds = $this->fetch_site_credentials(); $creds = $this->fetch_site_credentials();
$exists = provision_service('file')->path("exists", $dump_file, TRUE, $exists = provision_service('file')->exists($dump_file)
dt('Found database dump at @path.'), ->succeed('Found database dump at @path.')
dt('No database dump was found at @path.'), ->fail('No database dump was found at @path.', 'PROVISION_DB_DUMP_NOT_FOUND')
'PROVISION_DB_DUMP_NOT_FOUND'); ->status();
if ($exists) { if ($exists) {
$readable = provision_service('file')->path("readable", $dump_file, TRUE, dt('Database dump at @path is readable'), $readable = provision_service('file')->readable($dump_file)
dt('The database dump at @path could not be read.'), ->succeed('Database dump at @path is readable')
'PROVISION_DB_DUMP_NOT_READABLE'); ->fail('The database dump at @path could not be read.', 'PROVISION_DB_DUMP_NOT_READABLE')
->status();
if ($readable) { if ($readable) {
$this->import_dump($dump_file, $creds); $this->import_dump($dump_file, $creds);
} }
......
...@@ -17,7 +17,7 @@ function drush_db_provision_deploy_rollback($url = NULL) { ...@@ -17,7 +17,7 @@ function drush_db_provision_deploy_rollback($url = NULL) {
// Rollback doesn't apply here yet. Unless we trigger a deploy of the first dump // Rollback doesn't apply here yet. Unless we trigger a deploy of the first dump
// made. Which could go on infinitely if something is really long. // made. Which could go on infinitely if something is really long.
function drush_db_post_provision_deploy($url) { function drush_db_post_provision_deploy($url) {
provision_service('file')->path('unlink', drush_get_option('sites_path') .'/'. $url .'/database.sql', TRUE, provision_service('file')->unlink(drush_get_option('sites_path') .'/'. $url .'/database.sql')
dt("Removed dump file @path after restoring from it"), ->succeed('Removed dump file @path after restoring from it')
dt("Could not remove dump file @path"), 'DRUSH_PERM_ERROR'); ->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR');
} }
...@@ -30,9 +30,9 @@ function drush_db_pre_provision_restore_rollback($url = NULL) { ...@@ -30,9 +30,9 @@ function drush_db_pre_provision_restore_rollback($url = NULL) {
// Rollback doesn't apply here yet. Unless we trigger a restore of the first dump // 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. // made. Which could go on infinitely if something is really long.
function drush_db_post_provision_restore($url = NULL) { function drush_db_post_provision_restore($url = NULL) {
provision_service('file')->path('unlink', drush_get_option('sites_path') . '/' . $url .'/database.sql', TRUE, provision_service('file')->unlink(drush_get_option('sites_path') . '/' . $url . '/database.sql')
dt("Removed dump file @path after restoring from it"), ->succeed('Removed dump file @path after restoring from it')
dt("Could not remove dump file @path"), 'DRUSH_PERM_ERROR'); ->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR');
provision_service('db')->destroy_site_database($url); provision_service('db')->destroy_site_database($url);
......
This diff is collapsed.
...@@ -26,10 +26,11 @@ function drush_provision_drupal_provision_backup_validate($url = NULL, $backup_f ...@@ -26,10 +26,11 @@ function drush_provision_drupal_provision_backup_validate($url = NULL, $backup_f
} }
if ($backup_file) { if ($backup_file) {
if (provision_service('file')->path("exists", $backup_file, FALSE, if (provision_service('file')->exists($backup_file)->status()) {
dt("Backing site up to @path."), drush_set_error('PROVISION_BACKUP_ALREADY_EXISTS', dt('Back up file @path already exists.', array('@path' => $backup_file)));
dt("Back up file @path already exists."), }
'PROVISION_BACKUP_ALREADY_EXISTS')) { else {
drush_log(dt('Backing site up to @path.', array('@path' => $backup_file)), 'message');
drush_set_option('backup_file', $backup_file); drush_set_option('backup_file', $backup_file);
} }
} }
...@@ -77,7 +78,8 @@ function drush_provision_drupal_provision_backup($url) { ...@@ -77,7 +78,8 @@ function drush_provision_drupal_provision_backup($url) {
function drush_provision_drupal_provision_backup_rollback() { function drush_provision_drupal_provision_backup_rollback() {
$backup_file = drush_get_option('backup_file'); $backup_file = drush_get_option('backup_file');
if (file_exists($backup_file)) { if (file_exists($backup_file)) {
provision_service('file')->path('unlink', $backup_file, TRUE, provision_service('file')->unlink($backup_file)
dt("Removed stale backup file $backup_file"), dt("Failed deleting backup file $backup_file")); ->succeed('Removed stale backup file @path')
->fail('Failed deleting backup file @path');
} }
} }
...@@ -27,7 +27,9 @@ function drush_provision_drupal_pre_provision_clone($url, $new_url, $platform = ...@@ -27,7 +27,9 @@ function drush_provision_drupal_pre_provision_clone($url, $new_url, $platform =
* Remove the extracted site directory * Remove the extracted site directory
*/ */
function drush_provision_drupal_pre_provision_clone_rollback($url, $new_url, $platform = null) { function drush_provision_drupal_pre_provision_clone_rollback($url, $new_url, $platform = null) {
$success = provision_service('file')->path("unlink", drush_get_option('backup_file'), TRUE, dt('Removed unused clone site package'), dt('Could not remove unused clone site package')); $success = provision_service('file')->unlink(drush_get_option('backup_file'))
->succeed('Removed unused clone site package')
->fail('Could not remove unused clone site package');
} }
/** /**
......
...@@ -21,10 +21,10 @@ ...@@ -21,10 +21,10 @@
function drush_provision_drupal_provision_deploy_validate($url = null, $backup_file = null) { function drush_provision_drupal_provision_deploy_validate($url = null, $backup_file = null) {
_provision_drupal_url_required(); _provision_drupal_url_required();
$exists = provision_service('file')->path("exists", $backup_file, TRUE, $exists = provision_service('file')->exists($backup_file)
dt("Deploying site from @path"), ->succeed('Deploying site from @path')
dt("Could not find backup file @path"), ->fail('Could not find backup file @path', 'PROVISION_BACKUP_NOT_FOUND')
'PROVISION_BACKUP_NOT_FOUND'); ->status();
if ($exists) { if ($exists) {
drush_set_option('backup_file', $backup_file); drush_set_option('backup_file', $backup_file);
} }
...@@ -36,10 +36,10 @@ function drush_provision_drupal_provision_deploy_validate($url = null, $backup_f ...@@ -36,10 +36,10 @@ function drush_provision_drupal_provision_deploy_validate($url = null, $backup_f
function drush_provision_drupal_pre_provision_deploy($url, $backup_file) { function drush_provision_drupal_pre_provision_deploy($url, $backup_file) {
// the url is likely to have changed in the deployment // the url is likely to have changed in the deployment
drush_set_option('site_url', $url); drush_set_option('site_url', $url);
$extracted = provision_service('file')->path("extract", drush_get_option('backup_file'), drush_get_option('sites_path') ."/$url", $extracted = provision_service('file')->extract(drush_get_option('backup_file'), drush_get_option('sites_path') . '/' . $url)
dt('Successfully extracted the contents of @path'), ->succeed('Successfully extracted the contents of @path')
dt('Failed to extract the contents of @path'), ->fail('Failed to extract the contents of @path', 'PROVISION_BACKUP_EXTRACTION_FAILED')
'PROVISION_BACKUP_EXTRACTION_FAILED'); ->status();
if ($extracted) { if ($extracted) {
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE); drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
......
...@@ -69,7 +69,8 @@ function drush_provision_drupal_provision_install_rollback($url) { ...@@ -69,7 +69,8 @@ function drush_provision_drupal_provision_install_rollback($url) {
function drush_provision_drupal_post_provision_install($url) { function drush_provision_drupal_post_provision_install($url) {
drush_set_option('aliases', drush_get_option('aliases'), 'site'); drush_set_option('aliases', drush_get_option('aliases'), 'site');
drush_set_option('installed', TRUE, 'site'); drush_set_option('installed', TRUE, 'site');
provision_service('file')->path("chmod", "./sites/$url/settings.php", 0440, dt("Secured settings.php with safe permissions")); provision_service('file')->chmod('./sites/' . $url . '/settings.php', 0440)
->succeed('Secured settings.php with safe permissions');
_provision_drupal_rebuild_caches($url); _provision_drupal_rebuild_caches($url);
drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site'); drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site');
} }
......
...@@ -49,7 +49,9 @@ function drush_provision_drupal_pre_provision_migrate_rollback($url, $platform = ...@@ -49,7 +49,9 @@ function drush_provision_drupal_pre_provision_migrate_rollback($url, $platform =
drush_log(dt("Bringing site out of maintenance")); drush_log(dt("Bringing site out of maintenance"));
drush_set_option('site_offline', 0); drush_set_option('site_offline', 0);
_provision_drupal_create_settings_file($url); _provision_drupal_create_settings_file($url);
$success = provision_service('file')->path("unlink", drush_get_option('backup_file'), TRUE, dt('Removed unused migration site package'), dt('Could not remove unused migration site package')); $success = provision_service('file')->unlink(drush_get_option('backup_file'))
->succeed('Removed unused migration site package')
->fail('Could not remove unused migration site package');
_provision_apache_create_vhost_config($url); _provision_apache_create_vhost_config($url);
_provision_apache_restart_apache(); _provision_apache_restart_apache();
} }
......
...@@ -194,10 +194,10 @@ function _provision_drupal_create_settings_file($url = NULL) { ...@@ -194,10 +194,10 @@ function _provision_drupal_create_settings_file($url = NULL) {
$options['extra_config'] .= join("\n", drush_command_invoke_all('provision_drupal_config', $url, $options)); $options['extra_config'] .= join("\n", drush_command_invoke_all('provision_drupal_config', $url, $options));
drush_log(dt("Generate settings.php file")); drush_log(dt("Generate settings.php file"));
if (provision_service('file')->path("exists", "sites/$url/settings.php")) { if (provision_service('file')->exists('sites/' . $url . '/settings.php')->status()) {
provision_service('file')->path("chmod", "sites/$url/settings.php", 0640, provision_service('file')->chmod('sites/' . $url . '/settings.php', 0640)
dt('Changed permissions of settings.php to @confirm'), ->succeed('Changed permissions of settings.php to @perm')
dt('Could not change permissions of settings.php to @confirm')); ->fail('Could not change permissions of settings.php to @perm');
} }
$fp = provision_service('file')->path('fopen', 'sites/' . $url . '/settings.php', 'w'); $fp = provision_service('file')->path('fopen', 'sites/' . $url . '/settings.php', 'w');
...@@ -206,13 +206,13 @@ function _provision_drupal_create_settings_file($url = NULL) { ...@@ -206,13 +206,13 @@ function _provision_drupal_create_settings_file($url = NULL) {
fclose($fp); fclose($fp);
# Change the permissions of the file # Change the permissions of the file
provision_service('file')->path("chmod", "sites/$url/settings.php", 0440, provision_service('file')->chmod('sites/' . $url . '/settings.php', 0440)
dt('Changed permissions of settings.php to @confirm'), ->succeed('Changed permissions of settings.php to @perm')
dt('Could not change permissions of settings.php to @confirm')); ->fail('Could not change permissions of settings.php to @perm');
provision_service('file')->path("chgrp", "sites/$url/settings.php", drush_get_option('web_group'), provision_service('file')->chgrp('sites/' . $url . '/settings.php', drush_get_option('web_group'))
dt('Change group ownership of settings.php to @confirm'), ->succeed('Change group ownership of settings.php to @gid')
dt('Could not change group ownership of settings.php to @confirm')); ->fail('Could not change group ownership of settings.php to @gid');
} }
/** /**
...@@ -251,27 +251,24 @@ function _provision_drupal_create_directories($url, $profile = NULL) { ...@@ -251,27 +251,24 @@ function _provision_drupal_create_directories($url, $profile = NULL) {
foreach ($mkdir as $path => $perm) { foreach ($mkdir as $path => $perm) {
if (!is_dir($path)) { if (!is_dir($path)) {
provision_service('file')->path("mkdir", $path, TRUE, provision_service('file')->mkdir($path)
dt("Created <code>@path</code>"), ->succeed('Created <code>@path</code>')
dt("Could not create <code>@path</code>"), ->fail('Could not create <code>@path</code>', 'DRUSH_PERM_ERROR');
'DRUSH_PERM_ERROR');
} }
provision_service('file')->path("chmod_recursive", $path, $perm, provision_service('file')->chmod($path, $perm, TRUE)
dt("Changed permissions of <code>@path</code> to @confirm"), ->succeed('Changed permissions of <code>@path</code> to @perm')
dt("Could not change permissions <code>@path</code> to @confirm") ->fail('Could not change permissions <code>@path</code> to @perm');
);
} }
foreach ($chown as $path => $owner) { foreach ($chown as $path => $owner) {
provision_service('file')->path("chown_recursive", $path, $owner, provision_service('file')->chown($path, $owner, TRUE)
dt("Changed ownership of <code>@path</code>"), ->succeed('Changed ownership of <code>@path</code>')
dt("Could not change ownership <code>@path</code>"), ->fail('Could not change ownership <code>@path</code>', 'DRUSH_PERM_ERROR');
'DRUSH_PERM_ERROR' );
} }
foreach ($chgrp as $path => $group) { foreach ($chgrp as $path => $group) {
provision_service('file')->path("chgrp_recursive", $path, $group, provision_service('file')->chgrp($path, $group, TRUE)
dt("Changed group ownership of <code>@path</code>"), ->succeed('Changed group ownership of <code>@path</code>')
dt("Could not change group ownership <code>@path</code>")); ->fail('Could not change group ownership <code>@path</code>');
} }
} }
...@@ -391,9 +388,9 @@ function _provision_drupal_maintain_aliases($url) { ...@@ -391,9 +388,9 @@ function _provision_drupal_maintain_aliases($url) {
} }
foreach($aliases as $alias) { foreach($aliases as $alias) {
if (trim($alias)) { if (trim($alias)) {
provision_service('file')->path("symlink", $url, drush_get_option('docroot_path') . "/sites/" . $alias, provision_service('file')->symlink($url, drush_get_option('docroot_path') . '/sites/' . $alias)
dt("Created symlink for alias @alias", array("@alias" => $alias)), ->succeed('Created symlink for alias @target')
dt("Could not create symlink for alias @alias", array("@alias" => $alias))); ->fail('Could not create symlink for alias @target');
} }
} }
} }
...@@ -409,13 +406,15 @@ function _provision_drupal_delete_aliases($aliases, $silent = false) { ...@@ -409,13 +406,15 @@ function _provision_drupal_delete_aliases($aliases, $silent = false) {
} }
if ($silent) { if ($silent) {
$error = NULL; $error = NULL;
} else { }
$error = dt("Could not remove symlink for alias @alias", array("@alias" => $alias)); else {
$error = 'Could not remove symlink for alias @path';
} }
foreach ($aliases as $alias) { foreach ($aliases as $alias) {
if ($alias = trim($alias)) { if ($alias = trim($alias)) {
provision_service('file')->path("unlink", drush_get_option('docroot_path') . "/sites/" . $alias, TRUE, provision_service('file')->unlink(drush_get_option('docroot_path') . '/sites/' . $alias)
dt("Removed symlink for alias @alias", array("@alias" => $alias)), $error); ->succeed('Removed symlink for alias @path')
->fail($error);
} }
} }
} }
......
...@@ -26,10 +26,10 @@ ...@@ -26,10 +26,10 @@
function drush_provision_drupal_provision_restore_validate($url = null, $restore_file = null) { function drush_provision_drupal_provision_restore_validate($url = null, $restore_file = null) {
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE); drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
$exists = provision_service('file')->path("exists", $restore_file, TRUE, $exists = provision_service('file')->exists($restore_file)
dt("Restoring site from @path"), ->succeed('Restoring site from @path')
dt("Could not find backup file @path"), ->fail('Could not find backup file @path', 'PROVISION_BACKUP_NOT_FOUND')
'PROVISION_BACKUP_NOT_FOUND'); ->status();
if ($exists) { if ($exists) {
drush_set_option('restore_file', $restore_file); drush_set_option('restore_file', $restore_file);
} }
...@@ -41,10 +41,9 @@ function drush_provision_drupal_provision_restore_validate($url = null, $restore ...@@ -41,10 +41,9 @@ function drush_provision_drupal_provision_restore_validate($url = null, $restore
function drush_provision_drupal_pre_provision_restore($url, $restore_file) { function drush_provision_drupal_pre_provision_restore($url, $restore_file) {
drush_invoke('provision-backup', $url); drush_invoke('provision-backup', $url);
provision_service('file')->path("extract", drush_get_option('restore_file'), drush_get_option('sites_path') ."/$url.restore", provision_service('file')->extract(drush_get_option('restore_file'), drush_get_option('sites_path') . '/' . $url . '.restore')
dt('Successfully extracted the contents of @path'), ->succeed('Successfully extracted the contents of @path')
dt('Failed to extract the contents of @path'), ->fail('Failed to extract the contents of @path', 'PROVISION_BACKUP_EXTRACTION_FAILED');
'PROVISION_BACKUP_EXTRACTION_FAILED');
} }
/** /**
...@@ -58,12 +57,11 @@ function drush_provision_drupal_pre_provision_restore_rollback($url) { ...@@ -58,12 +57,11 @@ function drush_provision_drupal_pre_provision_restore_rollback($url) {
* Switch the restore directories around now that we have the new db installed * Switch the restore directories around now that we have the new db installed
*/ */
function drush_provision_drupal_provision_restore($url) { function drush_provision_drupal_provision_restore($url) {
$old = drush_get_option('sites_path') ."/$url.restore"; $old = drush_get_option('sites_path') . '/' . $url . '.restore';
$new = drush_get_option('sites_path') ."/$url"; $new = drush_get_option('sites_path') . '/' . $url;
provision_service('file')->path("switch_paths", $old, $new , provision_service('file')->switch_paths($old, $new)
dt('Swapping out the @path and @confirm directories was successful.'), ->succeed('Swapping out the @path1 and @path2 directories was successful.')
dt('Swapping the @path and @confirm directories has failed.'), ->fail('Swapping the @path1 and @path2 directories has failed.', 'DRUSH_PERM_ERROR');
'DRUSH_PERM_ERROR');
// make sure it has the latest site data available // make sure it has the latest site data available
_provision_drupal_create_settings_file($url); _provision_drupal_create_settings_file($url);
provision_save_site_data($url); provision_save_site_data($url);
......
...@@ -27,7 +27,7 @@ function drush_provision_drupal_provision_verify($url = null) { ...@@ -27,7 +27,7 @@ function drush_provision_drupal_provision_verify($url = null) {
if (PROVISION_CONTEXT_PLATFORM) { if (PROVISION_CONTEXT_PLATFORM) {
provision_service('file')->create_dir(drush_get_option('config_path'), dt('Provision configuration'), 0711); provision_service('file')->create_dir(drush_get_option('config_path'), dt('Provision configuration'), 0711);
provision_service('file')->create_dir(drush_get_option('config_path') . '/includes', dt('Provision PHP configuration'), 0711); provision_service('file')->create_dir(drush_get_option('config_path') . '/includes', dt('Provision PHP configuration'), 0711);
if (!provision_service('file')->path('exists', drush_get_option('config_path') . '/includes/global.inc', TRUE, dt("Global configuration file exists"))) { if (!provision_service('file')->exists(drush_get_option('config_path') . '/includes/global.inc')->succeed('Global configuration file exists')->status()) {
# create an empty global.inc so the include doesn't fail with # create an empty global.inc so the include doesn't fail with
# open_basedir restrictions # open_basedir restrictions
if (!$file = provision_service('file')->path('fopen', drush_get_option('config_path') . '/includes/global.inc', 'a')) { if (!$file = provision_service('file')->path('fopen', drush_get_option('config_path') . '/includes/global.inc', 'a')) {
...@@ -38,8 +38,9 @@ function drush_provision_drupal_provision_verify($url = null) { ...@@ -38,8 +38,9 @@ function drush_provision_drupal_provision_verify($url = null) {
} }
} }
provision_service('file')->create_dir(drush_get_option('backup_path'), dt('Backup'), 0700); provision_service('file')->create_dir(drush_get_option('backup_path'), dt('Backup'), 0700);
provision_service('file')->path("writable", drush_get_option('sites_path'), TRUE, dt("Drupal sites directory is writable by the provisioning script"), provision_service('file')->writable(drush_get_option('sites_path'))
dt("Drupal sites directory is not writable by the provisioning script"), 'PROVISION_SITES_DIR_NOT_WRITABLE'); ->succeed('Drupal sites directory @path is writable by the provisioning script')
->fail('Drupal sites directory @path is not writable by the provisioning script', 'PROVISION_SITES_DIR_NOT_WRITABLE');
drush_set_option('sites', array_keys((array) provision_drupal_find_sites()), 'drupal'); drush_set_option('sites', array_keys((array) provision_drupal_find_sites()), 'drupal');
drush_log(dt("This platform is running @short_name @version", array('@short_name' => 'drupal', '@version' => VERSION))); drush_log(dt("This platform is running @short_name @version", array('@short_name' => 'drupal', '@version' => VERSION)));
......
...@@ -201,20 +201,20 @@ function drush_provision_hostmaster_make($platform) { ...@@ -201,20 +201,20 @@ function drush_provision_hostmaster_make($platform) {
* Generate a provision.settings.php file to configure provision * Generate a provision.settings.php file to configure provision
*/ */
function _provision_generate_config() { function _provision_generate_config() {
$exists = provision_service('file')->path('exists', drush_get_option('docroot_path') . '/drushrc.php'); $exists = provision_service('file')->exists(drush_get_option('docroot_path') . '/drushrc.php')->status();
if ($exists) { if ($exists) {
drush_log(dt("Found existing drushrc.php file")); drush_log(dt("Found existing drushrc.php file"));
provision_service('file')->path("chmod", drush_get_option('docroot_path') . '/drushrc.php', 0600, provision_service('file')->chmod(drush_get_option('docroot_path') . '/drushrc.php', 0600)
dt('Changed permissions of drushrc.php to @confirm'), ->succeed('Changed permissions of drushrc.php to @perm')
dt('Could not change permissions of drushrc.php to @confirm')); ->fail('Could not change permissions of drushrc.php to @perm');
} }
else { else {
drush_log(dt("Generating drushrc.php file")); drush_log(dt("Generating drushrc.php file"));
} }
provision_save_platform_data(); provision_save_platform_data();
provision_service('file')->path("chmod", drush_get_option('docroot_path') . '/drushrc.php', 0400, provision_service('file')->chmod(drush_get_option('docroot_path') . '/drushrc.php', 0400)
dt('Changed permissions of drushrc.php to @confirm'), ->succeed('Changed permissions of drushrc.php to @perm')
dt('Could not change permissions of drushrc.php to @confirm')); ->fail('Could not change permissions of drushrc.php to @perm');
return TRUE; return TRUE;
} }
......
...@@ -64,7 +64,7 @@ function provision_load_site_data($url) { ...@@ -64,7 +64,7 @@ function provision_load_site_data($url) {
$conf_file = "sites/$url/site.php"; $conf_file = "sites/$url/site.php";
if (file_exists($conf_file)) { if (file_exists($conf_file)) {
provision_service('file')->path('chmod', $conf_file, 0400); provision_service('file')->chmod($conf_file, 0400);
require($conf_file); require($conf_file);
// The provision 0.1 config data might contain older data, // The provision 0.1 config data might contain older data,
...@@ -81,6 +81,13 @@ function provision_load_site_data($url) { ...@@ -81,6 +81,13 @@ function provision_load_site_data($url) {
*/ */
function provision_save_site_data() { function provision_save_site_data() {
$context = 'site'; $context = 'site';
drush_set_option('context-path', drush_get_option('context-path', null, 'site'));
drush_unset_option('context-path', 'site');
drush_set_option('config-file', drush_get_option('config-file', null, 'site'));
drush_unset_option('config-file', 'site');
drush_save_config($context); drush_save_config($context);
$filename = _drush_config_file($context); $filename = _drush_config_file($context);
...@@ -99,9 +106,9 @@ function provision_save_site_data() { ...@@ -99,9 +106,9 @@ function provision_save_site_data() {
fclose($fp); fclose($fp);
} }
provision_service('file')->path("chmod", $filename, 0600, provision_service('file')->chmod($filename, 0600)
dt('Changed permissions of drushrc.php to @confirm'), ->succeed('Changed permissions of drushrc.php to @perm')
dt('Could not change permissions of drushrc.php to @confirm')); ->fail('Could not change permissions of drushrc.php to @perm');
} }
/** /**
...@@ -117,6 +124,13 @@ function provision_save_site_data() { ...@@ -117,6 +124,13 @@ function provision_save_site_data() {
* Boolean. The value returned by drush_save_config(). * Boolean. The value returned by drush_save_config().
*/ */
function provision_save_platform_data() { function provision_save_platform_data() {
drush_set_option('context-path', drush_get_option('context-path', null, 'drupal'));
drush_unset_option('context-path', 'drupal');
drush_set_option('config-file', drush_get_option('config-file', null, 'drupal'));
drush_unset_option('config-file', 'drupal');
return drush_save_config('drupal'); return drush_save_config('drupal');
} }
...@@ -180,15 +194,17 @@ function _provision_recursive_delete($path) { ...@@ -180,15 +194,17 @@ function _provision_recursive_delete($path) {
} }
} }
$rm = provision_service('file')->path('rmdir', $path, TRUE, $rm = provision_service('file')->rmdir($path)
dt('Deleting @path directory successful.', array('@path' => $path)), ->succeed('Deleting @path directory successful.')
dt('Deleting @path directory failed.', array('@path' => $path))); ->fail('Deleting @path directory failed.')
->status();
$ret = $ret && $rm; $ret = $ret && $rm;
} }
else { else {
$rm = provision_service('file')->path('unlink', $path, TRUE, NULL, $rm = provision_service('file')->unlink($path)
dt('Deleting @path file failed.', array('@path' => $path))); ->fail('Deleting @path file failed.')
->status();
$ret = $ret && $rm; $ret = $ret && $rm;
} }
return $ret; return $ret;
......
<?php <?php
class provisionService { class provisionService {
protected $last_status;
protected $tokens;
function __construct() { function __construct() {
$this->init(); $this->init();
} }
...@@ -13,6 +16,70 @@ class provisionService { ...@@ -13,6 +16,70 @@ class provisionService {
return TRUE; return TRUE;
} }
/**
* Clear internal state
*/
protected function _clear_state() {
$this->last_status = NULL;
$this->tokens = NULL;
}
/**
* Return the status of the last operation.
*
* @return
* TRUE or FALSE for success or failure; NULL if there was not a previous
* operation.
*/
function status() {
return $this->last_status;
}
/**
* Log a notice into the logging system, if the last operation completed
* succesfully.
*
* @param $message
* The message to log, a string.
*/
function succeed($message) {
if ($this->last_status === TRUE) {
drush_log(dt($message, $this->tokens), 'message');
}
return $this;
}
/**
* Log a notice into the logging system, if the last operation did not
* complete succesfully.
*
* @param $message
* Log this as a error to the logging system, if the $error_codes parameter
* has been set, otherwise, log this as a warning. If the operation
* specifies an additional reason for the operation failing, it will be
* appended to this message.
*
* @param error_codes
* Generate these system level errors using the provision error bitmasks.
*/
function fail($message, $error_codes = NULL) {
if (!empty($this->tokens['@reason'])) {
$message .= ' (@reason)';
}
if ($this->last_status === FALSE) {
if (is_null($error_codes)) {
// Trigger a warning
drush_log(dt($message, $this->tokens), 'warning');
}
else {
// Trigger a sysem halting error
drush_set_error($error_codes, dt($message, $this->tokens));
}
}
return $this;
}
} }
class provisionConfig { class provisionConfig {
...@@ -86,9 +153,8 @@ class provisionConfig { ...@@ -86,9 +153,8 @@ class provisionConfig {
} }
function unlink() { function unlink() {
return provision_service('file')->path('unlink', $this->filename()); return provision_service('file')->unlink($this->filename())->status();
} }
} }
......
...@@ -24,7 +24,9 @@ function provision_ssl_provision_apache_vhost_config($url, $options) { ...@@ -24,7 +24,9 @@ function provision_ssl_provision_apache_vhost_config($url, $options) {
if ($options['ssl_redirect']) { if ($options['ssl_redirect']) {
// That's pretty bad, but if we *don't* do that, the vhost is never updated after the first write // That's pretty bad, but if we *don't* do that, the vhost is never updated after the first write
// XXX: we need a better way to identify if this is legit // XXX: we need a better way to identify if this is legit
provision_service('file')->path('exists', drush_get_option('vhost_path') . '/' . $url . '_80', FALSE, NULL, dt("Overwriting existing vhost %url:80 with redirection", array('%url' => $url))); if (provision_service('file')->exists(drush_get_option('vhost_path') . '/' . $url . '_80')->status()) {
drush_log(dt('Overwriting existing vhost %url:80 with redirection', array('%url' => $url)), 'warning');
}
$newoptions = $options; $newoptions = $options;
// in the redirection template, the ServerName is the first alias in the list // in the redirection template, the ServerName is the first alias in the list
array_push($newoptions['aliases'], $options['site_url']); array_push($newoptions['aliases'], $options['site_url']);
...@@ -44,6 +46,7 @@ function provision_ssl_provision_apache_vhost_config($url, $options) { ...@@ -44,6 +46,7 @@ function provision_ssl_provision_apache_vhost_config($url, $options) {
*/ */
function provision_ssl_provision_apache_delete_vhost($url, $options) { function provision_ssl_provision_apache_delete_vhost($url, $options) {
if ($options['ssl'] && $options['ssl_redirect']) { if ($options['ssl'] && $options['ssl_redirect']) {
provision_service('file')->path('unlink', drush_get_option('vhost_path') . '/' . $url . '_80', TRUE, NULL, dt("Failed deleting redirection vhost.")); provision_service('file')->unlink(drush_get_option('vhost_path') . '/' . $url . '_80')
->succeed('Failed deleting redirection vhost.');
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment