From 98ab7d52c5745c6637e46863d1c550c6ddb34c11 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 15 May 2005 07:06:46 +0000 Subject: [PATCH] r145: - Added logging mechanism to files - 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 | 19 ++++++++++++++++++- docs/schema_changes.sql | 2 ++ editcomment.php | 2 ++ editreport.php | 9 +++++++++ includes/functions.php | 7 ++++--- showhistory.php | 9 +++++++++ templates/default/history_bit.tpl | 11 +++++++++-- 7 files changed, 53 insertions(+), 6 deletions(-) diff --git a/attachment.php b/attachment.php index adea217..666f543 100755 --- a/attachment.php +++ b/attachment.php @@ -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 "attachment removed"; } @@ -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 "attachment added"; - } // ################################################################### @@ -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 "attachment updated"; } diff --git a/docs/schema_changes.sql b/docs/schema_changes.sql index 7ab6407..e54006b 100644 --- a/docs/schema_changes.sql +++ b/docs/schema_changes.sql @@ -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 diff --git a/editcomment.php b/editcomment.php index e42cd47..b7ae9f3 100644 --- a/editcomment.php +++ b/editcomment.php @@ -84,6 +84,8 @@ if ($_POST['do'] == 'update') WHERE commentid = $comment[commentid]" ); + log_action($bug['bugid'], 'log_update_comment', array($comment['commentid'])); + echo "comment saved"; } diff --git a/editreport.php b/editreport.php index e9fc9df..f0eb109 100644 --- a/editreport.php +++ b/editreport.php @@ -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'; diff --git a/includes/functions.php b/includes/functions.php index 0e42cb1..5b07d01 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -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)) . "' )" ); } diff --git a/showhistory.php b/showhistory.php index 65514d2..0af6dfd 100644 --- a/showhistory.php +++ b/showhistory.php @@ -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') . '";'); } diff --git a/templates/default/history_bit.tpl b/templates/default/history_bit.tpl index 88ebd6b..5971fa5 100644 --- a/templates/default/history_bit.tpl +++ b/templates/default/history_bit.tpl @@ -1,11 +1,18 @@ - + - + + + + + + +
History Entry (entryid: $log[historyid])History Entry (entryid: $log[historyid]) $log[user] $log[date]
$log[formatted]$log[formatted]
Changes
$log[changes]

+ -- 2.22.5