mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-27 11:13:30 +02:00
PostgreSQL improvements
This commit is contained in:
parent
1dfe6cd163
commit
f827f304e6
2 changed files with 51 additions and 8 deletions
|
@ -1,4 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* Argora Foundry
|
||||
*
|
||||
* A modular PHP boilerplate for building SaaS applications, admin panels, and control systems.
|
||||
*
|
||||
* @package App
|
||||
* @author Taras Kondratyuk <help@argora.org>
|
||||
* @copyright Copyright (c) 2025 Argora
|
||||
* @license MIT License
|
||||
* @link https://github.com/getargora/foundry
|
||||
*/
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
|
@ -12,11 +23,25 @@ class AuditMiddleware extends Middleware
|
|||
public function __invoke(Request $request, RequestHandler $handler)
|
||||
{
|
||||
if (isset($_SESSION['auth_user_id'])) {
|
||||
$userId = (int)$_SESSION['auth_user_id'];
|
||||
$this->container->get('db')->exec("SET @audit_usr_id = $userId");
|
||||
$this->container->get('db')->exec("SET @audit_ses_id = " . crc32(\Pinga\Session\Session::id()));
|
||||
$userId = (int) $_SESSION['auth_user_id'];
|
||||
$sessionId = crc32(\Pinga\Session\Session::id());
|
||||
$db = $this->container->get('db');
|
||||
|
||||
switch (envi('DB_DRIVER')) {
|
||||
case 'mysql':
|
||||
$db->exec("SET @audit_usr_id = {$userId}");
|
||||
$db->exec("SET @audit_ses_id = {$sessionId}");
|
||||
break;
|
||||
|
||||
case 'pgsql':
|
||||
// Use dotted custom GUC names; SELECT set_config(...) works everywhere
|
||||
$db->exec("SELECT set_config('app.audit_usr_id', '{$userId}', true)");
|
||||
$db->exec("SELECT set_config('app.audit_ses_id', '{$sessionId}', true)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue