If an option is specified, e.g. either the --charset or --collation option, the conversion will fail with the following error:
$ drush utf8mb4-convert-databases --collation="utf8mb4_unicode_ci" -y
This will convert all databases defined in settings.php to utf8mb4. Back up your databases before continuing! Continue? (y/n): y
Target MySQL database: mysite@localhost (default:default)
Converting database: mysite
exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1273 Unknown collation: '1'' in [error]
/var/www/mysite/docroot/includes/database/database.inc:2227
Stack trace:
#0 /var/www/mysite/docroot/includes/database/database.inc(2227): PDOStatement->execute(Array)
#1 /var/www/mysite/docroot/includes/database/database.inc(697):
DatabaseStatementBase->execute(Array, Array)
#2 /var/www/mysite/docroot/includes/database/database.inc(2406):
DatabaseConnection->query('ALTER DATABASE ...', Array, Array)
#3 /home/792e/.drush/utf8mb4_convert/utf8mb4_convert.drush.inc(92): db_query('ALTER DATABASE ...', Array)
#4 /home/792e/.drush/utf8mb4_convert/utf8mb4_convert.drush.inc(62):
DrupalCharsetConverter->convertDatabase('mysite...')
#5 /home/792e/.drush/utf8mb4_convert/utf8mb4_convert.drush.inc(230): DrupalCharsetConverter->convert(Array)
#6 [internal function]: drush_utf8mb4_convert_databases('utf8mb4_unicode...')
#7 /opt/scripts/drush/includes/command.inc(422): call_user_func_array('drush_utf8mb4_c...', Array)
#8 /opt/scripts/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
#9 [internal function]: drush_command('utf8mb4_unicode...')
#10 /opt/scripts/drush/includes/command.inc(199): call_user_func_array('drush_command', Array)
#11 /opt/scripts/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#12 /opt/scripts/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#13 /opt/scripts/drush/drush.php(12): drush_main()
#14 {main}
This happens because of the following code:
public function convertDatabase($database_name, $charset = NULL, $collation = NULL) {
drush_print('Converting database: ' . $database_name);
$sql = "ALTER DATABASE `" . $database_name . "` CHARACTER SET = :charset COLLATE = :collation;";
return $this->connection->query($sql, array(
':charset' => $charset ?: $this->charset,
':collation' => $collation ?: $this->collation,
));
}
The problem is that the logic for identifying the $charset and $collation uses the isset ternary operator ?: which was added to PHP 7 and does not work with PHP 5.6.
Comments
Comment #2
damienmckennaThis corrects the syntax so it's compatible with PHP 5.6.
Comment #4
stefan.r commentedComment #5
stefan.r commentedComment #6
damienmckennaSorry, it turned out there were two other locations of the syntax.
Comment #7
damienmckennaAnd it's still failing with all three changes. I'm still working on it.
Comment #8
damienmckennaIt also helps to pass the arguments correctly in the command line ;-) With the patch above this works:
Comment #10
stefan.r commentedCan we mark this as fixed?
Comment #11
damienmckennaYes, thank you!