summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Pugh2016-12-15 13:08:38 -0500
committerJon Pugh2016-12-15 13:08:38 -0500
commita06448253025e4ed1f27998f0afdc5eb1a4421c2 (patch)
tree5b63773aeffd875e3b08099f658fd0137879e295
parentfbf627ff96aa36cf126eb050195c42701bff0d21 (diff)
Issue #2836185: Allow "force-reinstall" drush option for "provision-install" command.7.x-3.8+devshop7.x-3.x+devshop
-rw-r--r--platform/install.provision.inc30
1 files changed, 29 insertions, 1 deletions
diff --git a/platform/install.provision.inc b/platform/install.provision.inc
index 8ffda4e..d5a1968 100644
--- a/platform/install.provision.inc
+++ b/platform/install.provision.inc
@@ -19,7 +19,35 @@ function drush_provision_drupal_provision_install_validate() {
return drush_set_error("PROVISION_URL_REQUIRED", dt("You need to specify a valid url to install a site"));
}
if (_provision_drupal_site_exists()) {
- return drush_set_error('PROVISION_SITE_INSTALLED');
+
+ // If "force-reinstall" option is set, delete the database and files.
+ if (drush_get_option('force-reinstall', FALSE)) {
+
+ drush_log(dt('Forcing reinstall...'), 'ok');
+
+ // Load the current database name from drushrc.php.
+ // I cannot find another way to find the current db_name!
+ require_once(d()->site_path . '/drushrc.php');
+ $old_db_name = $options['db_name'];
+
+ if (d()->service('db')->database_exists($old_db_name)) {
+ d()->service('db')->drop_database($old_db_name);
+ drush_log(dt('Dropped database @database.', array(
+ '@database' => $old_db_name,
+ )), 'ok');
+ }
+
+ // Destroy site_path
+ if (file_exists(d()->site_path)) {
+ _provision_recursive_delete( d()->site_path );
+ drush_log(dt('Deleted @site_path.', array('@site_path' => d()->site_path)), 'ok');
+ }
+ }
+
+ // Check again if site does not exist after the forced reinstall.
+ if (_provision_drupal_site_exists()) {
+ return drush_set_error('PROVISION_SITE_INSTALLED');
+ }
}
}