Commit 10d9332c authored by Adrian Rossouw's avatar Adrian Rossouw

Sort of fix site import, which also verifies now. Introduce d()->site_path...

Sort of fix site import, which also verifies now. Introduce d()->site_path instead of concatenating everywhere.
parent 1e29348c
......@@ -5,7 +5,7 @@ function drush_db_pre_provision_backup() {
}
function drush_db_pre_provision_backup_rollback() {
d()->service('file')->unlink(d()->root . '/sites/' . d()->uri . '/database.sql')
d()->service('file')->unlink(d()->site_path . '/database.sql')
->succeed('Deleted mysql dump from sites directory')
->fail('Could not delete mysql dump from sites directory');
}
......
......@@ -166,7 +166,7 @@ class provisionService_db extends provisionService {
function import_site_database($dump_file = null) {
if (is_null($dump_file)) {
$dump_file = d()->root . '/sites/' . d()->uri . '/database.sql';
$dump_file = d()->site_path . '/database.sql';
}
$creds = $this->fetch_site_credentials();
......
......@@ -16,7 +16,7 @@ function drush_db_provision_deploy_rollback() {
// 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.
function drush_db_post_provision_deploy() {
d()->service('file')->unlink(d()->root . '/sites/' . d()->uri . '/database.sql')
d()->service('file')->unlink(d()->site_path . '/database.sql')
->succeed('Removed dump file @path after restoring from it')
->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR');
}
......@@ -97,7 +97,7 @@ class provisionService_db_mysql extends provisionService_db_pdo {
// non-readable by the webserver.
umask(0077);
// Mixed copy-paste of drush_shell_exec and provision_shell_exec.
$cmd = sprintf('mysqldump --defaults-file=/dev/fd/3 -r%s/sites/%s/database.sql %s', escapeshellcmd(d()->root), escapeshellcmd(d()->uri), escapeshellcmd(drush_get_option('db_name')));
$cmd = sprintf('mysqldump --defaults-file=/dev/fd/3 -r%s/database.sql %s', escapeshellcmd(d()->site_path), escapeshellcmd(drush_get_option('db_name')));
$success = $this->safe_shell_exec($cmd, drush_get_option('db_host'), urldecode(drush_get_option('db_user')), urldecode(drush_get_option('db_passwd')));
if (!$success && !drush_get_option('force', false)) {
......
......@@ -11,7 +11,7 @@ function drush_db_pre_provision_restore() {
}
function drush_db_provision_restore() {
d()->service('db')->import_site_database(d()->root . '/sites/' . d()->uri . '.restore/database.sql');
d()->service('db')->import_site_database(d()->site_path . '.restore/database.sql');
}
......@@ -32,7 +32,7 @@ function drush_db_pre_provision_restore_rollback() {
// 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.
function drush_db_post_provision_restore() {
d()->service('file')->unlink(d()->root . '/sites/' . d()->uri . '/database.sql')
d()->service('file')->unlink(d()->site_path . '/database.sql')
->succeed('Removed dump file @path after restoring from it')
->fail('Could not remove dump file @path', 'DRUSH_PERM_ERROR');
......
......@@ -29,7 +29,7 @@
<?php print $extra_config; ?>
# Error handler for Drupal > 4.6.7
<Directory "<?php print $this->platform->root; ?>/sites/<?php print $uri; ?>/files">
<Directory "<?php print $this->site_path; ?>/files">
SetHandler This_is_a_Drupal_security_line_do_not_remove
</Directory>
......
......@@ -57,7 +57,7 @@ function drush_provision_drupal_provision_backup() {
drush_log(dt("Adding sites directory to !backup_file", array('!backup_file' => $backup_file)), 'backup');
$olddir = getcwd();
// we need to do this because some retarded implementations of tar (e.g. SunOS) don't support -C
chdir(d()->root . '/sites/' . d()->uri);
chdir(d()->site_path);
if (substr($backup_file, -2) == 'gz') {
// same as above: some do not support -z
$command = "tar cpf - . | gzip -c > %s";
......
......@@ -18,8 +18,8 @@ function drush_provision_drupal_pre_provision_delete($backup_file = NULL) {
*/
function drush_provision_drupal_provision_delete() {
if (d()->type === 'site') {
_provision_recursive_delete(d()->root . '/sites/' . d()->uri);
d()->service('file')->sync(d()->root . '/sites/' . d()->uri);
_provision_recursive_delete(d()->site_path);
d()->service('file')->sync(d()->site_path);
// we remove the aliases even if redirection is enabled as a precaution
// if redirection is enabled, keep silent about errors
_provision_drupal_delete_aliases(drush_get_option('aliases', array(), 'site'), drush_get_option('redirection'));
......
......@@ -33,7 +33,7 @@ function drush_provision_drupal_provision_deploy_validate($backup_file = null) {
*/
function drush_provision_drupal_pre_provision_deploy($backup_file) {
// the url is likely to have changed in the deployment
$extracted = d()->service('file')->extract($backup_file, d()->root . '/sites/' . d()->uri)
$extracted = d()->service('file')->extract($backup_file, d()->site_path)
->succeed('Successfully extracted the contents of @path')
->fail('Failed to extract the contents of @path to @target', 'PROVISION_BACKUP_EXTRACTION_FAILED')
->status();
......
......@@ -6,20 +6,25 @@
* Import existing drupal sites
*/
/**
* Check that the site directory at least exists.
*/
function drush_provision_drupal_provision_import_validate() {
_provision_drupal_url_required();
_provision_drupal_valid_site();
}
/**
* Import the information about the existing site, and return it in the $data context array
*/
function drush_provision_drupal_provision_import() {
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
drush_include_engine('drupal', 'import', drush_drupal_major_version());
drush_set_option('installed', TRUE, 'site');
if (d()->type === 'site') {
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
drush_include_engine('drupal', 'import', drush_drupal_major_version());
drush_set_option('installed', TRUE, 'site');
}
}
function drush_provision_drupal_post_provision_import() {
if (d()->type === 'site') {
d()->profile = drush_get_option('profile', 'default', 'site');
d()->language = drush_get_option('language', 'en', 'site');
d()->write_alias();
provision_backend_invoke(d()->name, 'provision-verify');
}
}
......@@ -53,8 +53,8 @@ function drush_provision_drupal_provision_install() {
*/
function drush_provision_drupal_provision_install_rollback() {
if (d()->uri) {
if (!_provision_drupal_site_installed()) {
_provision_recursive_delete('sites/' . drush_get_option('uri'));
if (!drush_get_option('installed', FALSE)) {
_provision_recursive_delete( d()->site_path );
}
} else {
drush_set_error('PROVISION_FRAMEWORK_ERROR', dt('no url defined in %function', array('%function' => __FUNCTION__)));
......
......@@ -76,7 +76,7 @@ function drush_provision_drupal_post_provision_migrate() {
// we remove the aliases even if redirection is enabled as a precaution
// if redirection is enabled, keep silent about errors
_provision_drupal_delete_aliases(drush_get_option('aliases', array()), drush_get_option('redirection'));
_provision_recursive_delete(d()->root . '/sites/' . d()->uri);
_provision_recursive_delete(d()->site_path);
}
......@@ -104,29 +104,6 @@ function provision_drupal_drush_exit() {
}
}
/**
* Some commands need to have a url to operate on.
* This prints out a message to that effect.
*/
function _provision_drupal_url_required() {
if (d()->type === 'platform') {
drush_set_error('PROVISION_REQUIRES_URL');
}
}
/**
* Validate a site exists, ie: has a settings.php file
*
* This will return an error for sites that haven't been created yet
*/
function _provision_drupal_valid_site() {
if (d()->type === 'site') {
if (!_provision_drupal_site_exists()) {
drush_set_error('PROVISION_DRUPAL_SITE_NOT_FOUND');
}
}
}
/**
* Test to see if the site settings.php exists
*
......@@ -136,45 +113,17 @@ function _provision_drupal_valid_site() {
* If the file exists, return TRUE, else return FALSE.
*/
function _provision_drupal_site_exists() {
return file_exists('sites/' . drush_get_option('uri') . '/settings.php');
return file_exists(d()->site_path . '/settings.php');
}
/**
* Validate a site has been installed, by checking it's site.php file.
*
* This will return an error for sites that haven't been installed yet
* Sync the Drupal site directory to the remote host.
*/
function _provision_drupal_valid_installed_site() {
if (d()->type === 'site') {
if (!_provision_drupal_site_installed()) {
drush_set_error('PROVISION_DRUPAL_SITE_NOT_FOUND');
}
}
}
function _provision_drupal_valid_not_installed_site() {
if (d()->type === 'site') {
if (_provision_drupal_site_installed()) {
drush_set_error('PROVISION_DRUPAL_SITE_INSTALLED');
}
}
}
/**
* Test to see if the site has a site.php and has it set to 'installed'
*/
function _provision_drupal_site_installed() {
if (_provision_drupal_site_exists()) {
return drush_get_option('installed');
}
return FALSE;
}
function provision_drupal_sync_site() {
d()->service('file')->sync(d()->root, TRUE);
if (d()->type === 'site') {
d()->service('file')->sync(d()->root . '/sites/' . d()->uri);
d()->service('file')->sync(d()->site_path);
}
}
......@@ -199,7 +148,7 @@ class provisionConfig_drupal_settings extends provisionConfig {
protected $mode = 0440;
function filename() {
return $this->root . '/sites/' . $this->uri . '/settings.php';
return $this->site_path . '/settings.php';
}
function process() {
......
......@@ -41,7 +41,7 @@ function drush_provision_drupal_provision_restore_validate($restore_file = null)
function drush_provision_drupal_pre_provision_restore($restore_file) {
drush_invoke('provision-backup');
d()->service('file')->extract(drush_get_option('restore_file'), d()->root . '/sites/' . d()->uri . '.restore')
d()->service('file')->extract(drush_get_option('restore_file'), d()->site_path . '.restore')
->succeed('Successfully extracted the contents of @path')
->fail('Failed to extract the contents of @path', 'PROVISION_BACKUP_EXTRACTION_FAILED');
}
......@@ -50,15 +50,15 @@ function drush_provision_drupal_pre_provision_restore($restore_file) {
* Remove the extracted site directory
*/
function drush_provision_drupal_pre_provision_restore_rollback() {
_provision_recursive_delete(d()->root . '/sites/' . d()->uri . '.restore');
_provision_recursive_delete(d()->site_path . '.restore');
}
/**
* Switch the restore directories around now that we have the new db installed
*/
function drush_provision_drupal_provision_restore() {
$old = d()->root . '/sites/' . d()->uri . '.restore';
$new = d()->root . '/sites/' . d()->uri;
$old = d()->site_path . '.restore';
$new = d()->site_path;
d()->service('file')->switch_paths($old, $new)
->succeed('Swapping out the @path1 and @path2 directories was successful.')
->fail('Swapping the @path1 and @path2 directories has failed.', 'DRUSH_PERM_ERROR');
......@@ -76,7 +76,7 @@ function drush_provision_drupal_provision_restore_rollback() {
* Delete the old site directory and recreate the settings file
*/
function drush_provision_drupal_post_provision_restore() {
_provision_recursive_delete(d()->root . '/sites/' . d()->uri . '.restore');
_provision_recursive_delete(d()->site_path . '.restore');
// This is the actual drupal provisioning requirements.
_provision_drupal_create_directories();
_provision_drupal_create_settings_file();
......
......@@ -15,9 +15,6 @@ function drush_provision_drupal_provision_verify_validate() {
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);
}
// This will not have an effect if you are running it on a platform, just
// tests that if a site is provided it is an existing one
_provision_drupal_valid_site();
}
......
......@@ -431,16 +431,19 @@ class provisionSite extends provisionEnvironment {
// 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;
$this->setProperty('site_enabled', true);
$this->setProperty('language', 'en');
$this->setProperty('site_port', 80);
$this->setProperty('client_email');
$this->setProperty('aliases', array(), TRUE);
$this->setProperty('db_server');
$this->setProperty('db_server', '@server_localhost');
$this->is_oid('db_server');
$this->service_subscribe('db', $this->db_server->name);
// this can potentially be handled by a Drupal sub class
......
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