Commit 0a8ae41b authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

#407334 - Refactor to use the drush_context API instead of passing a reference to the $args global

parent 1fc87b2b
<?php <?php
function provision_mysql_provision_pre_backup(&$data, $url = NULL) { function provision_mysql_provision_pre_backup($url = NULL) {
drush_log("Generating mysql dump for $url.", 'backup'); drush_log("Generating mysql dump for $url.", 'backup');
provision_shell_exec("mysqldump -u%s -p%s %s > sites/%s/database.sql", $data['db_user'], $data['db_passwd'], $data['db_name'], $url); provision_shell_exec("mysqldump -u%s -p%s %s > sites/%s/database.sql", drush_get_option('db_user'), drush_get_option('db_passwd'), drush_get_option('db_name'), $url);
} }
function provision_mysql_provision_pre_backup_rollback(&$data, $url = NULL) { function provision_mysql_provision_pre_backup_rollback($url = NULL) {
provision_path("unlink", PROVISION_SITES_PATH . "/$url/database.sql", TRUE, dt("Deleted mysql dump from sites directory"), provision_path("unlink", drush_get_option('sites_path') . "/$url/database.sql", TRUE, dt("Deleted mysql dump from sites directory"),
dt("Could not delete mysql dump from sites directory")); dt("Could not delete mysql dump from sites directory"));
} }
function provision_mysql_provision_post_backup(&$data, $url = NULL) { function provision_mysql_provision_post_backup($url = NULL) {
provision_mysql_provision_pre_backup_rollback($data, $url); provision_mysql_provision_pre_backup_rollback($url);
} }
...@@ -10,7 +10,9 @@ function provision_mysql_provision_delete_validate() { ...@@ -10,7 +10,9 @@ function provision_mysql_provision_delete_validate() {
* *
* This will drop the database, revoke the privileges and flush the privileges. * This will drop the database, revoke the privileges and flush the privileges.
*/ */
function provision_mysql_provision_delete(&$data, $url = NULL) { function provision_mysql_provision_delete($url = NULL) {
return _provision_mysql_destroy_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']); return _provision_mysql_destroy_site_db(
drush_get_option('db_name'), drush_get_option('db_user'),
drush_get_option('db_passwd'), drush_get_option('db_host'));
} }
...@@ -4,26 +4,32 @@ function provision_mysql_provision_deploy_validate() { ...@@ -4,26 +4,32 @@ function provision_mysql_provision_deploy_validate() {
provision_db_connect(); provision_db_connect();
} }
function provision_mysql_provision_deploy(&$data, $url) { function provision_mysql_provision_deploy($url) {
# generate a random password for use $db_type = drush_set_option('db_type', drush_get_option('db_type'), 'site');
$data['db_passwd'] = provision_password(); $db_host = drush_set_option('db_host', drush_get_option('db_host'), 'site');
$data['db_name'] = _provision_mysql_suggest_db_name($data, $url); $db_passwd = drush_set_option('db_passwd', provision_password(), 'site');
$data['db_user'] = $data['db_name']; $db_name = drush_set_option('db_name', _provision_mysql_suggest_db_name($url), 'site');
$db_user = drush_set_option('db_user', $db_name, 'site');
_provision_mysql_new_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']); _provision_mysql_new_site_db($db_name, $db_user, $db_passwd, $db_host);
_provision_mysql_import_dump(PROVISION_SITES_PATH .'/'. $url .'/database.sql', $data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']); _provision_mysql_import_dump(
drush_get_option('sites_path') .'/'. $url .'/database.sql',
$db_name, $db_user, $db_passwd, $db_host );
} }
function provision_mysql_provision_deploy_rollback(&$data, $url = NULL) { function provision_mysql_provision_deploy_rollback($url = NULL) {
_provision_mysql_destroy_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']); _provision_mysql_destroy_site_db(
drush_get_option('db_name'), drush_get_option('db_user'),
drush_get_option('db_passwd'), drush_get_option('db_host')
);
} }
// 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 provision_mysql_provision_post_deploy(&$data, $url = NULL) { function provision_mysql_provision_post_deploy($url = NULL) {
provision_path('unlink', 'sites/'. $url .'/database.sql', TRUE, provision_path('unlink', drush_get_option('sites_path') .'/'. $url .'/database.sql', TRUE,
dt("Removed dump file @path after restoring from it"), dt("Removed dump file @path after restoring from it"),
dt("Could not remove dump file @path"), DRUSH_PERM_ERROR); dt("Could not remove dump file @path"), DRUSH_PERM_ERROR);
} }
...@@ -4,23 +4,19 @@ function provision_mysql_provision_install_validate() { ...@@ -4,23 +4,19 @@ function provision_mysql_provision_install_validate() {
provision_db_connect(); provision_db_connect();
} }
function provision_mysql_provision_pre_install(&$data, $url = NULL) { function provision_mysql_provision_pre_install($url = NULL) {
$data['db_type'] = ($data['db_type']) ? $data['db_type'] : PROVISION_DB_TYPE; $db_type = drush_set_option('db_type', drush_get_option('db_type'), 'site');
$data['db_host'] = ($data['db_host']) ? $data['db_host'] : PROVISION_DB_HOST; $db_host = drush_set_option('db_host', drush_get_option('db_host'), 'site');
$db_passwd = drush_set_option('db_passwd', provision_password(), 'site');
$db_name = drush_set_option('db_name', _provision_mysql_suggest_db_name($url), 'site');
$db_user = drush_set_option('db_user', $db_name, 'site');
# generate a random password for use _provision_mysql_new_site_db($db_name, $db_user, $db_passwd, $db_host);
$data['db_passwd'] = provision_password();
$data['db_name'] = _provision_mysql_suggest_db_name($data, $url);
$data['db_user'] = $data['db_name'];
_provision_mysql_new_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']);
} }
function provision_mysql_provision_pre_install_rollback(&$data, $url = NULL) { function provision_mysql_provision_pre_install_rollback($url = NULL) {
_provision_mysql_destroy_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']); _provision_mysql_destroy_site_db(
unset($data['db_host']); drush_get_option('db_name'), drush_get_option('db_user'),
unset($data['db_type']); drush_get_option('db_passwd'), drush_get_option('db_host')
unset($data['db_passwd']); );
unset($data['db_user']);
unset($data['db_name']);
} }
...@@ -18,7 +18,7 @@ function provision_db_connect() { ...@@ -18,7 +18,7 @@ function provision_db_connect() {
if (_provision_db_connection()) { if (_provision_db_connection()) {
return TRUE; return TRUE;
} }
$connection = @mysql_connect(PROVISION_DB_HOST, PROVISION_DB_USER, PROVISION_DB_PASSWD); $connection = @mysql_connect(drush_get_option('master_db_host'), drush_get_option('master_db_user'), drush_get_option('master_db_passwd'));
if (!$connection) { if (!$connection) {
drush_set_error('PROVISION_MASTER_DB_FAILED', dt('Could not connect to the master database.'), 'error'); drush_set_error('PROVISION_MASTER_DB_FAILED', dt('Could not connect to the master database.'), 'error');
......
...@@ -62,7 +62,7 @@ function _provision_mysql_new_site_db($db_name, $db_user, $db_passwd, $db_host) ...@@ -62,7 +62,7 @@ function _provision_mysql_new_site_db($db_name, $db_user, $db_passwd, $db_host)
*/ */
function _provision_mysql_destroy_site_db($db_name, $db_user, $db_passwd, $db_host) { function _provision_mysql_destroy_site_db($db_name, $db_user, $db_passwd, $db_host) {
if ( _provision_mysql_database_exists($data['db_name']) ) { if ( _provision_mysql_database_exists($db_name) ) {
drush_log(dt("Dropping database @dbname", array('@dbname' => $db_name))); drush_log(dt("Dropping database @dbname", array('@dbname' => $db_name)));
if (!_provision_mysql_drop_database($db_name)) { if (!_provision_mysql_drop_database($db_name)) {
drush_log(dt("Failed to drop database @dbname", array('@dbname' => $db_name)), 'warning'); drush_log(dt("Failed to drop database @dbname", array('@dbname' => $db_name)), 'warning');
...@@ -147,9 +147,9 @@ function _provision_mysql_import_dump($dump_file, $db_name, $db_user, $db_passwd ...@@ -147,9 +147,9 @@ function _provision_mysql_import_dump($dump_file, $db_name, $db_user, $db_passwd
* possible that sites will be running with derivative names on the same server, * possible that sites will be running with derivative names on the same server,
* until the upgrade / restore process is completed. * until the upgrade / restore process is completed.
*/ */
function _provision_mysql_suggest_db_name($data, $url) { function _provision_mysql_suggest_db_name($url) {
if ($data['site_id']) { if ($sid = drush_get_option('site_id')) {
$id_suggest = 'site_'. $data['site_id']; $id_suggest = 'site_'. $sid;
$suggest[] = $id_suggest; $suggest[] = $id_suggest;
for ($i = 0; $i < 100; $i++) { for ($i = 0; $i < 100; $i++) {
$suggest[] = $id_suggest .'_'. $i; $suggest[] = $id_suggest .'_'. $i;
......
...@@ -4,43 +4,59 @@ function provision_mysql_provision_restore_validate() { ...@@ -4,43 +4,59 @@ function provision_mysql_provision_restore_validate() {
provision_db_connect(); provision_db_connect();
} }
function provision_mysql_provision_pre_restore(&$data, $url = NULL) { function provision_mysql_provision_pre_restore($url = NULL) {
// store a backup of the credentials of the site. $db_type = drush_set_option('db_type', drush_get_option('db_type'));
$data['old_db_name'] = $data['db_name']; $db_host = drush_set_option('db_host', drush_get_option('db_host'));
$data['old_db_passwd'] = $data['db_passwd']; $db_passwd = drush_set_option('db_passwd', provision_password());
$data['old_db_user'] = $data['db_user']; $db_name = drush_set_option('db_name', _provision_mysql_suggest_db_name($url));
$data['old_db_host'] = $data['db_host']; $db_user = drush_set_option('db_user', $db_name);
# generate a random password for use _provision_mysql_new_site_db($db_name, $db_user, $db_passwd, $db_host);
$data['db_passwd'] = provision_password();
$data['db_name'] = _provision_mysql_suggest_db_name($data, $url);
$data['db_user'] = $data['db_name'];
_provision_mysql_new_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']);
} }
function provision_mysql_provision_restore(&$data, $url) { function provision_mysql_provision_restore($url) {
_provision_mysql_import_dump(PROVISION_SITES_PATH .'/'. $url .'/database.sql', $data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']); _provision_mysql_import_dump(
drush_get_option('sites_path') .'/'. $url .'/database.sql',
drush_get_option('db_name'), drush_get_option('db_user'),
drush_get_option('db_passwd'), drush_get_option('db_host')
);
} }
function provision_mysql_provision_pre_restore_rollback(&$data, $url = NULL) { function provision_mysql_provision_pre_restore_rollback($url = NULL) {
_provision_mysql_destroy_site_db($data['db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']); _provision_mysql_destroy_site_db(
drush_get_option('db_name'), drush_get_option('db_user'),
drush_get_option('db_passwd'), drush_get_option('db_host'));
$keys = array('db_name', 'db_passwd', 'db_user', 'db_host'); $keys = array('db_name', 'db_passwd', 'db_user', 'db_host');
//Restore the original database credentials of the site. //Restore the original database credentials of the site.
// They were never truly lost, but the options in the 'process' context
// were overriding them. By unsetting the temporary options, the originals
// are automatically restored.
foreach ($keys as $key) { foreach ($keys as $key) {
$data[$key] = $data['old_'. $key]; drush_unset_option($key, 'process');
} }
} }
// 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 provision_mysql_provision_post_restore(&$data, $url = NULL) { function provision_mysql_provision_post_restore($url = NULL) {
print_r($data); provision_path('unlink', drush_get_option('sites_path') . '/' . $url .'/database.sql', TRUE,
provision_path('unlink', 'sites/'. $url .'/database.sql', TRUE,
dt("Removed dump file @path after restoring from it"), dt("Removed dump file @path after restoring from it"),
dt("Could not remove dump file @path"), DRUSH_PERM_ERROR); dt("Could not remove dump file @path"), DRUSH_PERM_ERROR);
#_provision_mysql_destroy_site_db($data['old_db_name'], $data['old_db_user'], $data['old_db_passwd'], $data['old_db_host']);
// We have now completed successfully, remove the old database.
_provision_mysql_destroy_site_db(
drush_get_option('db_name', null, 'site'), drush_get_option('db_user', null, 'site'),
drush_get_option('db_passwd', null, 'site'), drush_get_option('db_host', null, 'site')
);
// The new database credentials will be saved against the site now.
drush_set_option('db_name', drush_get_option('db_name'), 'site');
drush_set_option('db_type', drush_get_option('db_type'), 'site');
drush_set_option('db_user', drush_get_option('db_user'), 'site');
drush_set_option('db_host', drush_get_option('db_host'), 'site');
drush_set_option('db_passwd', drush_get_option('db_passwd'), 'site');
} }
...@@ -20,3 +20,9 @@ function provision_mysql_provision_verify() { ...@@ -20,3 +20,9 @@ function provision_mysql_provision_verify() {
} }
} }
function provision_mysql_provision_post_verify() {
if (PROVISION_CONTEXT_PLATFORM) {
drush_set_option('master_db', drush_get_option('master_db'), 'platform');
}
}
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* need to lookup the zid for the base zone of this site, and then call provision_dns_rr with the zid and site 'name' * need to lookup the zid for the base zone of this site, and then call provision_dns_rr with the zid and site 'name'
* (ie: pull off the tld and second-level domain for the 'base' zone, and treat the rest as the 'name') * (ie: pull off the tld and second-level domain for the 'base' zone, and treat the rest as the 'name')
*/ */
function provision_dns_provision_delete(&$data, $url = NULL) { function provision_dns_provision_delete($url = NULL) {
if ($url) { if ($url) {
# provision_dns_delete($url); # provision_dns_delete($url);
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
/** /**
* Implementation of hook_provision_pre_install * Implementation of hook_provision_pre_install
**/ **/
function provision_dns_provision_pre_install(&$data, $url = NULL) { function provision_dns_provision_pre_install($url = NULL) {
# data should now contain zone info directly, rather than having to pull them from # data should now contain zone info directly, rather than having to pull them from
if ($url) { if ($url) {
# $url_parts = _provision_dns_split_url($url); # $url_parts = _provision_dns_split_url($url);
...@@ -20,16 +20,16 @@ function provision_dns_provision_pre_install(&$data, $url = NULL) { ...@@ -20,16 +20,16 @@ function provision_dns_provision_pre_install(&$data, $url = NULL) {
# } # }
# the zone object should be passed in.. # the zone object should be passed in..
# $zone = provision_dns_create_zone($url_parts['zone'], $data); # initialize zone for this domain (if it doesn't exist) # $zone = provision_dns_create_zone($url_parts['zone']); # initialize zone for this domain (if it doesn't exist)
# provision_dns_create_record($url_parts['host'], $zone, $data); # creates the RR for the (sub)domain # provision_dns_create_record($url_parts['host'], $zone); # creates the RR for the (sub)domain
# provision_dns_commit($data['dns_id']); # makes the changes live (ie: restart bind) # provision_dns_commit(drush_get_option('dns_id')); # makes the changes live (ie: restart bind)
} }
} }
/** /**
* Implementation of hook_provision_pre_install_rollback * Implementation of hook_provision_pre_install_rollback
**/ **/
function provision_dns_provision_pre_install_rollback(&$data, $url = NULL) { function provision_dns_provision_pre_install_rollback($url = NULL) {
if ($url) { if ($url) {
# provision_dns_delete($url); # provision_dns_delete($url);
} }
...@@ -38,6 +38,6 @@ function provision_dns_provision_pre_install_rollback(&$data, $url = NULL) { ...@@ -38,6 +38,6 @@ function provision_dns_provision_pre_install_rollback(&$data, $url = NULL) {
/** /**
* Implementation of hook_provision_post_install * Implementation of hook_provision_post_install
**/ **/
function provision_dns_provision_post_install(&$data, $url = NULL) { function provision_dns_provision_post_install($url = NULL) {
# commit and restart bind # commit and restart bind
} }
...@@ -17,26 +17,25 @@ include_once('provision_dns.bind.inc'); ...@@ -17,26 +17,25 @@ include_once('provision_dns.bind.inc');
* *
* @param $domain * @param $domain
* The domain name/origin for the zone to be created. * The domain name/origin for the zone to be created.
* @param $data
* An array of data to populate the new zone. Most importantly, the 'dns_id'
* field must contain the nid of the DNS server which on which to privision this zone.
* *
* @return * @return
* The zone object, whether newly created, or already existing. * The zone object, whether newly created, or already existing.
**/ **/
function provision_dns_create_zone($domain, $data) { function provision_dns_create_zone($domain) {
$writable = provision_path("writable", PROVISION_NAMED_PATH, TRUE, NULL, /*
$writable = provision_path("writable", PROVISION_NAMED_PATH, TRUE, NULL,
t("DNS configuration path @path is not writable"), t("DNS configuration path @path is not writable"),
PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR); PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR);
*/
# if ($zone = provision_dns_status('zone', array('domain' => $domain))) { # if ($zone = provision_dns_status('zone', array('domain' => $domain))) {
# drush_log("Notice", t("Loading zone file for url @url", array('@url' => $domain))); # drush_log("Notice", t("Loading zone file for url @url", array('@url' => $domain)));
# return $zone; # return $zone;
# } else { # } else {
drush_log("Notice", dt("Generating zone file for url @url on dns server @id", array('@url' => $domain, '@id' => $data['dns_id']))); /**
drush_log("Notice", dt("Generating zone file for url @url on dns server @id", array('@url' => $domain, '@id' => drush_get_option('dns_id'))));
# Setup args array from defaults # Setup args array from defaults
$dns = node_load($data['dns_id']); $dns = node_load(drush_get_option('dns_id'));
$zone_fields['dns_id'] = $data['dns_id']; $zone_fields['dns_id'] = drush_get_option('dns_id');
$zone_fields['origin'] = $domain; $zone_fields['origin'] = $domain;
$zone_fields['serial'] = date('Ymd') . '01'; $zone_fields['serial'] = date('Ymd') . '01';
$ns_recs = explode("\n", $dns->ns); $ns_recs = explode("\n", $dns->ns);
...@@ -46,6 +45,7 @@ drush_log("notice", "provision_dns_create_zone ns_recs: ".$ns_recs[0].", ".$ns_r ...@@ -46,6 +45,7 @@ drush_log("notice", "provision_dns_create_zone ns_recs: ".$ns_recs[0].", ".$ns_r
$zone_fields['ns2'] = $ns_recs[1]; $zone_fields['ns2'] = $ns_recs[1];
$zone_fields['mbox'] = $dns->mbox; $zone_fields['mbox'] = $dns->mbox;
provision_dns_zone('add', $zone_fields); provision_dns_zone('add', $zone_fields);
*/
# $zone = provision_dns_status('zone', array('domain' => $domain)); # $zone = provision_dns_status('zone', array('domain' => $domain));
# foreach ($ns_recs as $ns) { # foreach ($ns_recs as $ns) {
# provision_dns_create_record('@', $zone, array('type' => 'NS', 'dns_ip' => trim($ns))); # provision_dns_create_record('@', $zone, array('type' => 'NS', 'dns_ip' => trim($ns)));
...@@ -61,18 +61,15 @@ drush_log("notice", "provision_dns_create_zone ns_recs: ".$ns_recs[0].", ".$ns_r ...@@ -61,18 +61,15 @@ drush_log("notice", "provision_dns_create_zone ns_recs: ".$ns_recs[0].", ".$ns_r
* The name part of the record to be created. * The name part of the record to be created.
* @param $zone * @param $zone
* The zone object in which to create the record. * The zone object in which to create the record.
* @param $data
* An array of data used to populate the record. Most importantly, the 'dns_ip' field should
* contain the IP address which the host record should point to.
* *
* @return * @return
* The record object, or FALSE if the record could not be created. * The record object, or FALSE if the record could not be created.
**/ **/
function provision_dns_create_record($host, $zone, $data) { function provision_dns_create_record($host, $zone) {
drush_log(dt("Creating %type record for url @url", array('%type' => $data['type'], '@url' => $host))); drush_log(dt("Creating %type record for url @url", array('%type' => drush_get_option('type'), '@url' => $host)));
$rec['name'] = $host; $rec['name'] = $host;
$rec['type'] = $data['type']?$data['type']:'A'; $rec['type'] = drush_get_option('type');
$rec['data'] = $data['dns_ip']; $rec['data'] = drush_get_option('dns_ip');
return provision_dns_rr('add', $zone->zid, $rec); return provision_dns_rr('add', $zone->zid, $rec);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Implementation of hook_provision_pre_restore * Implementation of hook_provision_pre_restore
* This is a duplicate of the _pre_install hook * This is a duplicate of the _pre_install hook
**/ **/
function provision_dns_provision_pre_restore(&$data, $url = NULL) { function provision_dns_provision_pre_restore($url = NULL) {
# re-install the zonefiles and/or resource records for the site? # re-install the zonefiles and/or resource records for the site?
# _provision_dns_provision_pre_restore($url, $data); # _provision_dns_provision_pre_restore($url, $data);
} }
...@@ -20,17 +20,17 @@ function provision_dns_provision_pre_restore(&$data, $url = NULL) { ...@@ -20,17 +20,17 @@ function provision_dns_provision_pre_restore(&$data, $url = NULL) {
* Implementation of hook_provision_pre_restore_rollback * Implementation of hook_provision_pre_restore_rollback
* This duplicates the _pre_install_rollback hook * This duplicates the _pre_install_rollback hook
**/ **/
function provision_dns_provision_pre_restore_rollback(&$data, $url = NULL) { function provision_dns_provision_pre_restore_rollback($url = NULL) {
# remove them again? # remove them again?
if ($url) { if ($url) {
# _provision_dns_delete($url); # _provision_dns_delete($url);
} }
} }
function provision_dns_provision_post_restore(&$data, $url = NULL) { function provision_dns_provision_post_restore($url = NULL) {
# restart bind? # restart bind?
} }
function provision_dns_provision_post_restore_rollback(&$data, $url = NULL) { function provision_dns_provision_post_restore_rollback($url = NULL) {
# restart bind # restart bind
} }
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
* *
* Can't be rolled back. * Can't be rolled back.
*/ */
function provision_dns_provision_verify(&$data, $url = NULL) { /*
function provision_dns_provision_verify($url = NULL) {
if (!$url) { if (!$url) {
// we are verifying a platform // we are verifying a platform
# Where does this constant come from now? # Where does this constant come from now?
...@@ -29,9 +30,9 @@ function provision_dns_provision_verify(&$data, $url = NULL) { ...@@ -29,9 +30,9 @@ function provision_dns_provision_verify(&$data, $url = NULL) {
return; return;
} }
# $zone = provision_dns_create_zone($url_parts['zone'], $data); # initializes the zone for the domain (if it doesn't exist) # $zone = provision_dns_create_zone($url_parts['zone']); # initializes the zone for the domain (if it doesn't exist)
# provision_dns_create_record($url_parts['host'], $zone, $data); # creates the RR for the (sub)domain # provision_dns_create_record($url_parts['host'], $zone); # creates the RR for the (sub)domain
# provision_dns_commit($data['dns_id']); # makes the changes live (ie: restart bind) # provision_dns_commit(drush_get_option('dns_id')); # makes the changes live (ie: restart bind)
} }
} }
*/
...@@ -10,6 +10,6 @@ ...@@ -10,6 +10,6 @@
/** /**
* implementation of hook_provision_vhost_extra * implementation of hook_provision_vhost_extra
*/ */
function provision_itk_provision_vhost_config($url, $data) { function provision_itk_provision_vhost_config($url) {
return "# Configur ITK permissions\nAssignUserID ". $data['web_user'] . ' #' . $data['web_group'] . "\n"; return "# Configur ITK permissions\nAssignUserID ". drush_get_option('web_user') . ' #' . drush_get_option('web_group') . "\n";
} }
...@@ -9,43 +9,45 @@ ...@@ -9,43 +9,45 @@
/** /**
* Make sure the site is installed and enabled, and that we have a valid target to back up to. * Make sure the site is installed and enabled, and that we have a valid target to back up to.
*/ */
function provision_drupal_provision_backup_validate(&$data, $url = NULL, $backup_file = NULL) { function provision_drupal_provision_backup_validate($url = NULL, $backup_file = NULL) {
_provision_drupal_url_required(); _provision_drupal_url_required();
_provision_drupal_valid_installed_site(); _provision_drupal_valid_installed_site();
// This is the actual drupal provisioning requirements. // This is the actual drupal provisioning requirements.
if (!is_dir(PROVISION_BACKUP_PATH)) { if (!is_dir(drush_get_option('backup_path'))) {
drush_set_error(PROVISION_BACKUP_PATH_NOT_FOUND); drush_set_error(PROVISION_BACKUP_PATH_NOT_FOUND);
} }
if ($backup_file) { if ($backup_file) {
if ( provision_path("exists", $backup_file, FALSE, if ( provision_path("exists", $backup_file, FALSE,
dt("Backing site up to @path."), dt("Backing site up to @path."),
dt("Back up file @path already exists."), dt("Back up file @path already exists."),
PROVISION_BACKUP_ALREADY_EXISTS)) { PROVISION_BACKUP_ALREADY_EXISTS)) {
$data['backup_file'] = $backup_file; drush_get_option('backup_file', $backup_file);
} }
} }
if (!$backup_file) { if (!$backup_file) {
$suggested = PROVISION_BACKUP_PATH ."/$url-". date("Y-m-d", mktime()) .".tar"; $suggested = drush_get_option('backup_path') ."/$url-". date("Y-m-d", mktime()) .".tar";
// Use format of mysite.com-2008-01-02, if already existing, add number. // Use format of mysite.com-2008-01-02, if already existing, add number.
while (is_file($suggested .'.gz')) { while (is_file($suggested .'.gz')) {
$count++; $count++;
$suggested = PROVISION_BACKUP_PATH ."/$url-". date("Y-m-d", mktime()) ."_$count.tar"; $suggested = drush_get_option('backup_path') ."/$url-". date("Y-m-d", mktime()) ."_$count.tar";
} }
$data['backup_file'] = (!empty($file)) ? ereg_replace('.gz$', '', $file) : $suggested; drush_set_option('backup_file', str_replace(".gz" , '', $suggested));
} }
} }
/** /**
* Implentation of hook_provision_backup() * Implentation of hook_provision_backup()
*/ */
function provision_drupal_provision_backup(&$data, $url, $backup_file) { function provision_drupal_provision_backup($url) {
$backup_file = drush_get_option('backup_file');
// Adds the site directory into the backup file // Adds the site directory into the backup file
drush_log("Adding sites directory to $data[backup_file].gz", 'backup'); drush_log(dt("Adding sites directory to !backup_file", array('!backup_file' => $backup_file)), 'backup');
$result = provision_shell_exec("cd %s; tar -rf %s * ", "sites/$url", $data['backup_file']); $result = provision_shell_exec("cd %s; tar -rf %s * ", drush_get_option('sites_path') . "/$url", $backup_file);
if (!$result) { if (!$result) {
drush_set_error(PROVISION_BACKUP_FAILED, dt("Could not back up sites directory for drupal")); drush_set_error(PROVISION_BACKUP_FAILED, dt("Could not back up sites directory for drupal"));
...@@ -56,7 +58,9 @@ function provision_drupal_provision_backup(&$data, $url, $backup_file) { ...@@ -56,7 +58,9 @@ function provision_drupal_provision_backup(&$data, $url, $backup_file) {
/** /**
* Generate a backup tarbal for a site. * Generate a backup tarbal for a site.
*/ */
function provision_drupal_provision_post_backup(&$data, $url, $backup_file = NULL) { function provision_drupal_provision_post_backup($url, $backup_file = NULL) {
provision_shell_exec("gzip %s", $data['backup_file']); $backup_file = drush_get_option('backup_file');
$data['backup_file'] = $data['backup_file'] .'.gz';
provision_shell_exec("gzip %s", $backup_file);
drush_set_option('backup_file', $backup_file . '.gz');
} }
...@@ -12,7 +12,7 @@ function provision_drupal_provision_cron_verify() { ...@@ -12,7 +12,7 @@ function provision_drupal_provision_cron_verify() {
/** /**
* Drush command to run cron * Drush command to run cron
*/ */
function _provision_cron(&$data, $url) { function _provision_cron($url) {
_provision_drupal_rebuild_caches($url); _provision_drupal_rebuild_caches($url);
} }
<?php <?php
function provision_drupal_provision_delete_validate(&$data, $url = NULL, $backup_file = NULL) { function provision_drupal_provision_delete_validate($url = NULL, $backup_file = NULL) {
_provision_drupal_valid_site(); _provision_drupal_valid_site();
} }
...@@ -9,24 +9,24 @@ function provision_drupal_provision_delete_validate(&$data, $url = NULL, $backup ...@@ -9,24 +9,24 @@ function provision_drupal_provision_delete_validate(&$data, $url = NULL, $backup
/** /**
* Before starting to delete the site, make a backup * Before starting to delete the site, make a backup
*/ */
function provision_drupal_provision_pre_delete(&$data, $url, $backup_file) { function provision_drupal_provision_pre_delete($url, $backup_file) {
// @TODO : fix the inline calling of provision_invoke // @TODO : fix the inline calling of provision_invoke
provision_invoke('backup', $data, $url, $backup_file); provision_invoke('backup', $url, $backup_file);
} }
/** /**
* Remove any directories for the site in sites * Remove any directories for the site in sites
* This can't be rolled back. so won't even try. * This can't be rolled back. so won't even try.
*/ */
function provision_drupal_provision_delete(&$data, $url) { function provision_drupal_provision_delete($url) {
if ($old_data = provision_load_site_data($url)) { $old_aliases = drush_get_option('aliases', array(), 'site');
if (sizeof($old_aliases = $old_data['aliases'])) {
_provision_drupal_delete_aliases($old_aliases); if (sizeof($old_aliases) == sizeof(drush_get_option('aliases'))) {
} _provision_drupal_delete_aliases($old_aliases);
} }
_provision_recursive_delete("sites/$url"); _provision_recursive_delete(drush_get_option('sites_path') . "/$url");
</