]> BookStack Code Mirror - bookstack/blobdiff - config/database.php
Trying to make the tests green.
[bookstack] / config / database.php
index 9650de117ff98ad0c58c9087a32e670cc2eb3161..3883b58686ae4abb54c26b7dc94578be236e6c6f 100644 (file)
@@ -1,5 +1,29 @@
 <?php
 
+// REDIS - Split out configuration into an array
+if (env('REDIS_SERVERS', false)) {
+    $redisServerKeys = ['host', 'port', 'database'];
+    $redisServers = explode(',', trim(env('REDIS_SERVERS', '127.0.0.1:6379:0'), ','));
+    $redisConfig = [
+        'cluster' => env('REDIS_CLUSTER', false)
+    ];
+    foreach ($redisServers as $index => $redisServer) {
+        $redisServerName = ($index === 0) ? 'default' : 'redis-server-' . $index;
+        $redisServerDetails = explode(':', $redisServer);
+        if (count($redisServerDetails) < 2) $redisServerDetails[] = '6379';
+        if (count($redisServerDetails) < 3) $redisServerDetails[] = '0';
+        $redisConfig[$redisServerName] = array_combine($redisServerKeys, $redisServerDetails);
+    }
+}
+
+$mysql_host = env('DB_HOST', 'localhost');
+$mysql_host_exploded = explode(':', $mysql_host);
+$mysql_port = env('DB_PORT', 3306);
+if (count($mysql_host_exploded) > 1) {
+    $mysql_host = $mysql_host_exploded[0];
+    $mysql_port = intval($mysql_host_exploded[1]);
+}
+
 return [
 
     /*
@@ -54,22 +78,23 @@ return [
 
         'mysql' => [
             'driver'    => 'mysql',
-            'host'      => env('DB_HOST', 'localhost'),
+            'host'      => $mysql_host,
             'database'  => env('DB_DATABASE', 'forge'),
             'username'  => env('DB_USERNAME', 'forge'),
             'password'  => env('DB_PASSWORD', ''),
-            'charset'   => 'utf8',
-            'collation' => 'utf8_unicode_ci',
+            'port'      => $mysql_port,
+            'charset'   => 'utf8mb4',
+            'collation' => 'utf8mb4_unicode_ci',
             'prefix'    => '',
             'strict'    => false,
         ],
 
         'mysql_testing' => [
             'driver'    => 'mysql',
-            'host'      => 'localhost',
+            'host'      => '127.0.0.1',
             'database'  => 'bookstack-test',
-            'username'  => 'bookstack-test',
-            'password'  => 'bookstack-test',
+            'username'  => env('MYSQL_USER', 'bookstack-test'),
+            'password'  => env('MYSQL_PASSWORD', 'bookstack-test'),
             'charset'   => 'utf8',
             'collation' => 'utf8_unicode_ci',
             'prefix'    => '',
@@ -123,16 +148,6 @@ return [
     |
     */
 
-    'redis' => [
-
-        'cluster' => false,
-
-        'default' => [
-            'host'     => '127.0.0.1',
-            'port'     => 6379,
-            'database' => 0,
-        ],
-
-    ],
+    'redis' => env('REDIS_SERVERS', false) ? $redisConfig : [],
 
 ];