]> BookStack Code Mirror - bookstack/commitdiff
Fixed quoting db/table names in encoding migration.
authorDan Brown <redacted>
Sun, 2 Jul 2017 16:34:32 +0000 (17:34 +0100)
committerDan Brown <redacted>
Sun, 2 Jul 2017 16:34:32 +0000 (17:34 +0100)
Also fixed incorrect if statement in db config.

config/database.php
database/migrations/2017_07_02_152834_update_db_encoding_to_ut8mb4.php

index 64dc89864e4cb4123e2b5e0b86dad7badee2c71b..3883b58686ae4abb54c26b7dc94578be236e6c6f 100644 (file)
@@ -19,7 +19,7 @@ if (env('REDIS_SERVERS', false)) {
 $mysql_host = env('DB_HOST', 'localhost');
 $mysql_host_exploded = explode(':', $mysql_host);
 $mysql_port = env('DB_PORT', 3306);
-if (count($mysql_host_exploded) > 0) {
+if (count($mysql_host_exploded) > 1) {
     $mysql_host = $mysql_host_exploded[0];
     $mysql_port = intval($mysql_host_exploded[1]);
 }
index 8d06d92b1242a354525ad08ae2bfcf61b9cf143e..550c95826c4693c4d9db36631ec971adf9f434ac 100644 (file)
@@ -17,11 +17,11 @@ class UpdateDbEncodingToUt8mb4 extends Migration
         $tables = DB::select('SHOW TABLES');
         $pdo = DB::getPdo();
         $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
-        $pdo->exec('ALTER DATABASE '.$database.' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
+        $pdo->exec('ALTER DATABASE `'.$database.'` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
         $key = 'Tables_in_' . $database;
         foreach ($tables as $table) {
             $tableName = $table->$key;
-            $pdo->exec('ALTER TABLE '.$tableName.' CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
+            $pdo->exec('ALTER TABLE `'.$tableName.'` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
         }
     }
 
@@ -36,11 +36,11 @@ class UpdateDbEncodingToUt8mb4 extends Migration
         $tables = DB::select('SHOW TABLES');
         $pdo = DB::getPdo();
         $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
-        $pdo->exec('ALTER DATABASE '.$database.' CHARACTER SET utf8 COLLATE utf8_unicode_ci');
+        $pdo->exec('ALTER DATABASE `'.$database.'` CHARACTER SET utf8 COLLATE utf8_unicode_ci');
         $key = 'Tables_in_' . $database;
         foreach ($tables as $table) {
             $tableName = $table->$key;
-            $pdo->exec('ALTER TABLE '.$tableName.' CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci');
+            $pdo->exec('ALTER TABLE `'.$tableName.'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci');
         }
     }
 }