Commit 96f6e167 authored by Adrian Rossouw's avatar Adrian Rossouw

Removed the provision_service function, and introduce service handler...

Removed the provision_service function, and introduce service handler subscriptions in the environment objects.

Instead of provision_service('type') you now use d()->service('type') to access the service object.
The context object returned by d() now manages which context object's service to return, based
on the internally managed subscriptions.
parent 4b2ebc70
<?php <?php
function drush_db_pre_provision_backup() { function drush_db_pre_provision_backup() {
provision_service('db')->generate_dump(); d()->service('db')->generate_dump();
} }
function drush_db_pre_provision_backup_rollback() { function drush_db_pre_provision_backup_rollback() {
provision_service('file')->unlink(d()->root . '/sites/' . d()->uri . '/database.sql') d()->service('file')->unlink(d()->root . '/sites/' . d()->uri . '/database.sql')
->succeed('Deleted mysql dump from sites directory') ->succeed('Deleted mysql dump from sites directory')
->fail('Could not delete mysql dump from sites directory'); ->fail('Could not delete mysql dump from sites directory');
} }
......
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
// $Id$ // $Id$
function drush_db_provision_clone_validate() { function drush_db_provision_clone_validate() {
provision_service('db')->connect(); d()->service('db')->connect();
} }
...@@ -16,7 +16,7 @@ function db_provision_services() { ...@@ -16,7 +16,7 @@ function db_provision_services() {
function db_drush_exit() { function db_drush_exit() {
// determine how to close it too. // determine how to close it too.
provision_service('db')->close(); d()->service('db')->close();
} }
function db_drush_help($section) { function db_drush_help($section) {
...@@ -174,12 +174,12 @@ class provisionService_db extends provisionService { ...@@ -174,12 +174,12 @@ class provisionService_db extends provisionService {
$creds = $this->fetch_site_credentials(); $creds = $this->fetch_site_credentials();
$exists = provision_service('file')->exists($dump_file) $exists = d()->service('file')->exists($dump_file)
->succeed('Found database dump at @path.') ->succeed('Found database dump at @path.')
->fail('No database dump was found at @path.', 'PROVISION_DB_DUMP_NOT_FOUND') ->fail('No database dump was found at @path.', 'PROVISION_DB_DUMP_NOT_FOUND')
->status(); ->status();
if ($exists) { if ($exists) {
$readable = provision_service('file')->readable($dump_file) $readable = d()->service('file')->readable($dump_file)
->succeed('Database dump at @path is readable') ->succeed('Database dump at @path is readable')
->fail('The database dump at @path could not be read.', 'PROVISION_DB_DUMP_NOT_READABLE') ->fail('The database dump at @path could not be read.', 'PROVISION_DB_DUMP_NOT_READABLE')
->status(); ->status();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
function drush_db_provision_delete_validate() { function drush_db_provision_delete_validate() {
if (d()->type === 'site') { if (d()->type === 'site') {
provision_service('db')->connect(); d()->service('db')->connect();
} }
} }
...@@ -13,6 +13,6 @@ function drush_db_provision_delete_validate() { ...@@ -13,6 +13,6 @@ function drush_db_provision_delete_validate() {
*/ */
function drush_db_provision_delete() { function drush_db_provision_delete() {
if (d()->type === 'site') { if (d()->type === 'site') {
provision_service('db')->destroy_site_database(); d()->service('db')->destroy_site_database();
} }
} }
<?php <?php
function drush_db_provision_deploy_validate() { function drush_db_provision_deploy_validate() {
provision_service('db')->connect(); d()->service('db')->connect();
} }
function drush_db_provision_deploy() { function drush_db_provision_deploy() {
provision_service('db')->create_site_database(); d()->service('db')->create_site_database();
provision_service('db')->import_site_database(); d()->service('db')->import_site_database();
} }
function drush_db_provision_deploy_rollback() { function drush_db_provision_deploy_rollback() {
provision_service('db')->destroy_site_database(); d()->service('db')->destroy_site_database();
} }
// 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() { function drush_db_post_provision_deploy() {
provision_service('file')->unlink(d()->root . '/sites/' . d()->uri . '/database.sql') d()->service('file')->unlink(d()->root . '/sites/' . d()->uri . '/database.sql')
->succeed('Removed dump file @path after restoring from it') ->succeed('Removed dump file @path after restoring from it')
->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR'); ->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR');
} }
<?php <?php
function drush_db_provision_install_validate() { function drush_db_provision_install_validate() {
d()->db_server->service('db')->connect(); d()->service('db')->connect();
} }
function drush_db_pre_provision_install() { function drush_db_pre_provision_install() {
d()->db_server->service('db')->create_site_database(); d()->service('db')->create_site_database();
} }
function drush_db_pre_provision_install_rollback() { function drush_db_pre_provision_install_rollback() {
if (!_provision_drupal_site_installed()) { if (!_provision_drupal_site_installed()) {
d()->db_server->service('db')->destroy_site_database(); d()->service('db')->destroy_site_database();
} }
} }
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
// $Id$ // $Id$
function drush_db_provision_migrate_validate() { function drush_db_provision_migrate_validate() {
provision_service('db')->connect(); d()->service('db')->connect();
} }
// Deletes the old database credentials // Deletes the old database credentials
function drush_db_post_provision_migrate() { function drush_db_post_provision_migrate() {
provision_service('db')->destroy_site_database( d()->service('db')->destroy_site_database(
drush_get_option('db_name'), drush_get_option('db_name'),
drush_get_option('db_user'), drush_get_option('db_user'),
drush_get_option('db_passwd') drush_get_option('db_passwd')
......
...@@ -136,7 +136,6 @@ password=%s ...@@ -136,7 +136,6 @@ password=%s
// XXX: failed to execute? unsure when this happens // XXX: failed to execute? unsure when this happens
$return_value = -1; $return_value = -1;
} }
dlm($output);
return ($return_value == 0); return ($return_value == 0);
} }
......
<?php <?php
function drush_db_provision_restore_validate() { function drush_db_provision_restore_validate() {
provision_service('db')->connect(); d()->service('db')->connect();
} }
function drush_db_pre_provision_restore() { function drush_db_pre_provision_restore() {
drush_set_option('old_db_creds', provision_service('db')->fetch_site_credentials()); drush_set_option('old_db_creds', d()->service('db')->fetch_site_credentials());
provision_service('db')->create_site_database(); d()->service('db')->create_site_database();
} }
function drush_db_provision_restore() { function drush_db_provision_restore() {
provision_service('db')->import_site_database(d()->root . '/sites/' . d()->uri . '.restore/database.sql'); d()->service('db')->import_site_database(d()->root . '/sites/' . d()->uri . '.restore/database.sql');
} }
function drush_db_pre_provision_restore_rollback() { function drush_db_pre_provision_restore_rollback() {
provision_service('db')->destroy_site_database(); d()->service('db')->destroy_site_database();
$keys = array('db_name', 'db_passwd', 'db_user', 'db_host'); $keys = array('db_name', 'db_passwd', 'db_user', 'db_host');
...@@ -32,11 +32,11 @@ function drush_db_pre_provision_restore_rollback() { ...@@ -32,11 +32,11 @@ function drush_db_pre_provision_restore_rollback() {
// 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() { function drush_db_post_provision_restore() {
provision_service('file')->unlink(d()->root . '/sites/' . d()->uri . '/database.sql') d()->service('file')->unlink(d()->root . '/sites/' . d()->uri . '/database.sql')
->succeed('Removed dump file @path after restoring from it') ->succeed('Removed dump file @path after restoring from it')
->fail('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(drush_get_option('old_db_creds')); d()->service('db')->destroy_site_database(drush_get_option('old_db_creds'));
// TODO - test this .. it's probably horribly broken .. deleting the newly restored db instead of the old one. // TODO - test this .. it's probably horribly broken .. deleting the newly restored db instead of the old one.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
function drush_http_provision_delete() { function drush_http_provision_delete() {
if (d()->type === 'site') { if (d()->type === 'site') {
provision_service('http')->delete_site_config(); d()->service('http')->delete_site_config();
} }
if (d()->type === 'platform') { if (d()->type === 'platform') {
$sites = provision_drupal_find_sites(); $sites = provision_drupal_find_sites();
...@@ -10,10 +10,10 @@ function drush_http_provision_delete() { ...@@ -10,10 +10,10 @@ function drush_http_provision_delete() {
drush_set_error(dt('Existing sites were found on this platform. These sites will need to be deleted before this platform can be deleted.')); drush_set_error(dt('Existing sites were found on this platform. These sites will need to be deleted before this platform can be deleted.'));
} }
else { else {
provision_service('http')->delete_platform_config(); d()->service('http')->delete_platform_config();
} }
} }
return provision_service('http')->parse_configs(); return d()->service('http')->parse_configs();
} }
<?php <?php
function drush_http_post_provision_deploy() { function drush_http_post_provision_deploy() {
provision_service('http')->create_site_config(); d()->service('http')->create_site_config();
provision_service('http')->parse_configs(); d()->service('http')->parse_configs();
} }
/** /**
* Delete the config file created. * Delete the config file created.
*/ */
function drush_http_post_provision_deploy_rollback() { function drush_http_post_provision_deploy_rollback() {
provision_service('http')->create_site_config(); d()->service('http')->create_site_config();
provision_service('http')->parse_configs(); d()->service('http')->parse_configs();
} }
...@@ -7,7 +7,7 @@ function drush_http_provision_disable() { ...@@ -7,7 +7,7 @@ function drush_http_provision_disable() {
drush_set_option('redirect_url', drush_get_option('web_disable_url')); drush_set_option('redirect_url', drush_get_option('web_disable_url'));
// TODO - this is majorly wrong i think. // TODO - this is majorly wrong i think.
provision_service('http')->create_site_config(); d()->service('http')->create_site_config();
provision_service('http')->parse_configs(); d()->service('http')->parse_configs();
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Implementation of hook_provision_enable * Implementation of hook_provision_enable
*/ */
function drush_http_provision_enable() { function drush_http_provision_enable() {
provision_service('http')->create_site_config(); d()->service('http')->create_site_config();
provision_service('http')->parse_configs(); d()->service('http')->parse_configs();
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Implementation of hook_provision_post_install * Implementation of hook_provision_post_install
*/ */
function drush_http_post_provision_install() { function drush_http_post_provision_install() {
provision_service('http')->create_site_config(); d()->service('http')->create_site_config();
provision_service('http')->parse_configs(); d()->service('http')->parse_configs();
} }
...@@ -5,18 +5,18 @@ ...@@ -5,18 +5,18 @@
*/ */
function drush_http_pre_provision_restore() { function drush_http_pre_provision_restore() {
drush_set_option('redirect_url', drush_get_option('web_maintenance_url')); drush_set_option('redirect_url', drush_get_option('web_maintenance_url'));
provision_service('http')->create_site_config(); d()->service('http')->create_site_config();
provision_service('http')->parse_configs(); d()->service('http')->parse_configs();
} }
function drush_http_pre_provision_restore_rollback() { function drush_http_pre_provision_restore_rollback() {
provision_service('http')->create_site_config(); d()->service('http')->create_site_config();
provision_service('http')->parse_configs(); d()->service('http')->parse_configs();
} }
function drush_http_post_provision_restore() { function drush_http_post_provision_restore() {
provision_service('http')->create_site_config(); d()->service('http')->create_site_config();
provision_service('http')->parse_configs(); d()->service('http')->parse_configs();
} }
......
...@@ -26,7 +26,7 @@ function drush_provision_drupal_provision_backup_validate($backup_file = NULL) { ...@@ -26,7 +26,7 @@ function drush_provision_drupal_provision_backup_validate($backup_file = NULL) {
} }
if ($backup_file) { if ($backup_file) {
if (provision_service('file')->exists($backup_file)->status()) { if (d()->service('file')->exists($backup_file)->status()) {
drush_set_error('PROVISION_BACKUP_ALREADY_EXISTS', dt('Back up file @path already exists.', array('@path' => $backup_file))); drush_set_error('PROVISION_BACKUP_ALREADY_EXISTS', dt('Back up file @path already exists.', array('@path' => $backup_file)));
} }
else { else {
...@@ -78,7 +78,7 @@ function drush_provision_drupal_provision_backup() { ...@@ -78,7 +78,7 @@ function drush_provision_drupal_provision_backup() {
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')->unlink($backup_file) d()->service('file')->unlink($backup_file)
->succeed('Removed stale backup file @path') ->succeed('Removed stale backup file @path')
->fail('Failed deleting backup file @path'); ->fail('Failed deleting backup file @path');
} }
......
...@@ -27,7 +27,7 @@ function drush_provision_drupal_pre_provision_clone($new_url, $platform = null) ...@@ -27,7 +27,7 @@ function drush_provision_drupal_pre_provision_clone($new_url, $platform = null)
* Remove the extracted site directory * Remove the extracted site directory
*/ */
function drush_provision_drupal_pre_provision_clone_rollback($new_url, $platform = null) { function drush_provision_drupal_pre_provision_clone_rollback($new_url, $platform = null) {
$success = provision_service('file')->unlink(drush_get_option('backup_file')) $success = d()->service('file')->unlink(drush_get_option('backup_file'))
->succeed('Removed unused clone site package') ->succeed('Removed unused clone site package')
->fail('Could not remove unused clone site package'); ->fail('Could not remove unused clone site package');
} }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
function drush_provision_drupal_provision_deploy_validate($backup_file = null) { function drush_provision_drupal_provision_deploy_validate($backup_file = null) {
_provision_drupal_url_required(); _provision_drupal_url_required();
$exists = provision_service('file')->exists($backup_file) $exists = d()->service('file')->exists($backup_file)
->succeed('Deploying site from @path') ->succeed('Deploying site from @path')
->fail('Could not find backup file @path', 'PROVISION_BACKUP_NOT_FOUND') ->fail('Could not find backup file @path', 'PROVISION_BACKUP_NOT_FOUND')
->status(); ->status();
...@@ -35,7 +35,7 @@ function drush_provision_drupal_provision_deploy_validate($backup_file = null) { ...@@ -35,7 +35,7 @@ function drush_provision_drupal_provision_deploy_validate($backup_file = null) {
*/ */
function drush_provision_drupal_pre_provision_deploy($backup_file) { function drush_provision_drupal_pre_provision_deploy($backup_file) {
// the url is likely to have changed in the deployment // the url is likely to have changed in the deployment
$extracted = provision_service('file')->extract(drush_get_option('backup_file'), d()->root . '/sites/' . d()->uri) $extracted = d()->service('file')->extract(drush_get_option('backup_file'), d()->root . '/sites/' . d()->uri)
->succeed('Successfully extracted the contents of @path') ->succeed('Successfully extracted the contents of @path')
->fail('Failed to extract the contents of @path', 'PROVISION_BACKUP_EXTRACTION_FAILED') ->fail('Failed to extract the contents of @path', 'PROVISION_BACKUP_EXTRACTION_FAILED')
->status(); ->status();
......
...@@ -49,10 +49,10 @@ function drush_provision_drupal_pre_provision_migrate_rollback($platform = null) ...@@ -49,10 +49,10 @@ function drush_provision_drupal_pre_provision_migrate_rollback($platform = null)
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(); _provision_drupal_create_settings_file();
$success = provision_service('file')->unlink(drush_get_option('backup_file')) $success = d()->service('file')->unlink(drush_get_option('backup_file'))
->succeed('Removed unused migration site package') ->succeed('Removed unused migration site package')
->fail('Could not remove unused migration site package'); ->fail('Could not remove unused migration site package');
provision_service('http')->create_site_config(); d()->service('http')->create_site_config();
_provision_apache_restart_apache(); _provision_apache_restart_apache();
} }
......
...@@ -246,22 +246,22 @@ function _provision_drupal_create_directories($url = NULL, $profile = NULL) { ...@@ -246,22 +246,22 @@ function _provision_drupal_create_directories($url = NULL, $profile = NULL) {
foreach ($mkdir as $path => $perm) { foreach ($mkdir as $path => $perm) {
if (!is_dir($path)) { if (!is_dir($path)) {
provision_service('file')->mkdir($path) d()->service('file')->mkdir($path)
->succeed('Created <code>@path</code>') ->succeed('Created <code>@path</code>')
->fail('Could not create <code>@path</code>', 'DRUSH_PERM_ERROR'); ->fail('Could not create <code>@path</code>', 'DRUSH_PERM_ERROR');
} }
provision_service('file')->chmod($path, $perm, TRUE) d()->service('file')->chmod($path, $perm, TRUE)
->succeed('Changed permissions of <code>@path</code> to @perm') ->succeed('Changed permissions of <code>@path</code> to @perm')
->fail('Could not change permissions <code>@path</code> to @perm'); ->fail('Could not change permissions <code>@path</code> to @perm');
} }
foreach ($chown as $path => $owner) { foreach ($chown as $path => $owner) {
provision_service('file')->chown($path, $owner, TRUE) d()->service('file')->chown($path, $owner, TRUE)
->succeed('Changed ownership of <code>@path</code> to @uid') ->succeed('Changed ownership of <code>@path</code> to @uid')
->fail('Could not change ownership <code>@path</code>', 'DRUSH_PERM_ERROR'); ->fail('Could not change ownership <code>@path</code>', 'DRUSH_PERM_ERROR');
} }
foreach ($chgrp as $path => $group) { foreach ($chgrp as $path => $group) {
provision_service('file')->chgrp($path, $group, TRUE) d()->service('file')->chgrp($path, $group, TRUE)
->succeed('Changed group ownership of <code>@path</code> to @gid') ->succeed('Changed group ownership of <code>@path</code> to @gid')
->fail('Could not change group ownership <code>@path</code> to @gid'); ->fail('Could not change group ownership <code>@path</code> to @gid');
} }
...@@ -383,7 +383,7 @@ function _provision_drupal_maintain_aliases() { ...@@ -383,7 +383,7 @@ function _provision_drupal_maintain_aliases() {
} }
foreach($aliases as $alias) { foreach($aliases as $alias) {
if (trim($alias)) { if (trim($alias)) {
provision_service('file')->symlink(d()->uri, d()->root . '/sites/' . $alias) d()->service('file')->symlink(d()->uri, d()->root . '/sites/' . $alias)
->succeed('Created symlink for alias @target') ->succeed('Created symlink for alias @target')
->fail('Could not create symlink for alias @target'); ->fail('Could not create symlink for alias @target');
} }
...@@ -407,7 +407,7 @@ function _provision_drupal_delete_aliases($aliases, $silent = false) { ...@@ -407,7 +407,7 @@ function _provision_drupal_delete_aliases($aliases, $silent = false) {
} }
foreach ($aliases as $alias) { foreach ($aliases as $alias) {
if ($alias = trim($alias)) { if ($alias = trim($alias)) {
provision_service('file')->unlink(d()->root . '/sites/' . $alias) d()->service('file')->unlink(d()->root . '/sites/' . $alias)
->succeed('Removed symlink for alias @path') ->succeed('Removed symlink for alias @path')
->fail($error); ->fail($error);
} }
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
function drush_provision_drupal_provision_restore_validate($restore_file = null) { function drush_provision_drupal_provision_restore_validate($restore_file = null) {
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE); drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE);
$exists = provision_service('file')->exists($restore_file) $exists = d()->service('file')->exists($restore_file)
->succeed('Restoring site from @path') ->succeed('Restoring site from @path')
->fail('Could not find backup file @path', 'PROVISION_BACKUP_NOT_FOUND') ->fail('Could not find backup file @path', 'PROVISION_BACKUP_NOT_FOUND')
->status(); ->status();
...@@ -41,7 +41,7 @@ function drush_provision_drupal_provision_restore_validate($restore_file = null) ...@@ -41,7 +41,7 @@ function drush_provision_drupal_provision_restore_validate($restore_file = null)
function drush_provision_drupal_pre_provision_restore($restore_file) { function drush_provision_drupal_pre_provision_restore($restore_file) {
drush_invoke('provision-backup'); drush_invoke('provision-backup');
provision_service('file')->extract(drush_get_option('restore_file'), d()->root . '/sites/' . d()->uri . '.restore') d()->service('file')->extract(drush_get_option('restore_file'), d()->root . '/sites/' . d()->uri . '.restore')
->succeed('Successfully extracted the contents of @path') ->succeed('Successfully extracted the contents of @path')
->fail('Failed to extract the contents of @path', 'PROVISION_BACKUP_EXTRACTION_FAILED'); ->fail('Failed to extract the contents of @path', 'PROVISION_BACKUP_EXTRACTION_FAILED');
} }
...@@ -59,7 +59,7 @@ function drush_provision_drupal_pre_provision_restore_rollback() { ...@@ -59,7 +59,7 @@ function drush_provision_drupal_pre_provision_restore_rollback() {
function drush_provision_drupal_provision_restore() { function drush_provision_drupal_provision_restore() {
$old = d()->root . '/sites/' . d()->uri . '.restore'; $old = d()->root . '/sites/' . d()->uri . '.restore';
$new = d()->root . '/sites/' . d()->uri; $new = d()->root . '/sites/' . d()->uri;
provision_service('file')->switch_paths($old, $new) d()->service('file')->switch_paths($old, $new)
->succeed('Swapping out the @path1 and @path2 directories was successful.') ->succeed('Swapping out the @path1 and @path2 directories was successful.')
->fail('Swapping the @path1 and @path2 directories has failed.', 'DRUSH_PERM_ERROR');