Commit 22e34296 authored by Adrian Rossouw's avatar Adrian Rossouw

introduce new type specific methods and command specific methods.

parent c9265bc8
......@@ -47,23 +47,21 @@ class provisionService_db extends provisionService {
);
}
function init() {
parent::init();
function init_server() {
parent::init_server();
$this->server->setProperty('master_db');
$this->creds = array_map('urldecode', parse_url($this->server->master_db));
return TRUE;
}
function verify() {
if ($this->context->type == 'server') {
$this->connect();
if ($this->can_create_database()) {
drush_log(dt('Provision can create new databases.'), 'message');
}
else {
drush_set_error('PROVISION_CREATE_DB_FAILED');
}
function verify_server_cmd() {
$this->connect();
if ($this->can_create_database()) {
drush_log(dt('Provision can create new databases.'), 'message');
}
else {
drush_set_error('PROVISION_CREATE_DB_FAILED');
}
}
......@@ -267,8 +265,8 @@ class provisionService_db_pdo extends provisionService_db {
protected $creds;
private $dsn;
function init() {
parent::init();
function init_server() {
parent::init_server();
$this->dsn = sprintf("%s:host=%s", $this->PDO_type, $this->creds['host']);
}
......
......@@ -12,8 +12,8 @@ class provisionService_http_apache extends provisionService_http_public {
return TRUE;
}
function init() {
parent::init();
function init_server() {
parent::init_server();
$this->configs['server'][] = 'provisionConfig_apache_server';
$this->configs['platform'][] = 'provisionConfig_apache_platform';
$this->configs['site'][] = 'provisionConfig_apache_site';
......
......@@ -79,8 +79,8 @@ class provisionService_http_public extends provisionService_http {
return $data;
}
function init() {
parent::init();
function init_server() {
parent::init_server();
// System account
if ($this->server->name == '@server_master') {
$this->server->setProperty('web_group', _provision_default_web_group());
......
......@@ -18,8 +18,8 @@ class provisionService_http_ssl extends provisionService_http_public {
return 443;
}
function init() {
parent::init();
function init_server() {
parent::init_server();
// SSL Port.
$this->server->setProperty('http_ssl_port', $this->default_ssl_port());
......@@ -34,6 +34,13 @@ class provisionService_http_ssl extends provisionService_http_public {
$this->server->http_ssld_path = "{$this->server->config_path}/ssl.d";
}
function init_site() {
parent::init_site();
$this->context->setProperty('ssl_enabled', 0);
$this->context->setProperty('ssl_key', null);
}
function config_data($config = null, $class = null) {
$data = parent::config_data($config, $class);
......
......@@ -194,23 +194,22 @@ class provisionContext {
* can fail safely.
*/
function __call($name, $args) {
$this->method_invoke($name, $args);
return false;
return $this->method_invoke($name, $args);
}
/**
* Execute a method on the object and all of it's associated
* services.
*/
function method_invoke($func, $args = array()) {
if (method_exists($this, $func)) {
call_user_func_array(array($this, $func), $args);
}
function method_invoke($func, $args = array(), $services = TRUE) {
provision::method_invoke($this, $func, $args);
// Services will be invoked regardless of the existence of a
// implementation in the context class.
$this->services_invoke($func, $args);
if ($services) {
$this->services_invoke($func, $args);
}
}
/**
* Execute the method for the current object type.
*
......@@ -256,6 +255,16 @@ class provisionContext {
$this->type = $matches[1];
$this->setProperty('context_type', $this->type);
// Set up the parent of this context object.
if (!is_null($this->parent_key)) {
$this->setProperty($this->parent_key);
$this->is_oid($this->parent_key);
}
// $this->server is always @server_master
$this->server = '@server_master';
$this->is_oid('server');
// Set up subscriptions for the available services.
$service_list = drush_command_invoke_all('provision_services');
foreach ($service_list as $service => $default) {
......@@ -346,7 +355,7 @@ class provisionContext {
// These may be on different servers entirely.
$services = $this->get_services();
foreach (array_keys($services) as $service) {
$results[$service] = $this->service($service)->$callback();
$results[$service] = provision::method_invoke($this->service($service), $callback, $args);
}
return $results;
}
......
......@@ -20,13 +20,8 @@ class provisionContext_platform extends provisionContext {
);
}
function init() {
parent::init();
function init_platform() {
$this->setProperty('root');
$this->setProperty('server', '@server_master');
$this->is_oid('server');
$this->setProperty('makefile', '');
}
}
......@@ -43,8 +43,7 @@ class provisionContext_server extends provisionContext {
return $options;
}
function init() {
parent::init();
function init_server() {
$this->setProperty('remote_host', 'localhost');
if ($this->name == '@server_master') {
......@@ -100,7 +99,6 @@ class provisionContext_server extends provisionContext {
drush_log("Loading $type driver for the $service service");
include_once($file);
$object = new $className($this->name);
$object->init();
$this->services[$service] = $object;
$this->setProperty($type_option, $type);
}
......
......@@ -21,18 +21,11 @@ class provisionContext_site extends provisionContext {
);
}
function init() {
$this->parent_key = 'platform';
parent::init();
$this->type = 'site';
$this->setProperty('platform');
$this->is_oid('platform');
function init_site() {
$this->setProperty('uri');
// we need to set the alias root to the platform root, otherwise drush will cause problems.
// we need to set the alias root to the platform root, otherwise drush will cause problems.
$this->root = $this->platform->root;
$this->setProperty('uri');
// set this because this path is accessed a lot in the code, especially in config files.
$this->site_path = $this->root . '/sites/' . $this->uri;
......@@ -43,10 +36,6 @@ class provisionContext_site extends provisionContext {
$this->setProperty('aliases', array(), TRUE);
$this->setProperty('redirection', FALSE);
// TODO :: figure out how to put this into service classes.
$this->setProperty('ssl_enabled', 0);
$this->setProperty('ssl_key', null);
// this can potentially be handled by a Drupal sub class
$this->setProperty('profile', 'default');
}
......
......@@ -372,6 +372,26 @@ class provisionException_continue extends provisionException {
}
/**
* Provision class.
*
* This is just a container for some useful static methods.
*/
class provision {
/**
* The actual body of the method_invoke function.
*
* This is a static method so it can be re-used by some other classes
* that aren't contexts. (notably services and configs).
*/
static function method_invoke($object, $func, $args = array()) {
if (method_exists($object, $func)) {
return call_user_func_array(array($object, $func), $args);
}
}
}
include_once('provision.context.inc');
include_once('provision.context.server.inc');
......
......@@ -27,17 +27,17 @@ class provisionService extends provisionChainedState {
* This is used so that we can create methods for drush commands, and
* can fail safely.
*/
function __call($name, $args) {
if (method_exists($this, $name)) {
return call_user_func_array(array($this, $name), $args);
}
return false;
function __call($name, $args = array()) {
return provision::method_invoke($this, $name, $args);
}
// All services have the ability to have an associated restart command and listen port.
function init() {
}
// All services have the ability to have an associated restart command and listen port.
function init_server() {
if (!is_null($this->service)) {
if ($this->has_port) {
$this->server->setProperty($this->service . '_port', $this->default_port());
......@@ -49,6 +49,15 @@ class provisionService extends provisionChainedState {
return TRUE;
}
function init_platform() {
}
function init_site() {
}
function default_port() {
return false;
}
......
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