Move updateClientInfos functioon to Session_Logger

This commit is contained in:
Nicolas Le Goff
2013-08-22 10:51:45 +02:00
parent 8790399214
commit e07c57d409
8 changed files with 92 additions and 99 deletions

View File

@@ -35,7 +35,7 @@ class Root implements ControllerProviderInterface
$controllers->get('/', function(Application $app, Request $request) { $controllers->get('/', function(Application $app, Request $request) {
try { try {
\User_Adapter::updateClientInfos($app, 3); \Session_Logger::updateClientInfos($app, 3);
} catch (SessionNotFound $e) { } catch (SessionNotFound $e) {
return $app->redirectPath('logout'); return $app->redirectPath('logout');
} }
@@ -103,7 +103,7 @@ class Root implements ControllerProviderInterface
$controllers->get('/tree/', function(Application $app, Request $request) { $controllers->get('/tree/', function(Application $app, Request $request) {
try { try {
\User_Adapter::updateClientInfos($app, 3); \Session_Logger::updateClientInfos($app, 3);
} catch (SessionNotFound $e) { } catch (SessionNotFound $e) {
return $app->redirectPath('logout'); return $app->redirectPath('logout');
} }

View File

@@ -289,7 +289,7 @@ class Root implements ControllerProviderInterface
public function getClient(Application $app, Request $request) public function getClient(Application $app, Request $request)
{ {
try { try {
\User_Adapter::updateClientInfos($app, 2); \Session_Logger::updateClientInfos($app, 2);
} catch (SessionNotFound $e) { } catch (SessionNotFound $e) {
return $app->redirectPath('logout'); return $app->redirectPath('logout');
} }

View File

@@ -64,7 +64,7 @@ class Lightbox implements ControllerProviderInterface
$controllers->get('/', function (SilexApplication $app) { $controllers->get('/', function (SilexApplication $app) {
try { try {
\User_Adapter::updateClientInfos($app, 6); \Session_Logger::updateClientInfos($app, 6);
} catch (SessionNotFound $e) { } catch (SessionNotFound $e) {
return $app->redirectPath('logout'); return $app->redirectPath('logout');
} }
@@ -200,7 +200,7 @@ class Lightbox implements ControllerProviderInterface
$controllers->get('/validate/{ssel_id}/', function (SilexApplication $app, $ssel_id) { $controllers->get('/validate/{ssel_id}/', function (SilexApplication $app, $ssel_id) {
try { try {
\User_Adapter::updateClientInfos($app, 6); \Session_Logger::updateClientInfos($app, 6);
} catch (SessionNotFound $e) { } catch (SessionNotFound $e) {
return $app->redirectPath('logout'); return $app->redirectPath('logout');
} }
@@ -254,7 +254,7 @@ class Lightbox implements ControllerProviderInterface
$controllers->get('/compare/{ssel_id}/', function (SilexApplication $app, $ssel_id) { $controllers->get('/compare/{ssel_id}/', function (SilexApplication $app, $ssel_id) {
try { try {
\User_Adapter::updateClientInfos($app, 6); \Session_Logger::updateClientInfos($app, 6);
} catch (SessionNotFound $e) { } catch (SessionNotFound $e) {
return $app->redirectPath('logout'); return $app->redirectPath('logout');
} }
@@ -308,7 +308,7 @@ class Lightbox implements ControllerProviderInterface
$controllers->get('/feeds/entry/{entry_id}/', function (SilexApplication $app, $entry_id) { $controllers->get('/feeds/entry/{entry_id}/', function (SilexApplication $app, $entry_id) {
try { try {
\User_Adapter::updateClientInfos($app, 6); \Session_Logger::updateClientInfos($app, 6);
} catch (SessionNotFound $e) { } catch (SessionNotFound $e) {
return $app->redirectPath('logout'); return $app->redirectPath('logout');
} }

View File

@@ -41,7 +41,7 @@ class Root implements ControllerProviderInterface
$controllers->get('/', function(Application $app) { $controllers->get('/', function(Application $app) {
try { try {
\User_Adapter::updateClientInfos($app, 1); \Session_Logger::updateClientInfos($app, 1);
} catch (SessionNotFound $e) { } catch (SessionNotFound $e) {
return $app->redirectPath('logout'); return $app->redirectPath('logout');
} }

View File

@@ -68,7 +68,7 @@ class Root implements ControllerProviderInterface
$dashboard = new \module_report_dashboard($app, $app['authentication']->getUser()); $dashboard = new \module_report_dashboard($app, $app['authentication']->getUser());
if ('json' !== $request->getRequestFormat()) { if ('json' !== $request->getRequestFormat()) {
\User_Adapter::updateClientInfos($app, 4); \Session_Logger::updateClientInfos($app, 4);
$dashboard->execute(); $dashboard->execute();

View File

@@ -10,13 +10,8 @@
*/ */
use Alchemy\Phrasea\Application; 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 class Session_Logger
{ {
/** /**
@@ -185,4 +180,86 @@ class Session_Logger
return new self($app, $databox, $row['id']); 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;
}
} }

View File

@@ -1496,88 +1496,6 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
return $this->_prefs[$prop]; 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) public static function get_sys_admins(Application $app)
{ {
$sql = 'SELECT usr_id, usr_login FROM usr $sql = 'SELECT usr_id, usr_login FROM usr

View File

@@ -150,8 +150,6 @@ interface User_Interface
public function getPrefs($prop); public function getPrefs($prop);
public static function updateClientInfos(Application $app, $app_id);
public static function get_sys_admins(Application $app); public static function get_sys_admins(Application $app);
public static function set_sys_admins(Application $app, $admins); public static function set_sys_admins(Application $app, $admins);