From b6229aba598f3a7927993aa857e05a2c75a617c6 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 10 May 2006 02:21:50 +0000 Subject: [PATCH] r811: More logging... man this must be bad for the environment. End deforestation now! --- editreport.php | 85 +++++--------------------------------- includes/class_logging.php | 49 ++++++++++------------ 2 files changed, 33 insertions(+), 101 deletions(-) diff --git a/editreport.php b/editreport.php index 2c1726a..daaaf78 100644 --- a/editreport.php +++ b/editreport.php @@ -147,7 +147,12 @@ if ($_POST['do'] == 'update') // do update stuff $pcv = parse_pcv_select($bugsys->in['pcv_select'], true); - $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"); + $nocustomfields = true; + if ($fields = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]")) + { + $nocustomfields = false; + $log2->add_data(true, $fields, array('bugid'), true, 'custom', 'custom'); + } // ------------------------------------------------------------------- // start updates @@ -178,65 +183,14 @@ if ($_POST['do'] == 'update') } $log2->add_data(false, $bugapi->values, $bugfields); - print_r($log2); exit; - $bugapi->update(); + + //$bugapi->update(); // ------------------------------------------------------------------- // do diff history - $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"); - - $diff[0] = array_diff_assoc($bugapi->objdata, $bugapi->values); - $diff[1] = array_diff_assoc($bugapi->values, $bugapi->objdata); - - $lookupindex = array( - 'status' => 'status', - 'severity' => 'severity', - 'priority' => 'priority', - 'versionid' => 'version', - 'assignedto' => 'assignto', - 'resolution' => 'resolution', - 'productid' => 'product', - 'componentid' => 'product' - ); - - 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"]; - $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')'; - - if ($key == 'assignedto') - { - $thevalue = (($temp['userid']) ? construct_user_display($temp) : ''); - $idbit = ''; - } - else if ($key == 'productid' OR $key == 'componentid') - { - $ref = 'product'; - $thevalue = $temp['title']; - } - - $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : ''); - } - } - - foreach ($diff[1] AS $key => $value) - { - $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"])); - } - - $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]); - $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]); + $hist[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"); if ($noinitialcustom === false) { @@ -248,26 +202,9 @@ if ($_POST['do'] == 'update') } } - foreach ($diff2[1] AS $key => $value) - { - if (in_array($key, $boxlist) AND $canallowempty) - { - $log->allowempty = true; - } - else - { - $log->allowempty = false; - } - - if ($key == 'bugid') - { - continue; - } - - $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"])); - } + $log2->add_data(false, $hist[1], array('bugid'), true, 'custom', 'custom'); - $log->allowempty = false; + print_r($log2); exit; $message->redirect($lang->string('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]"); } diff --git a/includes/class_logging.php b/includes/class_logging.php index 66e3949..7cc4932 100644 --- a/includes/class_logging.php +++ b/includes/class_logging.php @@ -19,6 +19,13 @@ || ################################################################### \*=====================================================================*/ +/* +A USEFUL QUERY: + +DELETE FROM history WHERE field IN ('lastposttime', 'lastpostby', 'hiddenlastposttime', 'hiddenlastpostby') + +*/ + /** * Bug Change Logging * @@ -78,46 +85,34 @@ class Logging * @param bool TRUE for original, FALSE for modified * @param array Data array * @param array List of fields in the data array to add; in format of array('field name' => 'display name', 'display name 2', 'display name 3') + * @param bool If TRUE, then the list of fields is used to exclude, not include * @param string Element to add to * @param string Field prefix */ - function add_data($orig, $data, $fields, $element = '', $prefix = '') + function add_data($orig, $data, $fields, $exclude = false, $element = '', $prefix = '') { $array = ($orig ? 'original' : 'modified'); - $prefix .= ($prefix != '' ? '.' : ''); + $prefix .= '.'; - foreach ($fields AS $fname => $fdisplay) + if ($exclude == false) { - if (is_numeric($fname)) + foreach ($fields AS $fname => $fdisplay) { - $fname = $fdisplay; + if (is_numeric($fname)) + { + $fname = $fdisplay; + } + + $this->{$array}["$element"]["$prefix$fdisplay"] = array('name' => $fname, 'value' => $data["$fname"]); } - - $this->{$array}["$element"]["$prefix$fdisplay"] = $data["$fname"]; } - } - - // ################################################################### - /** - * Adds strings to the IDs so that it's human-readable and that's - * stored in the database so that if whatever value is deleted, - * the text still exists in the end. This takes the element and a list - * of fields to prossess in order to work. - * - * @access public - * - * @param string Element name - * @param array List of fields to use - */ - function process_fields($element, $fields) - { - foreach (array('original', 'modified') AS $array) + else { - foreach ($this->{$array}["$element"] AS $display => $fname) + foreach ($data AS $fname => $value) { - if (in_array($fname, $fields)) + if (!in_array($fname, $fields)) { - + $this->{$array}["$element"]["$prefix$fname"] = array('name' => $fname, 'value' => $value); } } } -- 2.22.5