|
From: <gem...@li...> - 2011-12-19 12:39:24
|
Revision: 373
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=373&view=rev
Author: mennodekker
Date: 2011-12-19 12:39:13 +0000 (Mon, 19 Dec 2011)
Log Message:
-----------
Moved AccessLogActions from session to cache
Modified Paths:
--------------
trunk/library/classes/Gems/AccessLog.php
trunk/library/classes/Gems/Default/LogMaintenanceAction.php
trunk/library/classes/Gems/Util/ReceptionCode.php
trunk/library/classes/Gems/Util.php
Added Paths:
-----------
trunk/library/classes/Gems/Util/AccessLogActions.php
Modified: trunk/library/classes/Gems/AccessLog.php
===================================================================
--- trunk/library/classes/Gems/AccessLog.php 2011-12-19 10:21:13 UTC (rev 372)
+++ trunk/library/classes/Gems/AccessLog.php 2011-12-19 12:39:13 UTC (rev 373)
@@ -4,7 +4,7 @@
/**
* Copyright (c) 2011, Erasmus MC
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@@ -15,7 +15,7 @@
* * Neither the name of Erasmus MC nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -56,7 +56,7 @@
* Convenience calls to the log method:
*
* When you try to call 'log' + anything it will be interpreted as a call to the log
- * method where the part following log is the action and the first argument is the
+ * method where the part following log is the action and the first argument is the
* respondentId. When you want to utilize the full power of the logging system, use
* the log method directly.
*
@@ -86,12 +86,12 @@
$this->_userInfo = GemsEscort::getInstance()->session;
$this->loadActions();
}
-
+
/**
* Return an instance of the Gems_AccesLog class
- *
+ *
* @param Zend_Db_Adapter_Abstract $db
- * @return Gems_AccessLog
+ * @return Gems_AccessLog
*/
public static function getLog(Zend_Db_Adapter_Abstract $db = null)
{
@@ -107,58 +107,55 @@
protected function getActionId($action)
{
- if (! array_key_exists($action, $this->_sessionStore->actions)) {
+ if (! array_key_exists($action, $this->_actions)) {
//Check if a refresh fixes the problem
$this->loadActions(true);
- if (! array_key_exists($action, $this->_sessionStore->actions)) {
+ if (! array_key_exists($action, $this->_actions)) {
$values['glac_name'] = $action;
$values['glac_change'] = preg_match('/(save|add|store|delete|remove|create)/', $action);
-
- /*
+
+ /*
* For 1.3 release the default behaviour is to disable logging for all actions,
* so we get an opt-in per action
- */
+ */
$values['glac_log'] = 0;
-
+
/*
* Later on, we can set some rules like below to disable logging for
* actions like the autofilter
*/
//$values['glac_log'] = !substr_count($action, '.autofilter');
$values['glac_created'] = new Zend_Db_Expr('CURRENT_TIMESTAMP');
-
+
$this->_db->insert('gems__log_actions', $values);
$this->loadActions(true);
}
}
- return $this->_sessionStore->actions[$action]['id'];
+ return $this->_actions[$action]['id'];
}
/**
* Load the actions into memory, use optional parameter to enforce refreshing
- *
- * @param type $reset
+ *
+ * @param type $reset
*/
public function loadActions($reset = false)
{
//When project escort doesn't implement the log interface, we disable logging and don't load actions
- if (GemsEscort::getInstance() instanceof Gems_Project_Log_LogRespondentAccessInterface &&
- ($reset || (! isset($this->_sessionStore->actions)))) {
-
- $actions = array();
-
- try {
- $actionRows = $this->_db->fetchAll('SELECT glac_name, glac_id_action, glac_log FROM gems__log_actions ORDER BY glac_name');
- foreach($actionRows as $actionRow) {
- $actions[$actionRow['glac_name']]['id'] = $actionRow['glac_id_action'];
- $actions[$actionRow['glac_name']]['log'] = $actionRow['glac_log'];
- }
- } catch (Exception $e) {
- }
-
- $this->_sessionStore->actions = $actions;
+ if (GemsEscort::getInstance() instanceof Gems_Project_Log_LogRespondentAccessInterface &&
+ ($reset || (! isset($this->_actions)))) {
+
+ $actions = GemsEscort::getInstance()->getUtil()->getAccessLogActions();
+ if ($reset) {
+ $actions->invalidateCache();
+ //Now unset to force a reload
+ unset(GemsEscort::getInstance()->getUtil()->accessLogActions);
+ $actions = GemsEscort::getInstance()->getUtil()->getAccessLogActions();
+ }
+
+ $this->_actions = $actions->getAllData();
}
}
@@ -176,14 +173,14 @@
{
try {
//When project escort doesn't implement the log interface, we disable logging
- if (!(GemsEscort::getInstance() instanceof Gems_Project_Log_LogRespondentAccessInterface)
+ if (!(GemsEscort::getInstance() instanceof Gems_Project_Log_LogRespondentAccessInterface)
|| (!isset($this->_userInfo->user_id) && $force === false ) ) {
return $this;
}
- /*
+ /*
* For backward compatibility, get the request from the frontcontroller when it
- * is not supplied in the
+ * is not supplied in the
*/
if (!($request instanceof Zend_Controller_Request_Abstract)) {
$request = Zend_Controller_Front::getInstance()->getRequest();
@@ -202,12 +199,12 @@
} else {
$values['glua_remote_ip'] = '';
}
-
- /*
- * Now we know for sure that the action is in the sessionstore, check if we
+
+ /*
+ * Now we know for sure that the action is in the list, check if we
* need to log this action
*/
- if (!($this->_sessionStore->actions[$action]['log']) && !$force) return $this;
+ if (!($this->_actions[$action]['log']) && !$force) return $this;
if (isset($this->_sessionStore->glua_action)) {
//If we don't force a logentry, check if it is a duplicate
@@ -239,5 +236,5 @@
MUtil_Echo::r(GemsEscort::getInstance()->translate->_('Database needs to be updated!'));
return $this;
}
- }
+ }
}
\ No newline at end of file
Modified: trunk/library/classes/Gems/Default/LogMaintenanceAction.php
===================================================================
--- trunk/library/classes/Gems/Default/LogMaintenanceAction.php 2011-12-19 10:21:13 UTC (rev 372)
+++ trunk/library/classes/Gems/Default/LogMaintenanceAction.php 2011-12-19 12:39:13 UTC (rev 373)
@@ -55,9 +55,10 @@
return $model;
}
- public function getAfterSaveRoute($data) {
- Gems_AccessLog::getLog()->loadActions(true);
- return parent::getAfterSaveRoute($data);
+ public function afterSave(array $data, $isNew)
+ {
+ $this->loader->getUtil()->getAccessLogActions()->invalidateCache();
+ return parent::afterSave($data, $isNew);
}
public function getAutoSearchElements(MUtil_Model_ModelAbstract $model, array $data) {
Added: trunk/library/classes/Gems/Util/AccessLogActions.php
===================================================================
--- trunk/library/classes/Gems/Util/AccessLogActions.php (rev 0)
+++ trunk/library/classes/Gems/Util/AccessLogActions.php 2011-12-19 12:39:13 UTC (rev 373)
@@ -0,0 +1,80 @@
+<?php
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package Gems
+ * @subpackage Util
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: ReceptionCode.php 370 2011-12-19 09:27:19Z mennodekker $
+ */
+
+/**
+ * Utility function for caching Gems_AccessLog Actions table.
+ *
+ * @package Gems
+ * @subpackage Util
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class Gems_Util_AccessLogActions extends Gems_Registry_CachedArrayTargetAbstract
+{
+ /**
+ * Variable to add tags to the cache for cleanup.
+ *
+ * @var array
+ */
+ protected $_cacheTags = array('accesslog_actions');
+
+ /**
+ *
+ * @var Zend_Db_Adapter_Abstract
+ */
+ protected $db;
+
+ /**
+ * Returns the complete record.
+ *
+ * @return array
+ */
+ public function getAllData()
+ {
+ return $this->_data;
+ }
+
+ /**
+ * Load the data when the cache is empty.
+ *
+ * @param mixed $id
+ * @return array The array of data values
+ */
+ protected function loadData($id)
+ {
+ return $this->db->fetchAssoc('SELECT glac_name, glac_id_action AS id, glac_log AS log FROM gems__log_actions ORDER BY glac_name');
+ }
+}
Modified: trunk/library/classes/Gems/Util/ReceptionCode.php
===================================================================
--- trunk/library/classes/Gems/Util/ReceptionCode.php 2011-12-19 10:21:13 UTC (rev 372)
+++ trunk/library/classes/Gems/Util/ReceptionCode.php 2011-12-19 12:39:13 UTC (rev 373)
@@ -1,5 +1,4 @@
<?php
-
/**
* Copyright (c) 2011, Erasmus MC
* All rights reserved.
@@ -28,7 +27,7 @@
*
*
* @package Gems
- * @subpackage Ytil
+ * @subpackage Util
* @author Matijs de Jong <mj...@ma...>
* @copyright Copyright (c) 2011 Erasmus MC
* @license New BSD License
Modified: trunk/library/classes/Gems/Util.php
===================================================================
--- trunk/library/classes/Gems/Util.php 2011-12-19 10:21:13 UTC (rev 372)
+++ trunk/library/classes/Gems/Util.php 2011-12-19 12:39:13 UTC (rev 373)
@@ -101,7 +101,18 @@
*/
protected $translated;
+ /**
+ * Returns the AccessLogActions
+ *
+ * @param string $code
+ * @return Gems_Util_AccessLogActions
+ */
+ public function getAccessLogActions()
+ {
+ return $this->_getClass('accessLogActions', null, array('AccessLogActions'));
+ }
+
public function getConsentRejected()
{
if (isset($this->project->concentRejected)) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|