]> BookStack Code Mirror - bookstack/commitdiff
Merge branch 'floviolleau-db-prefixes' of https://github.com/floviolleau/BookStack...
authorDan Brown <redacted>
Wed, 29 Sep 2021 17:13:38 +0000 (18:13 +0100)
committerDan Brown <redacted>
Wed, 29 Sep 2021 17:13:38 +0000 (18:13 +0100)
.env.example
.env.example.complete
app/Auth/Permissions/PermissionService.php
app/Config/database.php

index 05383f04abcce2f08d732f2b08719cb5b3775a76..33a5d8ab992dc222f3a0978b402215dec6c08368 100644 (file)
@@ -23,6 +23,7 @@ APP_URL=https://example.com
 # Database details
 DB_HOST=localhost
 DB_DATABASE=database_database
+DB_TABLE_PREFIX=
 DB_USERNAME=database_username
 DB_PASSWORD=database_user_password
 
@@ -41,4 +42,4 @@ MAIL_HOST=localhost
 MAIL_PORT=1025
 MAIL_USERNAME=null
 MAIL_PASSWORD=null
-MAIL_ENCRYPTION=null
\ No newline at end of file
+MAIL_ENCRYPTION=null
index 5eb65c27f09f346fa806d48253ab3e2a26c87337..e28fedad9c58246ad2bc5cfc479ce780291bd707 100644 (file)
@@ -55,6 +55,7 @@ APP_PROXIES=null
 DB_HOST=localhost
 DB_PORT=3306
 DB_DATABASE=database_database
+DB_TABLE_PREFIX=
 DB_USERNAME=database_username
 DB_PASSWORD=database_user_password
 
index f84f518944ab81f2d95e8fee776f7e00b8cde8ba..70204c3f374fd0bb9c49f932d5824446da57dc80 100644 (file)
@@ -607,13 +607,13 @@ class PermissionService
      */
     public function filterRestrictedEntityRelations($query, string $tableName, string $entityIdColumn, string $entityTypeColumn, string $action = 'view')
     {
-        $tableDetails = ['tableName' => $tableName, 'entityIdColumn' => $entityIdColumn, 'entityTypeColumn' => $entityTypeColumn];
+        $tableDetails = ['tableName' => $this->db->getTablePrefix() . $tableName, 'entityIdColumn' => $entityIdColumn, 'entityTypeColumn' => $entityTypeColumn];
 
         $q = $query->where(function ($query) use ($tableDetails, $action) {
             $query->whereExists(function ($permissionQuery) use (&$tableDetails, $action) {
                 $permissionQuery->select(['role_id'])->from('joint_permissions')
-                    ->whereRaw('joint_permissions.entity_id=' . $tableDetails['tableName'] . '.' . $tableDetails['entityIdColumn'])
-                    ->whereRaw('joint_permissions.entity_type=' . $tableDetails['tableName'] . '.' . $tableDetails['entityTypeColumn'])
+                    ->whereRaw($this->db->getTablePrefix() . 'joint_permissions.entity_id=' . $tableDetails['tableName'] . '.' . $tableDetails['entityIdColumn'])
+                    ->whereRaw($this->db->getTablePrefix() . 'joint_permissions.entity_type=' . $tableDetails['tableName'] . '.' . $tableDetails['entityTypeColumn'])
                     ->where('action', '=', $action)
                     ->whereIn('role_id', $this->getCurrentUserRoles())
                     ->where(function (QueryBuilder $query) {
@@ -640,7 +640,7 @@ class PermissionService
             $query->where(function ($query) use (&$tableDetails, $morphClass) {
                 $query->whereExists(function ($permissionQuery) use (&$tableDetails, $morphClass) {
                     $permissionQuery->select('id')->from('joint_permissions')
-                        ->whereRaw('joint_permissions.entity_id=' . $tableDetails['tableName'] . '.' . $tableDetails['entityIdColumn'])
+                        ->whereRaw($this->db->getTablePrefix() . 'joint_permissions.entity_id=' . $tableDetails['tableName'] . '.' . $tableDetails['entityIdColumn'])
                         ->where('entity_type', '=', $morphClass)
                         ->where('action', '=', 'view')
                         ->whereIn('role_id', $this->getCurrentUserRoles())
index 7fb51a13bf0664c3994447d2df4cf20591dccdc8..9394439305a3b6839c886f2383dcbaea5141fe18 100644 (file)
@@ -69,7 +69,7 @@ return [
             'port'           => $mysql_port,
             'charset'        => 'utf8mb4',
             'collation'      => 'utf8mb4_unicode_ci',
-            'prefix'         => '',
+            'prefix'         => env('DB_TABLE_PREFIX', ''),
             'prefix_indexes' => true,
             'strict'         => false,
             'engine'         => null,