From de6d88cf6f2573e5caac8932dbcfc32fb8ce7389 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 15 May 2005 20:53:32 +0000 Subject: [PATCH] r150: Updated logging system to have one entry per changed field. We then group these entries by `dateline` for display --- docs/schema_changes.sql | 3 ++- includes/functions.php | 17 +++++++++++---- includes/init.php | 2 ++ showhistory.php | 32 +++++++++++++++++++++-------- templates/default/history_bit.tpl | 19 +++-------------- templates/default/history_group.tpl | 16 +++++++++++++++ 6 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 templates/default/history_group.tpl diff --git a/docs/schema_changes.sql b/docs/schema_changes.sql index e54006b..07cd832 100644 --- a/docs/schema_changes.sql +++ b/docs/schema_changes.sql @@ -22,7 +22,8 @@ CREATE TABLE `history` ( `dateline` INT(20) UNSIGNED NOT NULL, `userid` INT(10) UNSIGNED NOT NULL, `language` VARCHAR(255) NOT NULL, - `arguments` MEDIUMTEXT NOT NULL, + `arguments` MEDIUMTEXT NOT NULL, + `field` VARCHAR(255) NOT NULL, `original` MEDIUMTEXT NOT NULL, `changed` MEDIUMTEXT NOT NULL, PRIMARY KEY (`historyid`) diff --git a/includes/functions.php b/includes/functions.php index 5b07d01..7f17836 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -302,17 +302,26 @@ function parse_pcv_select($input, $validate = false) } // ######################### Start log_action ######################## -function log_action($bugid, $language, $arguments, $original = array(), $changed = array()) +function log_action($bugid, $language, $arguments, $field = '', $original = '', $changed = '', $logdiff = true) { global $bugsys; + if ($logdiff) + { + if ($original === $changed) + { + return; + } + } + $bugsys->db->query(" INSERT INTO " . TABLE_PREFIX . "history - (bugid, dateline, userid, language, arguments, original, changed) + (bugid, dateline, userid, language, arguments, field, original, changed) VALUES - (" . intval($bugid) . ", " . time() . ", " . $bugsys->userinfo['userid'] . ", + (" . intval($bugid) . ", " . LOG_TIME . ", " . $bugsys->userinfo['userid'] . ", '" . $bugsys->escape($language) . "', '" . $bugsys->escape(serialize($arguments)) . "', - '" . $bugsys->escape(serialize($original)) . "', '" . $bugsys->escape(serialize($changed)) . "' + '" . $bugsys->escape($field) . "', '" . $bugsys->escape($original) . "', + '" . $bugsys->escape($changed) . "' )" ); } diff --git a/includes/init.php b/includes/init.php index 17864ce..8b1eea0 100755 --- a/includes/init.php +++ b/includes/init.php @@ -48,6 +48,8 @@ define('COOKIE_PREFIX', $cookieprefix); unset($database, $servername, $username, $password, $usepconnect, $tableprefix, $cookieprefix); +define('LOG_TIME', time()); + require_once('./includes/functions_datastore.php'); require_once('./includes/functions.php'); diff --git a/showhistory.php b/showhistory.php index 0af6dfd..b0d0806 100644 --- a/showhistory.php +++ b/showhistory.php @@ -12,6 +12,7 @@ $fetchtemplates = array( 'history', + 'history_group', 'history_bit' ); @@ -26,22 +27,35 @@ if (!$bug) // ################################################################### -$logs = $db->query("SELECT history.*, user.* FROM " . TABLE_PREFIX . "history LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = history.userid) WHERE bugid = $bug[bugid]"); -while ($log = $db->fetch_array($logs)) +$logs_fetch = $db->query(" + SELECT history.*, user.userid, user.email, user.displayname, user.showemail + FROM " . TABLE_PREFIX . "history AS history + LEFT JOIN " . TABLE_PREFIX . "user AS user + ON (user.userid = history.userid) + WHERE bugid = $bug[bugid]" +); +while ($log = $db->fetch_array($logs_fetch)) { $log['formatted'] = call_user_func_array('phrase', array_merge(array($log['language']), unserialize($log['arguments']))); $log['date'] = datelike('standard', $log['dateline']); $log['user'] = construct_user_display($log); - $log['initial'] = unserialize($log['original']); - $log['final'] = unserialize($log['changed']); - - foreach ($log['initial'] AS $key => $value) + $logs["$log[dateline]"]["$log[historyid]"] = $log; + ksort($logs["$log[dateline]"]); +} + +ksort($logs); + +foreach ($logs AS $dateline => $logitems) +{ + $rowspan = 3; + $changes = ''; + foreach ($logitems AS $log) { - $log['changes'] .= "[$key] \"$value\" => \"{$log['final'][$key]}\"\n"; + $rowspan++; + eval('$changes .= "' . $template->fetch('history_bit') . '";'); } - - eval('$history .= "' . $template->fetch('history_bit') . '";'); + eval('$history .= "' . $template->fetch('history_group') . '";'); } eval('$template->flush("' . $template->fetch('history') . '");'); diff --git a/templates/default/history_bit.tpl b/templates/default/history_bit.tpl index 5971fa5..e497075 100644 --- a/templates/default/history_bit.tpl +++ b/templates/default/history_bit.tpl @@ -1,18 +1,5 @@ - - - - - - - - - - - - - + + + -
History Entry (entryid: $log[historyid])$log[user]$log[date]
$log[formatted]
Changes
$log[changes]
$log[field]$log[original]$log[changed]
-
- diff --git a/templates/default/history_group.tpl b/templates/default/history_group.tpl new file mode 100644 index 0000000..9eea1ab --- /dev/null +++ b/templates/default/history_group.tpl @@ -0,0 +1,16 @@ + + + + + + + + $changes + +
+ $log[date] + History Entry (entryid: $log[historyid]) +
$log[user]
+
Changes
$log[formatted]
+
+ -- 2.22.5