Commit 9ce2679e authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

Missing return to db create function. Added additional error checking. Become...

Missing return to db create function. Added additional error checking. Become more stringent about regenerating the config files. Wrong path to database.sql
parent b6b84612
......@@ -29,7 +29,10 @@ function _provision_mysql_new_site_db($db_name, $db_user, $db_passwd, $db_host)
_provision_mysql_old_password($db_user, $db_passwd, $db_host);
}
_provision_mysql_flush();
$status = _provision_mysql_database_exists($db_name);
provision_set_active_db();
return $status;
#TODO : Test to confirm that the database is actually writeable. Taking this on faith for now.
}
......@@ -116,6 +119,8 @@ function _provision_mysql_import_dump($dump_file, $db_name, $db_user, $db_passwd
t('The database dump at @path could not be read.'),
PROVISION_PERM_ERROR);
if ($readable) {
provision_log("notice", sprintf("Importing database using command: mysql -u%s -p%s -h%s %s < %s",
$db_user, $db_passwd, $db_host, $db_name, $dump_file));
provision_shell_exec("mysql -u%s -p%s -h%s %s < %s",
$db_user, $db_passwd, $db_host, $db_name, $dump_file );
}
......
......@@ -109,7 +109,7 @@ function provision_mysql_provision_pre_install($url, &$data) {
}
function provision_mysql_provision_pre_install_rollback($url, &$data) {
_provision_mysql_destroy_site_db($data['site_db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']);
_provision_mysql_destroy_site_db($data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
unset($data['site_db_host']);
unset($data['site_db_type']);
unset($data['site_db_passwd']);
......@@ -119,24 +119,28 @@ function provision_mysql_provision_pre_install_rollback($url, &$data) {
function provision_mysql_provision_pre_restore($url, &$data) {
// store a backup of the credentials of the site.
$keys = array('site_db_name', 'site_db_passwd', 'site_db_user', 'site_db_host');
foreach ($keys as $key) {
$data['old_' . $key] = $data[$key];
}
$data['old_site_db_name'] = $data['site_db_name'];
$data['old_site_db_passwd'] = $data['site_db_passwd'];
$data['old_site_db_user'] = $data['site_db_user'];
$data['old_site_db_host'] = $data['site_db_host'];
# generate a random password for use
$data['site_db_passwd'] = user_password();
$data['site_db_name'] = _provision_mysql_suggest_db_name($url, $data);
$data['site_db_user'] = $data['site_db_name'];
$data['site_db_user'] = $data['site_db_name'];
$success = _provision_mysql_new_site_db($data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
if ($success) {
_provision_mysql_import_dump($data['restore_file'], $data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
_provision_mysql_import_dump(PROVISION_SITES_PATH . '/' . $url . '.restore/database.sql', $data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
}
else {
provision_set_error(PROVISION_DB_ERROR);
provision_log("error", "could not create new database to be imported into");
}
}
function provision_mysql_provision_pre_restore_rollback($url, &$data) {
_provision_mysql_destroy_site_db($data['site_db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']);
_provision_mysql_destroy_site_db($data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
//Restore the original database credentials of the site.
foreach ($keys as $key) {
......@@ -150,7 +154,7 @@ function provision_mysql_provision_pre_restore_rollback($url, &$data) {
* This will drop the database, revoke the privileges and flush the privileges.
*/
function provision_mysql_provision_delete($url, &$data) {
return _provision_mysql_destroy_site_db($data['site_db_name'], $data['db_user'], $data['db_passwd'], $data['db_host']);
return _provision_mysql_destroy_site_db($data['site_db_name'], $data['site_db_user'], $data['site_db_passwd'], $data['site_db_host']);
}
// Rollback doesn't apply here yet. Unless we trigger a restore of the first dump
......
......@@ -239,6 +239,27 @@ function _provision_drupal_switch_active_site($url = null) {
}
}
function provision_drupal_provision_post_restore($url, $data) {
_provision_drupal_create_settings_file($url, $data);
}
function provision_drupal_provision_restore($url, $data) {
$old = PROVISION_SITES_PATH . "/$url.restore";
$new = PROVISION_SITES_PATH . "/$url";
provision_path("switch_paths", $old, $new ,
t('Swapping out the @path and @confirm directories was successful.'),
t('Swapping the @path and @confirm directories has failed.'),
PROVISION_PERM_ERROR);
// make sure it has the latest site data available
provision_save_site_data($url, $data);
}
// Luckily this is reversable =)
function provision_drupal_provision_restore_rollback($url, $data) {
provision_drupal_provision_restore($url, $data);
}
/**
* Force drupal to load the modules it expects to find on an uninstalled site
*/
......
......@@ -320,7 +320,7 @@ function provision_save_site_data($url, $data) {
$aid = $data['task_id'];
fwrite($fp, "\n\n#" . format_date($timestamp, "large"));
if ($aid) {
$task = array('task' => $data['site_task_type'], 'status' => provision_get_error());
$task = array('task' => $data['task_type'], 'status' => provision_get_error());
$line = "\n\$tasks[$aid][$timestamp] = " . str_replace(array(" ", "\n"), "", var_export($task, TRUE)) . ";";
fwrite($fp, $line);
}
......
......@@ -307,20 +307,6 @@ function provision_apache_provision_pre_restore_rollback($url, $data) {
_provision_recursive_delete(PROVISION_SITES_PATH . "/$url.restore");
}
function provision_apache_provision_restore($url, $data) {
$old = PROVISION_SITES_PATH . "/$url.restore";
$new = PROVISION_SITES_PATH . "/$url";
provision_path("switch_paths", $old, $new ,
t('Swapping out the @path and @confirm directories was successful.'),
t('Swapping the @path and @confirm directories has failed.'),
PROVISION_PERM_ERROR);
}
// Luckily this is reversable =)
function provision_apache_provision_restore_rollback($url, $data) {
provision_apache_provision_restore($url, $data);
}
function provision_apache_provision_post_restore($url, &$data) {
_provision_apache_create_vhost_config($url, $data);
_provision_apache_restart_apache();
......
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