Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/boa unfork #6

Merged
merged 7 commits into from
Oct 20, 2016
28 changes: 28 additions & 0 deletions db/Provision/Service/db/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ function can_grant_privileges() {

function grant($name, $username, $password, $host = '') {
$host = ($host) ? $host : '%';
if ($host != "127.0.0.1") {
$extra_host = "127.0.0.1";
$success_extra_host = $this->query("GRANT ALL PRIVILEGES ON `%s`.* TO `%s`@`%s` IDENTIFIED BY '%s'", $name, $username, $extra_host, $password);
}
// Issue: https://github.com/omega8cc/provision/issues/2
return $this->query("GRANT ALL PRIVILEGES ON `%s`.* TO `%s`@`%s` IDENTIFIED BY '%s'", $name, $username, $host, $password);
}

Expand All @@ -79,6 +84,29 @@ function revoke($name, $username, $host = '') {
if (!$grant_found) {
$success = $this->query("DROP USER `%s`@`%s`", $username, $host) && $success;
}

if ($host != "127.0.0.1") {
$extra_host = "127.0.0.1";
$success_extra_host = $this->query("REVOKE ALL PRIVILEGES ON `%s`.* FROM `%s`@`%s`", $name, $username, $extra_host);

// check if there are any privileges left for the user
$grants = $this->query("SHOW GRANTS FOR `%s`@`%s`", $username, $extra_host);
$grant_found = FALSE;
if ($grants) {
while ($grant = $grants->fetch()) {
// those are empty grants: just the user line
if (!preg_match("/^GRANT USAGE ON /", array_pop($grant))) {
// real grant, we shouldn't remove the user
$grant_found = TRUE;
break;
}
}
}
if (!$grant_found) {
$success_extra_host = $this->query("DROP USER `%s`@`%s`", $username, $extra_host) && $success_extra_host;
}
}

return $success;
}

Expand Down
1 change: 1 addition & 0 deletions install.hostmaster.inc
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ function drush_provision_hostmaster_install($site = NULL) {
'db_server' => $dbserver,
'uri' => $site,
'client_name' => drush_get_option('client_name'),
'client_email' => drush_get_option('client_email'),
'profile' => $profile,
'drush_aliases' => 'hm',
));
Expand Down
3 changes: 3 additions & 0 deletions migrate.hostmaster.inc
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,8 @@ function drush_provision_post_hostmaster_migrate($site, $platform) {
'old_platform_name' => drush_get_option('old_platform'),
'new_platform_name' => drush_get_option('new_platform'),
));
// We need to re-verify @server_master via frontend to re-generate
// its drush alias and to update Nginx configuration files.
provision_backend_invoke('@hostmaster', 'hosting-task', array(@server_master, 'verify'), array('force' => TRUE));
}

19 changes: 18 additions & 1 deletion platform/clone.provision.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Clone command implementation
*
* This command when called will
* This command when called will
* 1. Make a backup of the current site, before modifications are made.
* 2. Execute 'provision deploy' to build the new site using the backup of the old site.
*
Expand Down Expand Up @@ -38,6 +38,19 @@ function drush_provision_drupal_pre_provision_clone_rollback($new_name, $platfor
function drush_provision_drupal_provision_clone($new_name, $platform = null) {
drush_set_option('old_platform', d()->platform->name);

// If the site is cloned between platforms and not just in the same platform,
// we should update the info collected about source and target platform first.
if (!is_null(d($platform)->name) && (d($platform)->name != d()->platform->name)) {
provision_backend_invoke('@hostmaster', 'hosting-task', array(d()->platform->name, 'verify'), array('force' => TRUE));
sleep(5); // A small trick to avoid high load and race conditions.
provision_backend_invoke('@hostmaster', 'hosting-task', array(d($platform)->name, 'verify'), array('force' => TRUE));
sleep(5); // A small trick to avoid high load and race conditions.
}
// We should update also the info collected about the site before running clone.
$local_uri_verify = '@' . d()->uri;
provision_backend_invoke('@hostmaster', 'hosting-task', array($local_uri_verify, 'verify'), array('force' => TRUE));
sleep(5); // A small trick to avoid high load and race conditions.

$options = d()->options;
$options['uri'] = ltrim($new_name, '@');
$hash_name = drush_get_option('#name') ? '#name' : 'name';
Expand Down Expand Up @@ -80,7 +93,11 @@ function drush_provision_drupal_provision_clone($new_name, $platform = null) {
provision_backend_invoke($new_name, 'provision-deploy', array(drush_get_option('backup_file')), $deploy_options);

if (!drush_get_error()) {
// Verify the newly cloned site.
provision_backend_invoke($new_name, 'provision-verify');
sleep(5); // A small trick to avoid high load and race conditions.
// Verify again also original site via frontend to avoid issue #1004526
provision_backend_invoke('@hostmaster', 'hosting-task', array($local_uri_verify, 'verify'), array('force' => TRUE));
}

provision_reload_config('site', d()->site_path . '/drushrc.php');
Expand Down
5 changes: 5 additions & 0 deletions platform/import.provision.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ function drush_provision_drupal_post_provision_import() {
// Do not automatically save the drushrc at the end of the command.
drush_set_option('provision_save_config', false);

// We still run this extra backend sub-task to properly register packages etc.
provision_backend_invoke(d()->name, 'provision-verify');
sleep(5); // A small trick to avoid high load and race conditions.

// We run this extra verify via frontend to avoid issue #1004526.
provision_backend_invoke('@hostmaster', 'hosting-task', array(d()->name, 'verify'), array('force' => TRUE));

drush_include_engine('drupal', 'cron_key');

Expand Down
93 changes: 87 additions & 6 deletions platform/migrate.provision.inc
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,72 @@ function drush_provision_drupal_provision_migrate($platform, $new_name = NULL) {
$options = array();
$options['uri'] = d()->uri;

// If the site is migrated between platforms and not just renamed,
// we should update the info collected about source and target platform first.
// Note that we have to exclude Hostmaster platform from this extra verify.
if (d()->profile != 'hostmaster') {
if (!is_null(d($platform)->name) && (d($platform)->name != d()->platform->name)) {
provision_backend_invoke('@hostmaster', 'hosting-task', array(d()->platform->name, 'verify'), array('force' => TRUE));
sleep(5); // A small trick to avoid high load and race conditions.
provision_backend_invoke('@hostmaster', 'hosting-task', array(d($platform)->name, 'verify'), array('force' => TRUE));
sleep(5); // A small trick to avoid high load and race conditions.
}
}

if (!is_null($new_name) && ($new_name != d()->name)) {
$options = d()->options;
$options['uri'] = ltrim($new_name, '@');
$hash_name = drush_get_option('#name') ? '#name' : 'name';
$options[$hash_name] = $new_name;
$new_aliases = array();
$old_aliases = (is_array($options['aliases'])) ? $options['aliases'] : FALSE;
$pre_old_uri = ltrim(d()->uri, '@');
$pre_new_uri = ltrim($new_name, '@');
$raw_old_uri = preg_replace('/^www\./', '', $pre_old_uri);
$raw_new_uri = preg_replace('/^www\./', '', $pre_new_uri);
$www_old_uri = "www." . $raw_old_uri;
$www_new_uri = "www." . $raw_new_uri;
if (is_array($old_aliases) && !empty($old_aliases)) {
foreach ($old_aliases as $alias) {
if (!preg_match("/^www\./", $pre_old_uri) && preg_match("/^www\./", $pre_new_uri)) {
$new_aliases[] = str_replace($www_old_uri, $raw_new_uri, $alias);
}
elseif (preg_match("/^www\./", $pre_old_uri) && !preg_match("/^www\./", $pre_new_uri)) {
$new_aliases[] = str_replace($raw_old_uri, $www_new_uri, $alias);
}
elseif (!preg_match("/^www\./", $pre_old_uri) && !preg_match("/^www\./", $pre_new_uri)) {
$new_aliases[] = str_replace($www_old_uri, $www_new_uri, $alias);
}
elseif (preg_match("/^www\./", $pre_old_uri) && preg_match("/^www\./", $pre_new_uri)) {
$new_aliases[] = str_replace($raw_old_uri, $raw_new_uri, $alias);
}
}
$unique_aliases = array_unique($new_aliases); // Make sure there are no duplicates.
$options['aliases'] = array(); // Reset original aliases array.
$options['aliases'] = $unique_aliases; // Use rewritten aliases array.
if (!is_null(d($platform)->name) && (d($platform)->name == d()->platform->name)) {
drush_set_option('rename_only', TRUE);
}
drush_set_option('aliases', $unique_aliases);
}
else {
$detected_aliases = provision_drupal_find_aliases();
drush_set_option('aliases', $detected_aliases);
}
// Warning: do not try to re-verify the original site here
// even with backend-only verify, because it would create
// (and never delete) duplicate vhost with old domain
// and all aliases included - see issue #1067702.
}
else {
// We have to exclude Hostmaster site from any extra verify steps.
if (d()->profile != 'hostmaster') {
// We should update also the info collected about the site before running migrate task.
// Doing this is safe only when the site is migrated with the same name - see issue #1067702.
$local_uri_verify = '@' . d()->uri;
provision_backend_invoke('@hostmaster', 'hosting-task', array($local_uri_verify, 'verify'), array('force' => TRUE));
sleep(5); // A small trick to avoid high load and race conditions.
}
}
$options['platform'] = $platform;
$options['root'] = d($platform)->root;
Expand Down Expand Up @@ -140,17 +201,37 @@ function drush_provision_drupal_post_provision_migrate($platform, $new_name = NU
d()->service('http')->sync(d()->site_path);
}



if (!is_null($new_name) && ($new_name != d()->name)) {
// remove the existing alias
// Use correct context for cleanup operations.
$source_name = drush_get_option('source_name');
// Remove the existing drush alias.
$config = new Provision_Config_Drushrc_Alias(d()->name);
$config->unlink();

// Delete the old site directory.
_provision_recursive_delete(d($source_name)->site_path);
d()->service('http')->sync(d($source_name)->site_path);
// Remove old site name aliases.
_provision_drupal_delete_aliases();
// Remove the symlink in the clients directory.
_provision_client_delete_symlink();
}

// Load the config file of the newly migrated site and return it to hosting.
provision_reload_config('site', drush_get_option('new_site_path', d()->site_path) . '/drushrc.php');
$rename_only = drush_get_option('rename_only');
if ($rename_only) {
// We run this extra tricky backend verify to avoid issue #1004526.
if (d()->profile != 'hostmaster') {
$deploy_replace_site = drush_get_option('deploy_replace_site');
$final_aliases = drush_get_option('aliases');
provision_reload_config('site', drush_get_option('new_site_path', d($new_name)->site_path) . '/drushrc.php');
d($new_name)->aliases = drush_set_option('aliases', $final_aliases);
d($new_name)->write_alias();
drush_set_option('aliases', drush_get_option('aliases'), 'site');
drush_set_option('provision_save_config', false);
provision_backend_invoke($new_name, 'provision-verify');
}
}
else {
// Load the config file of the newly migrated site and return it to hosting.
provision_reload_config('site', drush_get_option('new_site_path', d()->site_path) . '/drushrc.php');
}
}