From 00af40ab14e6c32524daf077006a4f5ae6fd3823 Mon Sep 17 00:00:00 2001 From: floviolleau Date: Sun, 19 Sep 2021 14:28:57 +0200 Subject: [PATCH 1/4] Allow to use DB tables prefix --- app/Auth/Permissions/PermissionService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Auth/Permissions/PermissionService.php b/app/Auth/Permissions/PermissionService.php index f84f51894..70204c3f3 100644 --- a/app/Auth/Permissions/PermissionService.php +++ b/app/Auth/Permissions/PermissionService.php @@ -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()) From 1a8ae41263c622a0cab932336a652b649eca2852 Mon Sep 17 00:00:00 2001 From: floviolleau Date: Sun, 19 Sep 2021 14:31:18 +0200 Subject: [PATCH 2/4] Allow to use DB tables prefix --- app/Config/database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Config/database.php b/app/Config/database.php index 7fb51a13b..939443930 100644 --- a/app/Config/database.php +++ b/app/Config/database.php @@ -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, From f8abad1e3bf09c75cf736286fb323098370fdce2 Mon Sep 17 00:00:00 2001 From: floviolleau Date: Sun, 19 Sep 2021 14:32:35 +0200 Subject: [PATCH 3/4] Allow to use DB tables prefix --- .env.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 05383f04a..33a5d8ab9 100644 --- a/.env.example +++ b/.env.example @@ -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 From dbfa2d58ed5f0667ad6cb87d9e824e18da56f874 Mon Sep 17 00:00:00 2001 From: floviolleau Date: Sun, 19 Sep 2021 14:33:54 +0200 Subject: [PATCH 4/4] Allow to use DB tables prefix --- .env.example.complete | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.example.complete b/.env.example.complete index 49d834ff7..970ec16d9 100644 --- a/.env.example.complete +++ b/.env.example.complete @@ -47,6 +47,7 @@ APP_THEME=false DB_HOST=localhost DB_PORT=3306 DB_DATABASE=database_database +DB_TABLE_PREFIX= DB_USERNAME=database_username DB_PASSWORD=database_user_password