r150: Updated logging system to have one entry per changed field. We then group these...
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 15 May 2005 20:53:32 +0000 (20:53 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 15 May 2005 20:53:32 +0000 (20:53 +0000)
docs/schema_changes.sql
includes/functions.php
includes/init.php
showhistory.php
templates/default/history_bit.tpl
templates/default/history_group.tpl [new file with mode: 0644]

index e54006b097f09b74c605e97b05df878128cc52ed..07cd8324667059183b827a4242db3d705eb7cd07 100644 (file)
@@ -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`)
index 5b07d01e65b5e3f424957e4e7df7be3df642ff90..7f17836b5e844f4fd8bbd3d0e7b80f0e405b5267 100755 (executable)
@@ -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) . "'
                )"
        );
 }
index 17864cee6b9f5f5025a81907d2a6cafb04665a3c..8b1eea0e1e2059e25f2f5f631ede68f8d3ad2905 100755 (executable)
@@ -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');
 
index 0af6dfdf73959ee81dfb381504275d35320138f9..b0d080621e92d52f29b3bd48d67a9a694a93c7a6 100644 (file)
@@ -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') . '");');
index 5971fa560e4b1562cc1c83810e1a90f7831f896f..e4970757d09afc8f59b28bf168137322c121dd97 100644 (file)
@@ -1,18 +1,5 @@
-<table border="1" cellspacing="2" cellpadding="4" width="100%">
-<tr style="background-color: #EEEEEE">
-       <td width="45%">History Entry (entryid: $log[historyid])</td>
-       <td>$log[user]</td>
-       <td align="right">$log[date]</td>
-</tr>
-<tr>
-       <td rowspan="3" valign="top">$log[formatted]</td>
-</tr>
-<tr>
-       <td colspan="2"><strong>Changes</strong></td>
-</tr>
 <tr>
-       <td colspan="2"><pre>$log[changes]</pre></td>
+       <td width="20%"><em>$log[field]</em></td>
+       <td width="15%">$log[original]</td>
+       <td width="15%">$log[changed]</td>
 </tr>
-</table>
-<br />
-
diff --git a/templates/default/history_group.tpl b/templates/default/history_group.tpl
new file mode 100644 (file)
index 0000000..9eea1ab
--- /dev/null
@@ -0,0 +1,16 @@
+<table border="1" cellspacing="2" cellpadding="4" width="100%">
+<tr style="background-color: #EEEEEE">
+       <td width="50%">
+               <strong><span style="float: right">$log[date]</span>
+               History Entry (entryid: $log[historyid])</strong>
+               <div>$log[user]</div>
+       </td>
+       <td colspan="3"><strong>Changes</strong></td>
+</tr>
+<tr>
+       <td rowspan="$rowspan" valign="top">$log[formatted]</td>
+       $changes
+</tr>
+</table>
+<br />
+