From 3cbf1d24fbfb5e84725aadc278fbb93cad717bdd Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 20 Feb 2014 12:47:06 +0000 Subject: [PATCH] * eTemplate/all apps: limit displayed history to 500 entries --- etemplate/inc/class.historylog_widget.inc.php | 7 +++- phpgwapi/inc/class.historylog.inc.php | 33 ++++++++----------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/etemplate/inc/class.historylog_widget.inc.php b/etemplate/inc/class.historylog_widget.inc.php index b20781f26b..3bde61bf68 100644 --- a/etemplate/inc/class.historylog_widget.inc.php +++ b/etemplate/inc/class.historylog_widget.inc.php @@ -32,6 +32,11 @@ */ class historylog_widget { + /** + * Maximum number of log entries to display + */ + const MAX_DISPLAY = 500; + /** * @var array exported methods of this class */ @@ -161,7 +166,7 @@ class historylog_widget $historylog = new historylog($app); if (!$id || method_exists($historylog,'search')) { - $value = $id ? $historylog->search($filter ? array('history_record_id'=>$id) + $filter : $id) : false; + $value = $id ? $historylog->search($filter ? array('history_record_id'=>$id) + $filter : $id, 'history_id', 'DESC', self::MAX_DISPLAY) : false; } unset($historylog); diff --git a/phpgwapi/inc/class.historylog.inc.php b/phpgwapi/inc/class.historylog.inc.php index 425a1cb69c..2c4183cecf 100644 --- a/phpgwapi/inc/class.historylog.inc.php +++ b/phpgwapi/inc/class.historylog.inc.php @@ -2,11 +2,6 @@ /** * API - Record history logging * - * This class extends a backend class (at them moment SQL or LDAP) and implements some - * caching on to top of the backend functions. The cache is share for all instances of - * the accounts class and for LDAP it is persistent through the whole session, for SQL - * it's only on a per request basis. - * * @link http://www.egroupware.org * @author Joseph Engo * @copyright 2001 by Joseph Engo @@ -147,21 +142,22 @@ class historylog * * @param array/int $filter array with filters, or int record_id * @param string $order='history_id' sorting after history_id is identical to history_timestamp - * @param string $sort='ASC' + * @param string $sort='DESC' + * @param int $limit=null only return this many entries * @return array of arrays with keys id, record_id, appname, owner (account_id), status, new_value, old_value, * timestamp (Y-m-d H:i:s in servertime), user_ts (timestamp in user-time) */ - function search($filter,$order='history_id',$sort='DESC') + function search($filter,$order='history_id',$sort='DESC',$limit=null) { if (!is_array($filter)) $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array(); - if (!$_orderby || !preg_match('/^[a-z0-9_]+$/i',$_orderby) || !preg_match('/^(asc|desc)?$/i',$sort)) + if (!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort)) { $orderby = 'ORDER BY history_id DESC'; } else { - $orderby = "ORDER BY $_orderby $sort"; + $orderby = "ORDER BY $order $sort"; } foreach($filter as $col => $value) { @@ -177,7 +173,8 @@ class historylog if (!$filter['history_record_id']) return array(); $rows = array(); - foreach($this->db->select(self::TABLE,'*',$filter,__LINE__,__FILE__,false,$orderby) as $row) + foreach($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__, + isset($limit) ? 0 : false, $orderby, 'phpgwapi', $limit) as $row) { $row['user_ts'] = $this->db->from_timestamp($row['history_timestamp']) + 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset']; $rows[] = egw_db::strip_array_keys($row,'history_'); @@ -257,9 +254,9 @@ class historylog $rows[] = egw_db::strip_array_keys($row,'history_'); } if ($mysql_calc_rows) - { - $total = $GLOBALS['egw']->db->query('SELECT FOUND_ROWS()')->fetchColumn(); - } + { + $total = $GLOBALS['egw']->db->query('SELECT FOUND_ROWS()')->fetchColumn(); + } return $total; } @@ -378,13 +375,11 @@ class historylog if ($this->alternate_handlers[$value['status']]) { - eval('\$s = ' . $this->alternate_handlers[$value['status']] . '(' . $value['new_value'] . ');'); - $this->template->set_var('row_new_value',$s); - unset($s); + $this->template->set_var('row_new_value', + call_user_func($this->alternate_handlers[$value['status']], array($value['new_value']))); - eval('\$s = ' . $this->alternate_handlers[$value['status']] . '(' . $value['old_value'] . ');'); - $this->template->set_var('row_old_value',$s); - unset($s); + $this->template->set_var('row_old_value', + call_user_func($this->alternate_handlers[$value['status']], array($value['old_value']))); } else {