r145: - Added logging mechanism to files
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 15 May 2005 07:06:46 +0000 (07:06 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 15 May 2005 07:06:46 +0000 (07:06 +0000)
- Added before and after changes so we can array_diff_assoc() them to see individual changes
- Updated history viewer so we can see changes

attachment.php
docs/schema_changes.sql
editcomment.php
editreport.php
includes/functions.php
showhistory.php
templates/default/history_bit.tpl

index adea2170318bd4ce1c8ee6a8c7975c3e8bd24a86..666f543917b6b2223e22e1db47d6c3ea7d6cfcff 100755 (executable)
@@ -46,6 +46,8 @@ if ($_REQUEST['do'] == 'kill')
        
        $db->query("DELETE FROM " . TABLE_PREFIX . "attachment WHERE attachmentid = $attachment[attachmentid]");
        
+       log_action($bug['bugid'], 'log_kill_attachment', array($attachment['attachmentid']));
+       
        echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment removed</a>";
 }
 
@@ -117,11 +119,16 @@ if ($_POST['do'] == 'insert')
                )"
        );
        
+       $attachmentid = $db->insert_id();
+       log_action($bug['bugid'], 'log_new_attachment', array($FILE['name'], $attachmentid));
+       
        // mark obsoletes
        $obsoletes = $_POST['obsoletes'];
        array_walk($obsoletes, 'intval');
        $db->query("UPDATE " . TABLE_PREFIX . "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
        
+       log_action($bug['bugid'], 'log_mark_obsoletes', array($attachmentid, $FILE['name'], implode(', ', $obsoletes)));
+       
        // handle comment stuff
        if (can_perform('canpostcomments') AND trim($bugsys->in['comment']))
        {
@@ -141,13 +148,16 @@ if ($_POST['do'] == 'insert')
                                '" . nl2br($bugsys->in['comment_parsed']) . "'
                        )"
                );
+               
+               $commentid = $db->insert_id();
+               
+               log_action($bug['bugid'], 'log_new_attachment_comment', array($attachmentid, $commentid));
        }
        
        // update the last post data
        $db->query("UPDATE " . TABLE_PREFIX . "bug SET lastposttime = $time, lastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = $bug[bugid]");
        
        echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment added</a>";
-
 }
 
 // ###################################################################
@@ -193,6 +203,13 @@ if ($_POST['do'] == 'update')
                WHERE attachmentid = " . intval($bugsys->in['attachmentid'])
        );
        
+       $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "attachment WHERE attachmentid = $attachment[attachmentid]");
+       
+       $diff[0] = array_diff_assoc($attachment, $hist[1]);
+       $diff[1] = array_diff_assoc($hist[1], $attachment);
+       
+       log_action($bug['bugid'], 'log_update_attachment', array($attachment['attachmentid'], intval($bugsys->in['obsolete'])));
+       
        echo "<a href=\"showreport.php?bugid=$bug[bugid]\">attachment updated</a>";
 }
 
index 7ab64075fc545ba78524e970b39fbb2954a325f0..e54006b097f09b74c605e97b05df878128cc52ed 100644 (file)
@@ -23,5 +23,7 @@ CREATE TABLE `history` (
   `userid` INT(10) UNSIGNED NOT NULL, 
   `language` VARCHAR(255) NOT NULL, 
   `arguments` MEDIUMTEXT NOT NULL,
+  `original` MEDIUMTEXT NOT NULL, 
+  `changed` MEDIUMTEXT NOT NULL, 
   PRIMARY KEY (`historyid`)
 );
\ No newline at end of file
index e42cd47a007aabc3d550e385b0bc50f56c12ffa5..b7ae9f3f822008d7ff81d3c73bd538c5e20eed82 100644 (file)
@@ -84,6 +84,8 @@ if ($_POST['do'] == 'update')
                WHERE commentid = $comment[commentid]"
        );
        
+       log_action($bug['bugid'], 'log_update_comment', array($comment['commentid']));
+       
        echo "<a href=\"showreport.php?bugid=$bug[bugid]\">comment saved</a>";
 }
 
index e9fc9dfe8151397517eec1bfe9901e1252f8e830..f0eb109f676322e632c0b578888c1e1dc48016b5 100644 (file)
@@ -76,6 +76,8 @@ if ($_POST['do'] == 'update')
                exit;
        }
        
+       $hist[0] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
+       
        $db->query("
                UPDATE " . TABLE_PREFIX . "bug
                SET summary = '" . $bugsys->in['summary'] . "',
@@ -89,6 +91,13 @@ if ($_POST['do'] == 'update')
                WHERE bugid = $bug[bugid]"
        );
        
+       $hist[1] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]");
+       
+       $diff[0] = array_diff_assoc($hist[0], $hist[1]);
+       $diff[1] = array_diff_assoc($hist[1], $hist[0]);
+       
+       log_action($bug['bugid'], 'log_update_bug', array(), $diff[0], $diff[1]);
+       
        if (!$bugsys->in['firstcomment'])
        {
                echo 'you need to enter some text in the first comment';
index 0e42cb179c75de50da79836b81ddc0e0f3d8d84a..5b07d01e65b5e3f424957e4e7df7be3df642ff90 100755 (executable)
@@ -302,16 +302,17 @@ function parse_pcv_select($input, $validate = false)
 }
 
 // ######################### Start log_action ########################
-function log_action($bugid, $language, $arguments)
+function log_action($bugid, $language, $arguments, $original = array(), $changed = array())
 {
        global $bugsys;
        
        $bugsys->db->query("
                INSERT INTO " . TABLE_PREFIX . "history
-                       (bugid, dateline, userid, language, arguments)
+                       (bugid, dateline, userid, language, arguments, original, changed)
                VALUES
                        (" . intval($bugid) . ", " . time() . ", " . $bugsys->userinfo['userid'] . ", 
-                       '" . $bugsys->escape($language) . "', '" . $bugsys->escape(serialize($arguments)) . "'
+                       '" . $bugsys->escape($language) . "', '" . $bugsys->escape(serialize($arguments)) . "',
+                       '" . $bugsys->escape(serialize($original)) . "', '" . $bugsys->escape(serialize($changed)) . "'
                )"
        );
 }
index 65514d219875966b5f7f3bf834b7639b9d938ce7..0af6dfdf73959ee81dfb381504275d35320138f9 100644 (file)
@@ -32,6 +32,15 @@ while ($log = $db->fetch_array($logs))
        $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)
+       {
+               $log['changes'] .= "[$key] \"$value\"  =>  \"{$log['final'][$key]}\"\n";
+       }
+       
        eval('$history .= "' . $template->fetch('history_bit') . '";');
 }
 
index 88ebd6b2c71b92e51e8cf0823b4d4c673217fc67..5971fa560e4b1562cc1c83810e1a90f7831f896f 100644 (file)
@@ -1,11 +1,18 @@
 <table border="1" cellspacing="2" cellpadding="4" width="100%">
 <tr style="background-color: #EEEEEE">
-       <td>History Entry (entryid: $log[historyid])</td>
+       <td width="45%">History Entry (entryid: $log[historyid])</td>
        <td>$log[user]</td>
        <td align="right">$log[date]</td>
 </tr>
 <tr>
-       <td colspan="3">$log[formatted]</td>
+       <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>
 </tr>
 </table>
 <br />
+