From 3e837377c50126128bc3065464831130e010b208 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 19 May 2005 03:39:15 +0000 Subject: [PATCH] r159: - Finished all of that logging stuff - We now have a class_history.php file that allows us to handle easy diffs and logging - Removed log_action() [includes/functions.php] because this is much better - Updated all files to this new system --- attachment.php | 31 ++++++++++--- docs/roadmap.txt | 1 - docs/todo.txt | 1 - editcomment.php | 8 +++- editreport.php | 19 ++++++-- includes/class_history.php | 93 ++++++++++++++++++++++++++++++++++++++ includes/functions.php | 33 -------------- newcomment.php | 10 +++- 8 files changed, 149 insertions(+), 47 deletions(-) create mode 100644 includes/class_history.php diff --git a/attachment.php b/attachment.php index 16b260e..d4bda84 100755 --- a/attachment.php +++ b/attachment.php @@ -34,6 +34,11 @@ if (!$bug) exit; } +// setup logging +require_once('./includes/class_history.php'); +$log = new History(); +$log->bugid = $bug['bugid']; + // ################################################################### if ($_REQUEST['do'] == 'kill') @@ -46,7 +51,10 @@ 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']), true); + $log->language = 'log_kill_attachment'; + $log->arguments = array($attachment['attachmentid']); + $log->allowempty = true; + $log->log(); echo "attachment removed"; } @@ -120,7 +128,10 @@ if ($_POST['do'] == 'insert') ); $attachmentid = $db->insert_id(); - log_action($bug['bugid'], 'log_new_attachment', array($FILE['name'], $attachmentid), true); + $log->language = 'log_new_attachment'; + $log->arguments = array($FILE['name'], $attachmentid); + $log->allowempty = true; + $log->log(); // mark obsoletes $obsoletes = $_POST['obsoletes']; @@ -128,7 +139,10 @@ if ($_POST['do'] == 'insert') { 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)), false, 'obsoleted attachments', '', implode(', ', $obsoletes)); + + $log->language = 'log_mark_obsoletes'; + $log->arguments = array($attachmentid, $FILE['name'], implode(', ', $obsoletes)); + $log->log($log->diff('obsoleted attachments', '', implode(', ', $obsoletes))); } // handle comment stuff @@ -153,7 +167,10 @@ if ($_POST['do'] == 'insert') $commentid = $db->insert_id(); - log_action($bug['bugid'], 'log_new_attachment_comment', array($attachmentid, $commentid), true); + $log->language = 'log_new_attachment_comment'; + $log->arguments = array($attachmentid, $commentid); + $log->allowempty = true; + $log->log(); } // update the last post data @@ -210,8 +227,10 @@ if ($_POST['do'] == 'update') $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']), false, 'description', $diff[0]['description'], $diff[1]['description']); - log_action($bug['bugid'], 'log_update_attachment', array($attachment['attachmentid']), false, 'obsolete', $diff[0]['obsolete'], $diff[1]['obsolete']); + $log->language = 'log_update_attachment'; + $log->arguments = array($attachment['attachmentid']); + $log->log($log->diff('description', $diff[0]['description'], $diff[1]['description'])); + $log->log($log->diff('obsolete', $diff[0]['obsolete'], $diff[1]['obsolete'])); echo "attachment updated"; } diff --git a/docs/roadmap.txt b/docs/roadmap.txt index a1c88ef..f8ad35c 100755 --- a/docs/roadmap.txt +++ b/docs/roadmap.txt @@ -11,7 +11,6 @@ BUGTRACK 1.0 - Error message reporting - Admin auto-actions (see supplementary documentation) - Custom bug fields -- Bug statistics/logging ---------------------------------------- BETA 2 diff --git a/docs/todo.txt b/docs/todo.txt index 9b09087..4e857e2 100755 --- a/docs/todo.txt +++ b/docs/todo.txt @@ -33,7 +33,6 @@ BUGTRACK 1.0 - Custom bug fields - Default templates in the description field - Help bubbles detailing each field -- Bug logging ############################################################################### BUGTRACK 1.1 diff --git a/editcomment.php b/editcomment.php index b7ae9f3..01138b3 100644 --- a/editcomment.php +++ b/editcomment.php @@ -84,7 +84,13 @@ if ($_POST['do'] == 'update') WHERE commentid = $comment[commentid]" ); - log_action($bug['bugid'], 'log_update_comment', array($comment['commentid'])); + // setup logging + require_once('./includes/class_history.php'); + $log = new History(); + $log->bugid = $bug['bugid']; + $log->language = 'log_update_comment'; + $log->arguments = array($comment['commentid']); + $log->log(); echo "comment saved"; } diff --git a/editreport.php b/editreport.php index c2e2f5e..bb6bcea 100644 --- a/editreport.php +++ b/editreport.php @@ -37,6 +37,11 @@ if (!(((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['u exit; } +// setup logging +require_once('./includes/class_history.php'); +$log = new History(); +$log->bugid = $bug['bugid']; + // ################################################################### if (empty($_REQUEST['do'])) @@ -108,10 +113,17 @@ if ($_POST['do'] == 'update') 'componentid' => 'product' ); + $log->language = 'log_update_bug'; + foreach ($diff AS $num => $diffs) { foreach ($diffs AS $key => $value) { + if (!isset($lookupindex["$key"])) + { + continue; + } + $ref = $lookupindex["$key"]; $temp =& $bugsys->datastore["$ref"]["$value"]; $thevalue = $temp["$ref"]; @@ -129,12 +141,13 @@ if ($_POST['do'] == 'update') } $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : ''); - - log_action($bug['bugid'], 'log_update_bug', array(), false, $key, $diff["$num"]["$key"], $diff["$num"]["$key"]); } } - //log_action($bug['bugid'], 'log_update_bug', array(), $diff[0], $diff[1]); + foreach ($diff[1] AS $key => $value) + { + $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"])); + } if (!$bugsys->in['firstcomment']) { diff --git a/includes/class_history.php b/includes/class_history.php new file mode 100644 index 0000000..0fa82e3 --- /dev/null +++ b/includes/class_history.php @@ -0,0 +1,93 @@ +bugid = intval($this->bugid); + $this->language = $bugsys->escape($this->language); + $arguments = $bugsys->escape(serialize($this->arguments)); + + if ($diffdata == -1) + { + return; + } + + if (!$diffdata) + { + $bugsys->db->query(" + INSERT INTO " . TABLE_PREFIX . "history + (bugid, dateline, userid, language, arguments) + VALUES + (" . $this->bugid . ", " . LOG_TIME . ", " . $bugsys->userinfo['userid'] . ", + '" . $this->language . "', '" . $arguments . "' + )" + ); + } + else + { + $bugsys->db->query(" + INSERT INTO " . TABLE_PREFIX . "history + (bugid, dateline, userid, language, arguments, field, original, changed) + VALUES + (" . $this->bugid . ", " . LOG_TIME . ", " . $bugsys->userinfo['userid'] . ", + '" . $this->language . "', '" . $arguments . "', + '" . $bugsys->escape($diffdata['field']) . "', '" . $bugsys->escape($diffdata['initial']) . "', + '" . $bugsys->escape($diffdata['final']) . "' + )" + ); + } + } + + // ------------------------------------------------------------------- + // -- Do a diff + // ------------------------------------------------------------------- + function diff($field, $initial, $final) + { + if (empty($initial) AND empty($final)) + { + if (!$this->allowempty) + { + return -1; + } + } + + if (!$this->allowempty) + { + if ($initial === $final) + { + return -1; + } + } + + return array('field' => $field, 'initial' => $initial, 'final' => $final); + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/includes/functions.php b/includes/functions.php index 1c0b8c7..e4a21ab 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -301,39 +301,6 @@ function parse_pcv_select($input, $validate = false) } } -// ######################### Start log_action ######################## -function log_action($bugid, $language, $arguments, $ignoreblanks = false, $field = '', $original = '', $changed = '', $dodiff = true) -{ - global $bugsys; - - if (empty($original) AND empty($changed)) - { - if (!$ignoreblanks) - { - return; - } - } - - if ($dodiff AND !$ignoreblanks) - { - if ($original === $changed) - { - return; - } - } - - $bugsys->db->query(" - INSERT INTO " . TABLE_PREFIX . "history - (bugid, dateline, userid, language, arguments, field, original, changed) - VALUES - (" . intval($bugid) . ", " . LOG_TIME . ", " . $bugsys->userinfo['userid'] . ", - '" . $bugsys->escape($language) . "', '" . $bugsys->escape(serialize($arguments)) . "', - '" . $bugsys->escape($field) . "', '" . $bugsys->escape($original) . "', - '" . $bugsys->escape($changed) . "' - )" - ); -} - /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/newcomment.php b/newcomment.php index d786336..e69a9de 100644 --- a/newcomment.php +++ b/newcomment.php @@ -56,8 +56,14 @@ if ($_POST['do'] == 'insert') $db->query("UPDATE " . TABLE_PREFIX . "bug SET lastposttime = $time, lastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = " . intval($bugsys->in['bugid'])); - log_action(intval($bugsys->in['bugid']), 'log_new_comment', array($commentid)); - + // setup logging + require_once('./includes/class_history.php'); + $log = new History(); + $log->bugid = $bugsys->in['bugid']; + $log->language = 'log_new_comment'; + $log->arguments = array($commentid); + $log->log(); + echo "in['bugid']) . "\">comment inserted"; } -- 2.22.5