diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Root.php b/lib/Alchemy/Phrasea/Controller/Admin/Root.php index d068654b63..06758408fb 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Root.php @@ -35,7 +35,7 @@ class Root implements ControllerProviderInterface $controllers->get('/', function(Application $app, Request $request) { try { - \User_Adapter::updateClientInfos($app, 3); + \Session_Logger::updateClientInfos($app, 3); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } @@ -103,7 +103,7 @@ class Root implements ControllerProviderInterface $controllers->get('/tree/', function(Application $app, Request $request) { try { - \User_Adapter::updateClientInfos($app, 3); + \Session_Logger::updateClientInfos($app, 3); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } diff --git a/lib/Alchemy/Phrasea/Controller/Client/Root.php b/lib/Alchemy/Phrasea/Controller/Client/Root.php index e000efd76a..18cf4f9b69 100644 --- a/lib/Alchemy/Phrasea/Controller/Client/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Client/Root.php @@ -289,7 +289,7 @@ class Root implements ControllerProviderInterface public function getClient(Application $app, Request $request) { try { - \User_Adapter::updateClientInfos($app, 2); + \Session_Logger::updateClientInfos($app, 2); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } diff --git a/lib/Alchemy/Phrasea/Controller/Lightbox.php b/lib/Alchemy/Phrasea/Controller/Lightbox.php index 0e2a3d487c..15395ea667 100644 --- a/lib/Alchemy/Phrasea/Controller/Lightbox.php +++ b/lib/Alchemy/Phrasea/Controller/Lightbox.php @@ -64,7 +64,7 @@ class Lightbox implements ControllerProviderInterface $controllers->get('/', function (SilexApplication $app) { try { - \User_Adapter::updateClientInfos($app, 6); + \Session_Logger::updateClientInfos($app, 6); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } @@ -200,7 +200,7 @@ class Lightbox implements ControllerProviderInterface $controllers->get('/validate/{ssel_id}/', function (SilexApplication $app, $ssel_id) { try { - \User_Adapter::updateClientInfos($app, 6); + \Session_Logger::updateClientInfos($app, 6); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } @@ -254,7 +254,7 @@ class Lightbox implements ControllerProviderInterface $controllers->get('/compare/{ssel_id}/', function (SilexApplication $app, $ssel_id) { try { - \User_Adapter::updateClientInfos($app, 6); + \Session_Logger::updateClientInfos($app, 6); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } @@ -308,7 +308,7 @@ class Lightbox implements ControllerProviderInterface $controllers->get('/feeds/entry/{entry_id}/', function (SilexApplication $app, $entry_id) { try { - \User_Adapter::updateClientInfos($app, 6); + \Session_Logger::updateClientInfos($app, 6); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Root.php b/lib/Alchemy/Phrasea/Controller/Prod/Root.php index dc18b45bd6..3360b20e77 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Root.php @@ -41,7 +41,7 @@ class Root implements ControllerProviderInterface $controllers->get('/', function(Application $app) { try { - \User_Adapter::updateClientInfos($app, 1); + \Session_Logger::updateClientInfos($app, 1); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } diff --git a/lib/Alchemy/Phrasea/Controller/Report/Root.php b/lib/Alchemy/Phrasea/Controller/Report/Root.php index 8ebdd99b98..168d78bdaa 100644 --- a/lib/Alchemy/Phrasea/Controller/Report/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Report/Root.php @@ -68,7 +68,7 @@ class Root implements ControllerProviderInterface $dashboard = new \module_report_dashboard($app, $app['authentication']->getUser()); if ('json' !== $request->getRequestFormat()) { - \User_Adapter::updateClientInfos($app, 4); + \Session_Logger::updateClientInfos($app, 4); $dashboard->execute(); diff --git a/lib/classes/Session/Logger.php b/lib/classes/Session/Logger.php index d9998cecc5..dc1f06a1d2 100644 --- a/lib/classes/Session/Logger.php +++ b/lib/classes/Session/Logger.php @@ -10,13 +10,8 @@ */ use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Exception\SessionNotFound; -/** - * - * @package Session - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ class Session_Logger { /** @@ -185,4 +180,86 @@ class Session_Logger return new self($app, $databox, $row['id']); } + + public static function updateClientInfos(Application $app, $appId) + { + if (!$app['authentication']->isAuthenticated()) { + return; + } + + $session = $app['EM']->find('Entities\Session', $app['session']->get('session_id')); + + if (!$session) { + throw new SessionNotFound('No session found'); + } + + if (!$session->hasModuleId($appId)) { + $module = new \Entities\SessionModule(); + + $module->setModuleId($appId); + $module->setSession($session); + $session->addModule($module); + + $app['EM']->persist($module); + $app['EM']->persist($session); + + $app['EM']->flush(); + } + + $usrId = $app['authentication']->getUser()->get_id(); + + $user = User_Adapter::getInstance($usrId, $app); + + $appName = array( + '1' => 'Prod', + '2' => 'Client', + '3' => 'Admin', + '4' => 'Report', + '5' => 'Thesaurus', + '6' => 'Compare', + '7' => 'Validate', + '8' => 'Upload', + '9' => 'API' + ); + + if (isset($appName[$appId])) { + $sbas_ids = array_keys($user->ACL()->get_granted_sbas()); + + foreach ($sbas_ids as $sbas_id) { + try { + $logger = $app['phraseanet.logger']($app['phraseanet.appbox']->get_databox($sbas_id)); + + $connbas = connection::getPDOConnection($app, $sbas_id); + $sql = 'SELECT appli FROM log WHERE id = :log_id'; + $stmt = $connbas->prepare($sql); + $stmt->execute(array(':log_id' => $logger->get_id())); + $row3 = $stmt->fetch(PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + if (!$row3) + throw new Exception('no log'); + $applis = unserialize($row3['appli']); + + if (!in_array($appId, $applis)) { + $applis[] = $appId; + } + + $sql = 'UPDATE log SET appli = :applis WHERE id = :log_id'; + + $params = array( + ':applis' => serialize($applis) + , ':log_id' => $logger->get_id() + ); + + $stmt = $connbas->prepare($sql); + $stmt->execute($params); + $stmt->closeCursor(); + } catch (Exception $e) { + + } + } + } + + return; + } } diff --git a/lib/classes/User/Adapter.php b/lib/classes/User/Adapter.php index 2913ffad4a..8d99caf491 100644 --- a/lib/classes/User/Adapter.php +++ b/lib/classes/User/Adapter.php @@ -1496,88 +1496,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface return $this->_prefs[$prop]; } - public static function updateClientInfos(Application $app, $app_id) - { - if (!$app['authentication']->isAuthenticated()) { - return; - } - - $session = $app['EM']->find('Entities\Session', $app['session']->get('session_id')); - - if (!$session) { - throw new SessionNotFound('No session found'); - } - - if (!$session->hasModuleId($app_id)) { - $module = new \Entities\SessionModule(); - - $module->setModuleId($app_id); - $module->setSession($session); - $session->addModule($module); - - $app['EM']->persist($module); - $app['EM']->persist($session); - - $app['EM']->flush(); - } - - $usr_id = $app['authentication']->getUser()->get_id(); - - $user = User_Adapter::getInstance($usr_id, $app); - - $appName = array( - '1' => 'Prod', - '2' => 'Client', - '3' => 'Admin', - '4' => 'Report', - '5' => 'Thesaurus', - '6' => 'Compare', - '7' => 'Validate', - '8' => 'Upload', - '9' => 'API' - ); - - if (isset($appName[$app_id])) { - $sbas_ids = array_keys($user->ACL()->get_granted_sbas()); - - foreach ($sbas_ids as $sbas_id) { - try { - $logger = $app['phraseanet.logger']($app['phraseanet.appbox']->get_databox($sbas_id)); - - $connbas = connection::getPDOConnection($app, $sbas_id); - $sql = 'SELECT appli FROM log WHERE id = :log_id'; - $stmt = $connbas->prepare($sql); - $stmt->execute(array(':log_id' => $logger->get_id())); - $row3 = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if (!$row3) - throw new Exception('no log'); - $applis = unserialize($row3['appli']); - - if (!in_array($app_id, $applis)) { - $applis[] = $app_id; - } - - $sql = 'UPDATE log SET appli = :applis WHERE id = :log_id'; - - $params = array( - ':applis' => serialize($applis) - , ':log_id' => $logger->get_id() - ); - - $stmt = $connbas->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - } catch (Exception $e) { - - } - } - } - - return; - } - public static function get_sys_admins(Application $app) { $sql = 'SELECT usr_id, usr_login FROM usr diff --git a/lib/classes/User/Interface.php b/lib/classes/User/Interface.php index 3b23447c1d..0320109a6b 100644 --- a/lib/classes/User/Interface.php +++ b/lib/classes/User/Interface.php @@ -150,8 +150,6 @@ interface User_Interface public function getPrefs($prop); - public static function updateClientInfos(Application $app, $app_id); - public static function get_sys_admins(Application $app); public static function set_sys_admins(Application $app, $admins);