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

DamienMcKenna created an issue. See original summary.

damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new720 bytes

This corrects the syntax so it's compatible with PHP 5.6.

  • stefan.r committed ca4a9b7 on 7.x-1.x authored by DamienMcKenna
    Issue #2857698 by DamienMcKenna: Specifying options fails with PHP 5.6,...
stefan.r’s picture

Status: Needs review » Patch (to be ported)
stefan.r’s picture

Status: Patch (to be ported) » Fixed
damienmckenna’s picture

Status: Fixed » Needs review
StatusFileSize
new1.52 KB

Sorry, it turned out there were two other locations of the syntax.

damienmckenna’s picture

Status: Needs review » Needs work

And it's still failing with all three changes. I'm still working on it.

damienmckenna’s picture

Issue summary: View changes
Status: Needs work » Needs review

It also helps to pass the arguments correctly in the command line ;-) With the patch above this works:

$ 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: catalyst@localhost (default:default)
Converting database: catalyst
Converting table: actions
Converting table: aggregator_category
Converting table: aggregator_category_feed
Converting table: aggregator_category_item
Converting table: aggregator_feed
Converting table: aggregator_item
...

  • stefan.r committed d847bde on 7.x-1.x authored by DamienMcKenna
    Issue #2857698 by DamienMcKenna: Specifying options fails with PHP 5.6,...
stefan.r’s picture

Can we mark this as fixed?

damienmckenna’s picture

Status: Needs review » Fixed

Yes, thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.