Commit 5e6c4cec authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

#374797 - move to drush_log and drush_set_error

parent a01fc209
<?php
function provision_mysql_provision_pre_backup(&$data, $url = NULL) {
provision_log("backup", "Generating mysql dump for $url.");
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);
}
function provision_mysql_provision_pre_backup_rollback(&$data, $url = NULL) {
provision_path("unlink", PROVISION_SITES_PATH . "/$url/database.sql", TRUE, dt("Deleted mysql dump from sites directory"), dt("Could not delete mysql dump from sites directory"));
provision_path("unlink", PROVISION_SITES_PATH . "/$url/database.sql", TRUE, dt("Deleted mysql dump from sites directory"),
dt("Could not delete mysql dump from sites directory"));
}
function provision_mysql_provision_post_backup(&$data, $url = NULL) {
......
......@@ -25,5 +25,5 @@ function provision_mysql_provision_deploy_rollback(&$data, $url = NULL) {
function provision_mysql_provision_post_deploy(&$data, $url = NULL) {
provision_path('unlink', 'sites/'. $url .'/database.sql', TRUE,
dt("Removed dump file @path after restoring from it"),
dt("Could not remove dump file @path"), PROVISION_PERM_ERROR);
dt("Could not remove dump file @path"), DRUSH_PERM_ERROR);
}
......@@ -21,8 +21,7 @@ function provision_db_connect() {
$connection = @mysql_connect(PROVISION_DB_HOST, PROVISION_DB_USER, PROVISION_DB_PASSWD);
if (!$connection) {
provision_set_error(PROVISION_DB_ERROR);
provision_log('error', dt('Could not connect to the master database.'));
drush_set_error('PROVISION_MASTER_DB_FAILED', dt('Could not connect to the master database.'), 'error');
}
else {
$success = @mysql_select_db('mysql', $connection);
......@@ -30,8 +29,7 @@ function provision_db_connect() {
_provision_db_connection($connection);
}
else {
provision_set_error(PROVISION_DB_ERROR);
provision_log('error', dt('Could not select the mysql database.'));
drush_set_error('PROVISION_MASTER_DB_FAILED', dt('Could not select the mysql database.'), 'error');
return FALSE;
}
}
......@@ -60,8 +58,7 @@ function _provision_db_query($query, $debug = 0) {
return $result;
}
else {
provision_log("error",
mysql_error(_provision_db_connection()) ."\nquery: ". $query);
drush_log( mysql_error(_provision_db_connection()) ."\nquery: ". $query, 'error');
return FALSE;
}
}
......
......@@ -9,35 +9,49 @@
*/
include_once('provision.mysql.inc');
define('PROVISION_CREATE_DB_FAILED', 'PROVISION_CREATE_DB_FAILED');
define('PROVISION_DROP_DB_FAILED', 'PROVISION_DROP_DB_FAILED');
define('PROVISION_DB_DUMP_NOT_FOUND', 'PROVISION_DB_DUMP_NOT_FOUND');
define('PROVISION_DB_DUMP_NOT_READABLE', 'PROVISION_DB_DUMP_NOT_READABLE');
define('PROVISION_DB_IMPORT_FAILED', 'PROVISION_DB_IMPORT_FAILED');
function provision_mysql_provision_finalize() {
provision_db_close();
}
function provision_mysql_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.');
}
}
/**
* Generate a new mysql database and user account for the specified credentials
*/
function _provision_mysql_new_site_db($db_name, $db_user, $db_passwd, $db_host) {
if (!_provision_mysql_create_database($db_name) ||
!_provision_mysql_database_exists($db_name) ) {
provision_set_error(PROVISION_DB_ERROR);
provision_log("error", "Database could not be created.");
drush_set_error(PROVISION_CREATE_DB_FAILED);
drush_log("Database could not be created.", 'error');
return FALSE;
}
if (!_provision_mysql_grant($db_name, $db_user, $db_passwd)
|| !_provision_mysql_grant($db_name, $db_user, $db_passwd, 'localhost')) {
provision_log("warning", "Could not GRANT user access.");
drush_log("Could not GRANT user access.", 'warning');
}
_provision_mysql_flush_privileges();
$status = _provision_mysql_database_exists($db_name);
if ($status) {
provision_log('success', dt('Created @name database', array("@name" => $db_name)));
drush_log(dt('Created @name database', array("@name" => $db_name)), 'success');
}
else {
provision_set_error(PROVISION_DB_ERROR);
provision_log("error", dt("Could not create @name database", array("@name" => $db_name)));
drush_set_error(PROVISION_CREATE_DB_FAILED, dt("Could not create @name database", array("@name" => $db_name)));
}
return $status;
//TODO : Test to confirm that the database is actually writeable. Taking this on faith for now.
......@@ -49,22 +63,21 @@ 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) {
if ( _provision_mysql_database_exists($data['db_name']) ) {
provision_log("notice", 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)) {
provision_log("warning", dt("Failed to drop database @dbname", array('@dbname' => $db_name)));
drush_log(dt("Failed to drop database @dbname", array('@dbname' => $db_name)), 'warning');
}
}
if ( _provision_mysql_database_exists($db_name) ) {
provision_set_error(PROVISION_DB_ERROR);
provision_log("error", "Database could not be destroyed.");
drush_set_error(PROVISION_DROP_DB_FAILED);
return FALSE;
}
provision_log("notice", "Revoking privileges");
drush_log("Revoking privileges");
_provision_mysql_flush_privileges();
if (!_provision_mysql_revoke($db_name, $db_user)) {
provision_log("warning", dt("Failed to revoke user privileges"));
drush_log(dt("Failed to revoke user privileges"), 'warning');
}
}
......@@ -90,7 +103,7 @@ function _provision_mysql_can_create_database() {
_provision_mysql_create_database($test);
if (_provision_mysql_database_exists($test)) {
if (!_provision_mysql_drop_database($test)) {
provision_log("warning", dt("Failed to drop database @dbname", array('@dbname' => $test)));
drush_log(dt("Failed to drop database @dbname", array('@dbname' => $test)), 'warning');
}
return TRUE;
}
......@@ -111,16 +124,16 @@ function _provision_mysql_import_dump($dump_file, $db_name, $db_user, $db_passwd
$exists = provision_path("exists", $dump_file, TRUE,
dt('Found database dump at @path.'),
dt('No database dump was found at @path.'),
PROVISION_FRAMEWORK_ERROR);
PROVISION_DB_DUMP_NOT_FOUND);
if ($exists) {
$readable = provision_path("readable", $dump_file, TRUE, dt('Database dump at @path is readable'),
dt('The database dump at @path could not be read.'),
PROVISION_PERM_ERROR);
PROVISION_DB_DUMP_NOT_READABLE);
if ($readable) {
provision_log("notice", sprintf("Importing database using command: mysql -u%s -p%s -h%s %s < %s",
drush_log(sprintf("Importing database using command: mysql -u%s -p%s -h%s %s < %s",
$db_user, $db_passwd, $db_host, $db_name, $dump_file));
if (!provision_shell_exec("mysql -u%s -p%s -h%s %s < %s", $db_user, $db_passwd, $db_host, $db_name, $dump_file )) {
provision_log("error", dt("Database import failed"));
drush_set_error(PROVISION_DB_IMPORT_FAILED, dt("Database import failed"));
}
}
}
......
......@@ -39,7 +39,7 @@ function provision_mysql_provision_pre_restore_rollback(&$data, $url = NULL) {
function provision_mysql_provision_post_restore(&$data, $url = NULL) {
provision_path('unlink', 'sites/'. $url .'/database.sql', TRUE,
dt("Removed dump file @path after restoring from it"),
dt("Could not remove dump file @path"), PROVISION_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']);
}
......@@ -12,11 +12,10 @@ function provision_mysql_provision_verify_validate() {
function provision_mysql_provision_verify() {
if (PROVISION_CONTEXT_PLATFORM) {
if (!_provision_mysql_can_create_database()) {
provision_set_error(PROVISION_DB_ERROR | PROVISION_FRAMEWORK_ERROR);
provision_log('error', dt('Unable to create new databases.'));
drush_set_error('PROVISION_CREATE_DB_FAILED', dt('Unable to create new databases.'));
}
else {
provision_log("message", dt('Mysql can create new databases.'));
drush_log(dt('Mysql can create new databases.'), 'message');
}
}
}
......
......@@ -15,8 +15,7 @@ function provision_drupal_provision_backup_validate(&$data, $url = NULL, $backup
// This is the actual drupal provisioning requirements.
if (!is_dir(PROVISION_BACKUP_PATH)) {
provision_log("Backup directory does not exist.");
provision_set_error(PROVISION_PERM_ERROR);
drush_set_error(PROVISION_BACKUP_PATH_NOT_FOUND);
}
if ($backup_file) {
......@@ -45,12 +44,11 @@ function provision_drupal_provision_backup_validate(&$data, $url = NULL, $backup
*/
function provision_drupal_provision_backup(&$data, $url, $backup_file) {
// Adds the site directory into the backup file
provision_log("backup", "Adding sites directory to $data[backup_file].gz");
drush_log("Adding sites directory to $data[backup_file].gz", 'backup');
$result = provision_shell_exec("cd %s; tar -rf %s * ", "sites/$url", $data['backup_file']);
if (!$result) {
provision_log("error", "Could not back up sites directory for drupal");
provision_set_error(PROVISION_FRAMEWORK_ERROR);
drush_set_error(PROVISION_BACKUP_FAILED, dt("Could not back up sites directory for drupal"));
}
}
......
......@@ -94,12 +94,12 @@ function install_send_welcome_mail($url, $profile, $language, $client_email) {
$mail_success = drupal_mail($mailkey, $account->mail, $subject, $body, $from);
if ($mail_success) {
provision_log('message', t('Sent welcome mail to @client', array('@client' => $client_email)));
drush_log(t('Sent welcome mail to @client', array('@client' => $client_email)), 'message');
}
else {
provision_log('notice', t('Could not send welcome mail to @client', array('@client' => $client_email)));
drush_log(t('Could not send welcome mail to @client', array('@client' => $client_email)));
}
provision_log('message', t('Login url: !onetime', array('!onetime' => $onetime)));
drush_log(t('Login url: !onetime', array('!onetime' => $onetime)), 'message');
}
......@@ -120,14 +120,12 @@ function install_main() {
db_set_active();
// Check if Drupal is installed.
if (install_verify_drupal()) {
provision_set_error(PROVISION_SITE_INSTALLED);
provision_log('error', st('Site is already installed'));
drush_set_error(PROVISION_DRUPAL_SITE_INSTALLED, st('Site is already installed'));
return FALSE;
}
}
else {
provision_set_error(PROVISION_FRAMEWORK_ERROR);
provision_log('error', st('Config file could not be loaded'));
drush_set_error(PROVISION_CONFIG_NOT_VALID, st('Config file could not be loaded'));
return FALSE;
}
// Load module basics (needed for hook invokes).
......@@ -139,10 +137,10 @@ function install_main() {
drupal_load('module', 'filter');
provision_log("install", st("Installing Drupal schema"));
drush_log(st("Installing Drupal schema"), 'install');
// Load the profile.
require_once "./profiles/$profile/$profile.profile";
provision_log("install", st("Loading @profile install profile", array("@profile" => $profile)));
drush_log(st("Loading @profile install profile", array("@profile" => $profile)), 'install');
$requirements = drupal_check_profile($profile);
$severity = drupal_requirements_severity($requirements);
......@@ -161,11 +159,11 @@ function install_main() {
$modules = drupal_verify_profile($profile, $install_locale);
if (!$modules) {
provision_set_error(PROVISION_FRAMEWORK_ERROR);
drush_set_error(PROVISION_DRUPAL_INSTALL_FAILED);
return FALSE;
}
foreach ($modules as $module) {
provision_log("success", st("Installing module : @module", array("@module" => $module)));
drush_log(st("Installing module : @module", array("@module" => $module)), 'success');
}
// Perform actual installation defined in the profile.
drupal_install_profile($profile, $modules);
......
......@@ -46,7 +46,7 @@ function update_main() {
$updates = drupal_get_schema_versions($module);
$max_version = max($updates);
if ($version <= $max_version) {
provision_log('notice', pt('Updating module @module from schema version @start to schema version @max', array('@module' => $module, '@start' => $version - 1, '@max' => $max_version)));
drush_log(pt('Updating module @module from schema version @start to schema version @max', array('@module' => $module, '@start' => $version - 1, '@max' => $max_version)));
foreach ($updates as $update) {
$finished = FALSE;
if ($update >= $version) {
......@@ -65,7 +65,7 @@ function update_main() {
}
}
else {
provision_log("notice", pt('No updates for @module module', array('@module' => $module)));
drush_log(pt('No updates for @module module', array('@module' => $module)));
}
}
}
......
......@@ -69,12 +69,12 @@ function install_send_welcome_mail($url, $profile, $language, $client_email) {
$mail_success = drupal_mail('install', 'welcome-admin', $account->mail, user_preferred_language($account), $mail_params, $from, TRUE);
if ($mail_success) {
provision_log('message', t('Sent welcome mail to @client', array('@client' => $client_email)));
drush_log(t('Sent welcome mail to @client', array('@client' => $client_email)), 'message');
}
else {
provision_log('notice', t('Could not send welcome mail to @client', array('@client' => $client_email)));
drush_log(t('Could not send welcome mail to @client', array('@client' => $client_email)));
}
provision_log('message', t('Login url: !onetime', array('!onetime' => $onetime)));
drush_log(t('Login url: !onetime', array('!onetime' => $onetime)), 'message');
}
}
......@@ -153,24 +153,20 @@ function install_main() {
db_set_active();
if (install_verify_drupal()) {
provision_set_error(PROVISION_SITE_INSTALLED);
provision_log('error', st('Site is already installed'));
return FALSE;
return drush_set_error(PROVISION_DRUPAL_SITE_INSTALLED);
}
}
else {
provision_set_error(PROVISION_FRAMEWORK_ERROR);
provision_log('error', st('Config file could not be loaded'));
return FALSE;
return drush_set_error(PROVISION_CONFIG_NOT_VALID);
}
provision_log("install", st("Installing Drupal schema"));
drush_log(st("Installing Drupal schema"), 'install');
// Load the profile.
require_once "./profiles/$profile/$profile.profile";
provision_log("install", st("Loading @profile install profile", array("@profile" => $profile)));
drush_log(st("Loading @profile install profile", array("@profile" => $profile)), 'install');
provision_log("install", st("Installing translation : @locale", array("@locale" => $install_locale)));
drush_log(st("Installing translation : @locale", array("@locale" => $install_locale)), 'install');
/**
* Handles requirement checking
......@@ -203,17 +199,14 @@ function install_main() {
}
if ($missing_requirement) {
provision_set_error(PROVISION_INSTALL_ERROR);
provision_log('error', t("Could not meet the requirements for installing the drupal profile"));
return FALSE;
return drush_set_error(PROVISION_INSTALL_MISSING_REQUIREMENTS);
}
// Verify existence of all required modules.
$modules = drupal_verify_profile($profile, $language);
if (!$modules) {
provision_set_error(PROVISION_FRAMEWORK_ERROR);
return FALSE;
return drush_set_error(PROVISION_DRUPAL_INSTALL_FAILED);
}
drupal_install_system();
......@@ -235,7 +228,7 @@ function install_main() {
foreach ($modules as $module) {
_drupal_install_module($module);
module_enable(array($module));
provision_log("notice", t("Installed @module module.",
drush_log(t("Installed @module module.",
array("@module" => $files[$module]->info['name'])));
}
......
......@@ -31,8 +31,7 @@ function update_main() {
// are removed, it will == 0.
$last_removed = module_invoke($module, 'update_last_removed');
if ($schema_version < $last_removed) {
provision_set_error(PROVISION_INSTALL_ERROR);
provision_log('error', pt( $module .' module can not be updated. Its schema version is '. $schema_version .'. Updates up to and including '. $last_removed .' have been removed in this release. In order to update '. $module .' module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.'));
drush_set_error(PROVISION_DRUPAL_UPDATE_FAILED, dt( $module .' module can not be updated. Its schema version is '. $schema_version .'. Updates up to and including '. $last_removed .' have been removed in this release. In order to update '. $module .' module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.'));
continue;
}
......@@ -55,7 +54,7 @@ function update_main() {
$updates = drupal_get_schema_versions($module);
$max_version = max($updates);
if ($version <= $max_version) {
provision_log('notice', pt('Updating module @module from schema version @start to schema version @max', array('@module' => $module, '@start' => $version - 1, '@max' => $max_version)));
drush_log(pt('Updating module @module from schema version @start to schema version @max', array('@module' => $module, '@start' => $version - 1, '@max' => $max_version)));
foreach ($updates as $update) {
if ($update >= $version) {
$operations[] = array('_update_do_one', array($module, $update));
......@@ -63,7 +62,7 @@ function update_main() {
}
}
else {
provision_log('notice', pt('No updates for module @module', array('@module' => $module)));
drush_log(pt('No updates for module @module', array('@module' => $module)));
}
}
$batch = array(
......@@ -79,7 +78,7 @@ function update_main() {
batch_process();
}
else {
provision_log('notice', pt('No outstanding updates'));
drush_log(pt('No outstanding updates'));
}
}
......
......@@ -75,12 +75,12 @@ function install_send_welcome_mail($url, $profile, $language, $client_email) {
$mail_success = drupal_mail('install', 'welcome-admin', $account->mail, user_preferred_language($account), $mail_params, $from, TRUE);
if ($mail_success) {
provision_log('message', t('Sent welcome mail to @client', array('@client' => $client_email)));
drush_log(t('Sent welcome mail to @client', array('@client' => $client_email)), 'message');
}
else {
provision_log('notice', t('Could not send welcome mail to @client', array('@client' => $client_email)));
drush_log(t('Could not send welcome mail to @client', array('@client' => $client_email)));
}
provision_log('message', t('Login url: !onetime', array('!onetime' => $onetime)));
drush_log(t('Login url: !onetime', array('!onetime' => $onetime)), 'message');
}
}
......@@ -162,9 +162,7 @@ function install_main() {
// Check if Drupal is installed.
if (install_verify_drupal()) {
provision_set_error(PROVISION_SITE_INSTALLED);
provision_log('error', st('Site is already installed'));
return FALSE;
return drush_set_error(PROVISION_DRUPAL_SITE_INSTALLED);
}
}
else {
......@@ -178,12 +176,12 @@ function install_main() {
}
provision_log("install", st("Installing Drupal schema"));
drush_log(st("Installing Drupal schema"), 'install');
// Load the profile.
require_once "./profiles/$profile/$profile.profile";
provision_log("install", st("Loading @profile install profile", array("@profile" => $profile)));
drush_log(st("Loading @profile install profile", array("@profile" => $profile)), 'install');
provision_log("install", st("Installing translation : @locale", array("@locale" => $install_locale)));
drush_log(st("Installing translation : @locale", array("@locale" => $install_locale)), 'install');
/**
* Handles requirement checking
......@@ -217,9 +215,7 @@ function install_main() {
}
if ($missing_requirement) {
provision_set_error(PROVISION_INSTALL_ERROR);
provision_log('error', t("Could not meet the requirements for installing the drupal profile"));
return FALSE;
return drush_set_error(PROVISION_DRUPAL_INSTALL_MISSING_REQUIREMENTS);
}
// Verify existence of all required modules.
......@@ -228,9 +224,7 @@ function install_main() {
$severity = drupal_requirements_severity($requirements);
if ($severity == REQUIREMENT_ERROR) {
provision_log('error', t('Missing requirements'));
provision_set_error(PROVISION_FRAMEWORK_ERROR);
return FALSE;
return drush_set_error(PROVISION_DRUPAL_INSTALL_MISSING_REQUIREMENTS);
}
drupal_install_system();
......@@ -253,7 +247,7 @@ function install_main() {
foreach ($modules as $module) {
_drupal_install_module($module);
module_enable(array($module));
provision_log("notice", t("Installed @module module.",
drush_log(t("Installed @module module.",
array("@module" => $files[$module]->info['name'])));
}
module_load_all();
......
......@@ -31,8 +31,7 @@ function update_main() {
// are removed, it will == 0.
$last_removed = module_invoke($module, 'update_last_removed');
if ($schema_version < $last_removed) {
provision_set_error(PROVISION_INSTALL_ERROR);
provision_log('error', pt( $module .' module can not be updated. Its schema version is '. $schema_version .'. Updates up to and including '. $last_removed .' have been removed in this release. In order to update '. $module .' module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.'));
drush_set_error(PROVISION_DRUPAL_UPDATE_FAILED, dt( $module .' module can not be updated. Its schema version is '. $schema_version .'. Updates up to and including '. $last_removed .' have been removed in this release. In order to update '. $module .' module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.'));
continue;
}
......@@ -55,7 +54,7 @@ function update_main() {
$updates = drupal_get_schema_versions($module);
$max_version = max($updates);
if ($version <= $max_version) {
provision_log('notice', pt('Updating module @module from schema version @start to schema version @max', array('@module' => $module, '@start' => $version - 1, '@max' => $max_version)));
drush_log(dt('Updating module @module from schema version @start to schema version @max', array('@module' => $module, '@start' => $version - 1, '@max' => $max_version)));
foreach ($updates as $update) {
if ($update >= $version) {
$operations[] = array('_update_do_one', array($module, $update));
......@@ -63,7 +62,7 @@ function update_main() {
}
}
else {
provision_log('notice', pt('No updates for module @module', array('@module' => $module)));
drush_log(dt('No updates for module @module', array('@module' => $module)));
}
}
$batch = array(
......@@ -79,7 +78,7 @@ function update_main() {
batch_process();
}
else {
provision_log('notice', pt('No outstanding updates'));
drush_log(dt('No outstanding updates'));
}
}
......@@ -100,12 +99,7 @@ function _update_do_one($module, $number, &$context) {
if (function_exists($function)) {
$ret = $function($context['sandbox']);
}
foreach ($ret as $info) {
if (!$info['success']) {
provision_set_error('PROVISION_DB_ERROR');
}
provision_log( ($info['success']) ? 'success' : 'error', $info['query']);
}
provision_drupal_install_log($ret);
if (isset($ret['#finished'])) {
$context['finished'] = $ret['#finished'];
......
......@@ -5,19 +5,19 @@
* Rebuild all the caches
*/
cache_clear_all();
provision_log('notice', t('Cleared all caches'));
drush_log(t('Cleared all caches'));
node_types_rebuild();
provision_log('notice', t('Rebuild node type cache'));
drush_log(t('Rebuild node type cache'));
module_rebuild_cache();
provision_log('notice', t('Rebuild module cache'));
drush_log(t('Rebuild module cache'));
system_theme_data();
provision_log('notice', t('Rebuild theme cache'));
drush_log(t('Rebuild theme cache'));
node_access_rebuild();
provision_log('notice', t('Rebuild node access cache'));
drush_log(t('Rebuild node access cache'));
menu_rebuild();
provision_log('notice', t('Rebuild menu cache'));
drush_log(t('Rebuild menu cache'));
......@@ -12,7 +12,7 @@ $old_url = $data['old_site_url'];
* directories.
*/
provision_log('notice',
drush_log(
pt('Changed paths from sites/@old_url to sites/@new_url',
array('@old_url' => $old_url, '@new_url' => $new_url)));
......
......@@ -8,6 +8,38 @@
* and all the install api code.
*/
define('PROVISION_BACKUP_PATH_NOT_FOUND', 'PROVISION_BACKUP_PATH_NOT_FOUND');
define('PROVISION_BACKUP_FAILED', 'PROVISION_BACKUP_FAILED');
define('PROVISION_DRUPAL_INSTALL_FAILED', 'PROVISION_DRUPAL_INSTALL_FAILED');
define('PROVISION_DRUPAL_UPDATE_FAILED', 'PROVISION_DRUPAL_UPDATE_FAILED');
define('PROVISION_DRUPAL_INSTALL_MISSING_REQUIREMENTS', 'PROVISION_DRUPAL_INSTALL_MISSING_REQUIREMENTS');
define('PROVISION_DRUPAL_SITE_INSTALLED', 'PROVISION_DRUPAL_SITE_INSTALLED');
define('PROVISION_DRUPAL_SITE_NOT_FOUND', 'PROVISION_DRUPAL_SITE_NOT_FOUND');
define('PROVISION_CONFIG_NOT_VALID', 'PROVISION_CONFIG_NOT_VALID');
define('PROVISION_REQUIRES_URL', 'PROVISION_REQUIRES_URL');
function provision_drupal_drush_help($section) {
switch ($section) {
case 'error:PROVISION_CONFIG_NOT_VALID' :
return dt('Config file could not be loaded.');
case 'error:PROVISION_DRUPAL_SITE_INSTALLED' :
return dt('Site has already been installed.');
case 'error:PROVISION_DRUPAL_SITE_NOT_FOUND' :
return dt('Site was not found.');
case 'error:PROVISION_DRUPAL_INSTALL_FAILED' :
return dt('Could not complete Drupal installation.');
case 'error:PROVISION_DRUPAL_UPDATE_FAILED' :
return dt('Could not complete Drupal update.');
case 'error:PROVISION_BACKUP_PATH_NOT_FOUND' :
return dt("Backup directory does not exist.");
case 'error:PROVISION_DRUPAL_INSTALL_MISSING_REQUIREMENTS' :
return dt("Could not meet the requirements for installing the drupal profile");
case 'error:PROVISION_REQUIRES_URL' :
return dt('You need to specify the URL argument for this command');
}
}
/**
* Initialize the platform / site
*
......@@ -47,8 +79,7 @@ function provision_drupal_provision_finalize(&$data, $url = NULL) {
*/
function _provision_drupal_url_required() {
if (PROVISION_CONTEXT_PLATFORM) {
provision_set_error(PROVISION_FRAMEWORK_ERROR);
provision_log('error', dt('You need to specify the URL argument for this command'));
drush_set_error(PROVISION_REQUIRES_URL);
}
}
......@@ -60,8 +91,7 @@ function _provision_drupal_url_required() {
function _provision_drupal_valid_site() {
if (PROVISION_CONTEXT_SITE) {
if (!_provision_drupal_site_exists(PROVISION_ACTIVE_URL)) {
provision_set_error(PROVISION_SITE_NOT_FOUND);
provision_log("error", "Site could not be found.");
drush_set_error(PROVISION_DRUPAL_SITE_NOT_FOUND);
}
}
}
......@@ -87,8 +117,7 @@ function _provision_drupal_site_exists($url) {
function _provision_drupal_valid_installed_site() {
if (PROVISION_CONTEXT_SITE) {
if (!_provision_drupal_site_installed(PROVISION_ACTIVE_URL)) {
provision_set_error(PROVISION_SITE_NOT_FOUND);
provision_log("error", "Site has not been installed yet.");
drush_set_error(PROVISION_DRUPAL_SITE_NOT_FOUND);
}
}
}
......@@ -96,8 +125,7 @@ function _provision_drupal_valid_installed_site() {
function _provision_drupal_valid_not_installed_site() {
if (PROVISION_CONTEXT_SITE) {
if (_provision_drupal_site_installed(PROVISION_ACTIVE_URL)) {
provision_set_error(PROVISION_SITE_INSTALLED);
provision_log('error', dt('This site has already been installed.'));
drush_set_error(PROVISION_DRUPAL_SITE_INSTALLED);
}
}
}
......@@ -134,7 +162,7 @@ function _provision_drupal_default_template() {
* because the modules might provide additional information about the site.
*/
function _provision_drupal_create_settings_file(&$data, $url = NULL) {
provision_log('notice', dt("Generate settings.php file"));
drush_log(dt("Generate settings.php file"));
if (provision_path("exists", "sites/$url/settings.php")) {
provision_path("chmod", "sites/$url/settings.php", 0640,
dt('Changed permissions of settings.php to @confirm'),
......@@ -227,7 +255,7 @@ function _provision_find_profiles() {
include_once('includes/install.inc');
if (!$dir = opendir("./profiles")) {
provision_log('error', dt("Cannot find profiles directory"));
drush_log(dt("Cannot find profiles directory"), 'error');
return FALSE;
}
while (FALSE !== ($name = readdir($dir))) {
......@@ -258,7 +286,7 @@ function _provision_find_profiles() {
}
$profile->info['languages'] = array_keys($languages);
$return[$name] = $profile;
provision_log('notice', dt('found install profile %name', array('%name' => $name)));
drush_log(dt('found install profile %name', array('%name' => $name)));
}
return $return;
......@@ -275,7 +303,7 @@ function provision_drupal_find_sites() {
}
closedir($dir);
} else {
provision_log("error", dt("Cannot find sites directory"));
drush_log(dt("Cannot find sites directory"), 'error');
$sites = FALSE;
}
return $sites;
......@@ -364,9 +392,9 @@ function _provision_drupal_delete_aliases($aliases) {
function provision_drupal_install_log($ret) {
foreach ($ret as $info) {
if (!$info['success']) {
provision_set_error('PROVISION_DB_ERROR');
drush_set_error(PROVISION_DRUPAL_INSTALL_FAILED);
}
provision_log( ($info['success']) ? 'success' : 'error', $info['query']);
drush_log($info['query'], ($info['success']) ? 'success' : 'error');
}
}
......@@ -23,7 +23,7 @@ function provision_drupal_provision_verify(&$data, $url = null) {
$data['sites'] = array_keys((array) provision_drupal_find_sites()); // return list of hosted sites. used to determine whether or not to import.
$data['platform'] = array('short_name' => 'drupal', 'version' => drush_drupal_version());
provision_log('notice', dt("This platform is running @short_name @version",
drush_log(dt("This platform is running @short_name @version",
array('@short_name' => 'drupal', '@version' => VERSION)));
$data['profiles'] = _provision_find_profiles();
}
......
......@@ -52,9 +52,7 @@ function provision_init() {
// Do not allow the program to be run as the root user. ever
$name = posix_getpwuid(posix_geteuid());
if ($name['name'] == 'root') {
provision_log('error', 'You are running the provision script as the root user. Exiting');
provision_set_error(PROVISION_FRAMEWORK_ERROR);
provision_output($url);
return drush_set_error(PROVISION_ROOT_USER_ERROR, dt('You are running the provision script as the root user. Exiting'));