Commit cbe61d07 authored by drumm's avatar drumm Committed by Neil Drumm

Move defaults setting code into services and work on service initialization.

parent 8581230f
......@@ -12,13 +12,49 @@
include_once(dirname(__FILE__) . '/../provision.service.inc');
function db_drush_init($url = null) {
include_once('mysql/mysql_service.inc');
// todo same as http, consolidate
$command = drush_get_command();
$command = explode(" ", $command['command']);
if (preg_match("/^provision-/", $command[0])) {
_provision_context_init($url);
// TODO - remove this shit
if (PROVISION_CONTEXT_SERVER) {
if (!is_null(drush_get_option('init_db'))) {
// Bootstrap for alias creation.
include_once(drush_get_option('init_db') . '/'. drush_get_option('init_db') .'_service.inc');
$class = 'provisionService_db_' . drush_get_option('init_db');
provision_service('db', new $class());
}
}
else {
// todo should be constructed based on drush aliases
include_once('mysql/mysql_service.inc');
provision_service('db', new provisionService_db_mysql());
}
}
// this is where we generate the db service object.
}
function db_drush_exit() {
// determine how to close it too.
provision_service('db')->close();
}
function db_drush_help($section) {
switch ($section) {
case 'error:PROVISION_CREATE_DB_FAILED' :
return dt('Unable to create new databases.');
case 'error:PROVISION_DROP_DB_FAILED' :
return dt('Unable to drop database.');
}
}
class provisionService_db extends provisionService {
function __construct() {
$master_db = drush_get_option('master_db');
if ($master_db) {
......@@ -61,37 +97,9 @@ function db_drush_init($url = null) {
foreach ($options as $option => $key) {
$creds[$key] = drush_get_option($option, '');
}
provision_service('db', new provisionService_db_mysql($creds));
}
// this is where we generate the db service object.
}
function db_drush_exit() {
// determine how to close it too.
provision_service('db')->close();
}
function db_drush_help($section) {
switch ($section) {
case 'error:PROVISION_CREATE_DB_FAILED' :
return dt('Unable to create new databases.');
case 'error:PROVISION_DROP_DB_FAILED' :
return dt('Unable to drop database.');
}
}
class provisionService_db extends provisionService {
function __construct($creds) {
$this->creds = $creds;
}
function verify() {
if (!$this->can_create_database()) {
drush_set_error('PROVISION_CREATE_DB_FAILED');
......@@ -323,11 +331,10 @@ class provisionService_db_pdo extends provisionService_db {
protected $creds;
private $dsn;
function __construct($creds) {
parent::__construct($creds);
function __construct() {
parent::__construct();
$this->dsn = sprintf("%s:host=%s", $this->PDO_type, $this->creds['host']);
}
function connect() {
......
......@@ -3,14 +3,33 @@
include_once(dirname(__FILE__) . '/../provision.service.inc');
function http_drush_init($url = null) {
// todo same as http, consolidate
$command = drush_get_command();
$command = explode(" ", $command['command']);
if (preg_match("/^provision-/", $command[0])) {
_provision_context_init($url);
include_once('apache/apache_service.inc');
provision_service('http', new provisionService_http_apache());
if (PROVISION_CONTEXT_SERVER) {
if (!is_null(drush_get_option('init_http'))) {
// Bootstrap for alias creation.
include_once(drush_get_option('init_http') . '/'. drush_get_option('init_http') .'_service.inc');
$class = 'provisionService_http_' . drush_get_option('init_http');
provision_service('http', new $class());
}
}
else {
// todo should be constructed based on drush aliases
include_once('apache/apache_service.inc');
provision_service('http', new provisionService_http_apache());
}
}
}
class provisionService_http extends provisionService {
/**
* Set defaults
*/
function __construct() {
// Set up defines for platform
$docroot = drush_get_option(array("r", "root"), $_SERVER['PWD']);
......@@ -50,11 +69,6 @@ function http_drush_init($url = null) {
drush_set_default('site_port', 80);
}
}
class provisionService_http extends provisionService {
/**
* Ask the web server to check for and load configuration changes.
*/
......
......@@ -67,13 +67,12 @@ function _provision_context_init($url) {
return TRUE;
}
$context = 'server';
if (drush_bootstrap_validate(DRUSH_BOOTSTRAP_DRUPAL_ROOT)) {
$context = drush_get_option('provision_context');
// todo could probably clean this up, may want to throw errors
if (($context === 'platform' || $context === 'site') && drush_bootstrap_validate(DRUSH_BOOTSTRAP_DRUPAL_ROOT)) {
// i don't think i should be bootstrapping here yet ... but i have no choice yet.
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_ROOT);
$context = 'platform';
if ($url) {
$context = 'site';
if ($context === 'site' && $url) {
drush_set_option('uri' , 'http://' . $url);
drush_set_default('site_url', $url);
drush_set_default('profile', 'default');
......
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