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
function drush_db_pre_provision_backup() {
provision_service('db')->generate_dump();
d()->service('db')->generate_dump();
}
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')
->fail('Could not delete mysql dump from sites directory');
}
......
......@@ -2,5 +2,5 @@
// $Id$
function drush_db_provision_clone_validate() {
provision_service('db')->connect();
d()->service('db')->connect();
}
......@@ -16,7 +16,7 @@ function db_provision_services() {
function db_drush_exit() {
// determine how to close it too.
provision_service('db')->close();
d()->service('db')->close();
}
function db_drush_help($section) {
......@@ -174,12 +174,12 @@ class provisionService_db extends provisionService {
$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.')
->fail('No database dump was found at @path.', 'PROVISION_DB_DUMP_NOT_FOUND')
->status();
if ($exists) {
$readable = provision_service('file')->readable($dump_file)
$readable = d()->service('file')->readable($dump_file)
->succeed('Database dump at @path is readable')
->fail('The database dump at @path could not be read.', 'PROVISION_DB_DUMP_NOT_READABLE')
->status();
......
......@@ -2,7 +2,7 @@
function drush_db_provision_delete_validate() {
if (d()->type === 'site') {
provision_service('db')->connect();
d()->service('db')->connect();
}
}
......@@ -13,6 +13,6 @@ function drush_db_provision_delete_validate() {
*/
function drush_db_provision_delete() {
if (d()->type === 'site') {
provision_service('db')->destroy_site_database();
d()->service('db')->destroy_site_database();
}
}
<?php
function drush_db_provision_deploy_validate() {
provision_service('db')->connect();
d()->service('db')->connect();
}
function drush_db_provision_deploy() {
provision_service('db')->create_site_database();
provision_service('db')->import_site_database();
d()->service('db')->create_site_database();
d()->service('db')->import_site_database();
}
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
// made. Which could go on infinitely if something is really long.
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')
->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR');
}
<?php
function drush_db_provision_install_validate() {
d()->db_server->service('db')->connect();
d()->service('db')->connect();
}
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() {
if (!_provision_drupal_site_installed()) {
d()->db_server->service('db')->destroy_site_database();
d()->service('db')->destroy_site_database();
}
}
......@@ -2,12 +2,12 @@
// $Id$
function drush_db_provision_migrate_validate() {
provision_service('db')->connect();
d()->service('db')->connect();
}
// Deletes the old database credentials
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_user'),
drush_get_option('db_passwd')
......
......@@ -136,7 +136,6 @@ password=%s
// XXX: failed to execute? unsure when this happens
$return_value = -1;
}
dlm($output);
return ($return_value == 0);
}
......
<?php
function drush_db_provision_restore_validate() {
provision_service('db')->connect();
d()->service('db')->connect();
}
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() {
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() {
provision_service('db')->destroy_site_database();
d()->service('db')->destroy_site_database();
$keys = array('db_name', 'db_passwd', 'db_user', 'db_host');
......@@ -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
// made. Which could go on infinitely if something is really long.
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')
->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.
......
......@@ -2,7 +2,7 @@
function drush_http_provision_delete() {
if (d()->type === 'site') {
provision_service('http')->delete_site_config();
d()->service('http')->delete_site_config();
}
if (d()->type === 'platform') {
$sites = provision_drupal_find_sites();
......@@ -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.'));
}
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
function drush_http_post_provision_deploy() {
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
d()->service('http')->create_site_config();
d()->service('http')->parse_configs();
}
/**
* Delete the config file created.
*/
function drush_http_post_provision_deploy_rollback() {
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
d()->service('http')->create_site_config();
d()->service('http')->parse_configs();
}
......@@ -7,7 +7,7 @@ function drush_http_provision_disable() {
drush_set_option('redirect_url', drush_get_option('web_disable_url'));
// TODO - this is majorly wrong i think.
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
d()->service('http')->create_site_config();
d()->service('http')->parse_configs();
}
......@@ -4,7 +4,7 @@
* Implementation of hook_provision_enable
*/
function drush_http_provision_enable() {
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
d()->service('http')->create_site_config();
d()->service('http')->parse_configs();
}
......@@ -11,7 +11,7 @@
* Implementation of hook_provision_post_install
*/
function drush_http_post_provision_install() {
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
d()->service('http')->create_site_config();
d()->service('http')->parse_configs();
}
......@@ -5,18 +5,18 @@
*/
function drush_http_pre_provision_restore() {
drush_set_option('redirect_url', drush_get_option('web_maintenance_url'));
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
d()->service('http')->create_site_config();
d()->service('http')->parse_configs();
}
function drush_http_pre_provision_restore_rollback() {
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
d()->service('http')->create_site_config();
d()->service('http')->parse_configs();
}
function drush_http_post_provision_restore() {
provision_service('http')->create_site_config();
provision_service('http')->parse_configs();
d()->service('http')->create_site_config();
d()->service('http')->parse_configs();
}
......
......@@ -26,7 +26,7 @@ function drush_provision_drupal_provision_backup_validate($backup_file = NULL) {
}
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)));
}
else {
......@@ -78,7 +78,7 @@ function drush_provision_drupal_provision_backup() {
function drush_provision_drupal_provision_backup_rollback() {
$backup_file = drush_get_option('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')
->fail('Failed deleting backup file @path');
}
......
......@@ -27,7 +27,7 @@ function drush_provision_drupal_pre_provision_clone($new_url, $platform = null)
* Remove the extracted site directory
*/
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')
->fail('Could not remove unused clone site package');
}
......
......@@ -21,7 +21,7 @@
function drush_provision_drupal_provision_deploy_validate($backup_file = null) {
_provision_drupal_url_required();
$exists = provision_service('file')->exists($backup_file)
$exists = d()->service('file')->exists($backup_file)
->succeed('Deploying site from @path')
->fail('Could not find backup file @path', 'PROVISION_BACKUP_NOT_FOUND')
->status();
......@@ -35,7 +35,7 @@ function drush_provision_drupal_provision_deploy_validate($backup_file = null) {
*/
function drush_provision_drupal_pre_provision_deploy($backup_file) {
// 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')
->fail('Failed to extract the contents of @path', 'PROVISION_BACKUP_EXTRACTION_FAILED')
->status();
......
......@@ -49,10 +49,10 @@ function drush_provision_drupal_pre_provision_migrate_rollback($platform = null)
drush_log(dt("Bringing site out of maintenance"));
drush_set_option('site_offline', 0);
_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')
->fail('Could not remove unused migration site package');
provision_service('http')->create_site_config();
d()->service('http')->create_site_config();
_provision_apache_restart_apache();
}
......
......@@ -246,22 +246,22 @@ function _provision_drupal_create_directories($url = NULL, $profile = NULL) {
foreach ($mkdir as $path => $perm) {
if (!is_dir($path)) {
provision_service('file')->mkdir($path)
d()->service('file')->mkdir($path)
->succeed('Created <code>@path</code>')
->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')
->fail('Could not change permissions <code>@path</code> to @perm');
}
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')
->fail('Could not change ownership <code>@path</code>', 'DRUSH_PERM_ERROR');
}
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')
->fail('Could not change group ownership <code>@path</code> to @gid');
}
......@@ -383,7 +383,7 @@ function _provision_drupal_maintain_aliases() {
}
foreach($aliases as $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')
->fail('Could not create symlink for alias @target');
}
......@@ -407,7 +407,7 @@ function _provision_drupal_delete_aliases($aliases, $silent = false) {
}
foreach ($aliases as $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')
->fail($error);
}
......
......@@ -26,7 +26,7 @@
function drush_provision_drupal_provision_restore_validate($restore_file = null) {
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')
->fail('Could not find backup file @path', 'PROVISION_BACKUP_NOT_FOUND')
->status();
......@@ -41,7 +41,7 @@ function drush_provision_drupal_provision_restore_validate($restore_file = null)
function drush_provision_drupal_pre_provision_restore($restore_file) {
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')
->fail('Failed to extract the contents of @path', 'PROVISION_BACKUP_EXTRACTION_FAILED');
}
......@@ -59,7 +59,7 @@ function drush_provision_drupal_pre_provision_restore_rollback() {
function drush_provision_drupal_provision_restore() {
$old = d()->root . '/sites/' . d()->uri . '.restore';
$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.')
->fail('Swapping the @path1 and @path2 directories has failed.', 'DRUSH_PERM_ERROR');
// make sure it has the latest site data available
......
......@@ -26,18 +26,18 @@ function drush_provision_drupal_provision_verify_validate() {
*/
function drush_provision_drupal_provision_verify() {
if (d()->type === 'server') {
provision_service('file')->create_dir(d()->config_path, dt('Provision configuration'), 0711);
provision_service('file')->create_dir(d()->config_path . '/includes', dt('Provision PHP configuration'), 0711);
if (!provision_service('file')->exists(d()->config_path . '/includes/global.inc')->succeed('Global configuration file exists')->status()) {
d()->service('file')->create_dir(d()->config_path, dt('Provision configuration'), 0711);
d()->service('file')->create_dir(d()->config_path . '/includes', dt('Provision PHP configuration'), 0711);
if (!d()->service('file')->exists(d()->config_path . '/includes/global.inc')->succeed('Global configuration file exists')->status()) {
// Create an empty global.inc so the include doesn't fail with
// open_basedir restrictions
$config = new provisionConfig_global_settings(d()->name);
$config->write();
}
provision_service('file')->create_dir(d()->backup_path, dt('Backup'), 0700);
d()->service('file')->create_dir(d()->backup_path, dt('Backup'), 0700);
}
elseif (d()->type === 'platform') {
provision_service('file')->writable(d()->root . '/sites')
d()->service('file')->writable(d()->root . '/sites')
->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');
......
......@@ -70,8 +70,8 @@ class provisionConfig {
function write() {
$filename = $this->filename();
// Make directory structure if it does not exist.
if (!provision_service('file')->exists(dirname($filename))->status()) {
provision_service('file')->mkdir(dirname($filename))
if (!d()->service('file')->exists(dirname($filename))->status()) {
d()->service('file')->mkdir(dirname($filename))
->succeed('Created directory @path.')
->fail('Could not create directory @path.');
}
......@@ -82,23 +82,23 @@ class provisionConfig {
if ($template = $this->load_template()) {
// Make sure we can write to the file
if (!is_null($this->mode) && !($this->mode & 0200) && provision_service('file')->exists($filename)->status()) {
provision_service('file')->chmod($filename, $this->mode | 0200)
if (!is_null($this->mode) && !($this->mode & 0200) && d()->service('file')->exists($filename)->status()) {
d()->service('file')->chmod($filename, $this->mode | 0200)
->succeed('Changed permissions of @path to @perm')
->fail('Could not change permissions of @path to @perm');
}
provision_service('file')->file_put_contents($filename, $this->render_template($template, $this->data), $this->append ? FILE_APPEND : 0)
d()->service('file')->file_put_contents($filename, $this->render_template($template, $this->data), $this->append ? FILE_APPEND : 0)
->succeed('Generated config ' . (empty($this->description) ? $filename : $this->description), 'success');
// Change the permissions of the file if needed
if (!is_null($this->mode)) {
provision_service('file')->chmod($filename, $this->mode)
d()->service('file')->chmod($filename, $this->mode)
->succeed('Changed permissions of @path to @perm')
->fail('Could not change permissions of @path to @perm');
}
if (!is_null($this->group)) {
provision_service('file')->chgrp($filename, $this->group)
d()->service('file')->chgrp($filename, $this->group)
->succeed('Change group ownership of @path to @gid')
->fail('Could not change group ownership of @path to @gid');
}
......@@ -107,7 +107,7 @@ class provisionConfig {
}
function unlink() {
return provision_service('file')->unlink($this->filename())->status();
return d()->service('file')->unlink($this->filename())->status();
}
}
......
......@@ -64,7 +64,10 @@ class provisionEnvironment {
public $name = null;
public $type = null;
protected $properties = array();
protected $service_subs = array();
protected $parent_key = null;
protected $oid_map = array();
......@@ -167,8 +170,28 @@ class provisionEnvironment {
$config->write();
}
/**
* Subscribe a service handler.
*
* All future calls to $this->service($service) will be redirected
* to the context object of #name you specify.
*/
function service_subscribe($service, $name) {
$this->service_subs[$service] = $name;
}
/**
* Return a service object for the specific service type.
*
* This will return a specifically subscribed service object when
* one has been registered with service_subscribe, otherwise it will
* return the value specified by the property specified by $this->parent_key.
*/
function service($service, $name = null) {
if (!is_null($this->parent_key)) {
if (isset($this->service_subs[$service])) {
return d($this->service_subs[$service])->service($service, ($name) ? $name : $this->name);
}
elseif (!is_null($this->parent_key)) {
return $this->{$this->parent_key}->service($service, ($name) ? $name : $this->name);
}
else {
......@@ -184,8 +207,8 @@ class provisionEnvironment {
* objects for each of the available service types.
*/
class provisionServer extends provisionEnvironment {
protected $services = array();
protected $services = array();
static function option_documentation() {
$options = array(
'--remote_host' => 'server: host name; default localhost',
......@@ -315,6 +338,8 @@ class provisionPlatform extends provisionEnvironment {
$this->type = 'platform';
$this->setProperty('root');
$this->service_subscribe("http", $this->web_server);
$this->setProperty('server', '@server_localhost');
$this->is_oid('server');
......@@ -360,6 +385,7 @@ class provisionSite extends provisionEnvironment {
$this->setProperty('client_email');
$this->service_subscribe("db", $this->db_server);
$this->setProperty('db_server');
$this->is_oid('db_server');
......
......@@ -87,7 +87,7 @@ function _provision_recursive_delete($path) {
}
}
$rm = provision_service('file')->rmdir($path)
$rm = d()->service('file')->rmdir($path)
->succeed('Deleting @path directory successful.')
->fail('Deleting @path directory failed.')
->status();
......@@ -95,7 +95,7 @@ function _provision_recursive_delete($path) {
$ret = $ret && $rm;
}
else {
$rm = provision_service('file')->unlink($path)
$rm = d()->service('file')->unlink($path)
->fail('Deleting @path file failed.')
->status();
$ret = $ret && $rm;
......
......@@ -128,7 +128,3 @@ class provisionService_null extends provisionService {
}
}
function provision_service($type, $object = null) {
return d()->service($type);
}
......@@ -57,7 +57,7 @@ class provisionConfig_ssl_vhost extends provisionConfig {
*/
function provision_ssl_provision_apache_delete_vhost($options) {
if ($options['ssl'] && $options['ssl_redirect']) {
provision_service('file')->unlink(drush_get_option('vhost_path') . '/' . drush_get_option('uri') . '_80')
d()->service('file')->unlink(drush_get_option('vhost_path') . '/' . drush_get_option('uri') . '_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