Last active
March 28, 2017 18:41
-
-
Save pbull/79f4599b4483d493dfe63a7ecc8d57eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/utf8mb4_convert.drush.inc b/utf8mb4_convert.drush.inc | |
index de647d0..9a0e66a 100644 | |
--- a/utf8mb4_convert.drush.inc | |
+++ b/utf8mb4_convert.drush.inc | |
@@ -225,16 +225,25 @@ function utf8mb4_convert_drush_command() { | |
$items['utf8mb4-convert-databases'] = array( | |
'description' => "Converts all databases defined in settings.php to utf8mb4.", | |
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, | |
+ 'arguments' => array( | |
+ 'connections' => 'A space separated list of connections. Default is default connection.', | |
+ ), | |
'options' => array( | |
'collation' => 'Specify a collation. Default is "utf8mb4_general_ci", sites with content that is outside of Latin 1 characters may want to use "utf8mb4_unicode_ci".', | |
'charset' => 'Specify a charset. Default is "utf8mb4".', | |
- ) | |
+ ), | |
+ 'examples' => array( | |
+ 'drush utf8mb4-convert-databases' => 'Convert the default database.', | |
+ 'drush utf8mb4-convert-databases default' => 'Convert the default database (same as no argument).', | |
+ 'drush utf8mb4-convert-databases default site2 site3' => 'Convert all specified databases.', | |
+ ), | |
+ 'aliases' => array('mb4c'), | |
); | |
return $items; | |
} | |
-function drush_utf8mb4_convert_databases() { | |
+function drush_utf8mb4_convert_databases($connections_input = NULL) { | |
$charset = drush_get_option('charset', 'utf8mb4'); | |
$collation = drush_get_option('collation', 'utf8mb4_general_ci'); | |
global $databases; | |
@@ -242,11 +251,29 @@ function drush_utf8mb4_convert_databases() { | |
drush_print('Please install Drupal 7.50 or above prior to running this script.'); | |
return; | |
} | |
- if (!drush_confirm('This will convert all databases defined in settings.php to utf8mb4. Back up your databases before continuing! Continue?')) { | |
+ | |
+ // Default to the default DB connection, else use the user input. | |
+ if (empty($connections_input)) { | |
+ $connections['default'] = $databases['default']; | |
+ } | |
+ else { | |
+ $connections_list = array(); | |
+ // Dump the module name in the first position. | |
+ drush_shift(); | |
+ // Get the rest, array_intersect_key needs an associative array for the keys. | |
+ while ($arg = drush_shift()) { | |
+ $connections_list[$arg] = ''; | |
+ } | |
+ $connections = array_intersect_key($databases, $connections_list); | |
+ } | |
+ | |
+ drush_print(dt('This will convert the following databases to utf8mb4: !connections', array('!connections' => implode(', ', array_keys($connections))))); | |
+ if (!drush_confirm('Back up your databases before continuing! Continue?')) { | |
return; | |
} | |
+ | |
$converter = new DrupalCharsetConverter($charset, $collation); | |
- $success = $converter->convert($databases); | |
+ $success = $converter->convert($connections); | |
// Prevent the hook_requirements() check from telling us to convert the | |
// database to utf8mb4. | |
if ($success) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment