From 1c2969e9a5e902541b1778f582c9bd5d7c988e59 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 30 May 2005 05:03:29 +0000 Subject: [PATCH] r212: Fixed a problem where the last post would be off if we did not have permission to see the comment. Quite a big fix. What was done is a `bug.hiddenlastposttime` and a `bug.hiddenlastpostby` were created and these track the last unhidden comment. The originals still track all of them, though. Therefore whenever a comment is modified or added, this record is updated to the most recent unhidden comment. --- docs/schema_changes.sql | 4 +++- docs/update_bug_table_cache.php | 26 +++++++++++++++++++++++--- editcomment.php | 9 +++++++++ index.php | 15 ++++++++++++--- newcomment.php | 9 ++++++++- newreport.php | 11 ++++++++++- 6 files changed, 65 insertions(+), 9 deletions(-) diff --git a/docs/schema_changes.sql b/docs/schema_changes.sql index ab76e7a..7431b3a 100644 --- a/docs/schema_changes.sql +++ b/docs/schema_changes.sql @@ -52,4 +52,6 @@ CREATE TABLE `bugvaluefill` ( ALTER TABLE `bug` ADD `hidden` INT(2) UNSIGNED NOT NULL AFTER `assignedto`; -ALTER TABLE `comment` ADD `hidden` INT(2) UNSIGNED NOT NULL; \ No newline at end of file +ALTER TABLE `comment` ADD `hidden` INT(2) UNSIGNED NOT NULL; + +ALTER TABLE `bug` ADD `hiddenlastposttime` INT(10) UNSIGNED NOT NULL, ADD `hiddenlastpostby` INT(10) UNSIGNED NOT NULL; \ No newline at end of file diff --git a/docs/update_bug_table_cache.php b/docs/update_bug_table_cache.php index 0098748..87a5956 100644 --- a/docs/update_bug_table_cache.php +++ b/docs/update_bug_table_cache.php @@ -3,20 +3,40 @@ chdir('./../'); require_once('./global.php'); -$comments = $db->query("SELECT * FROM comment ORDER BY bugid, dateline ASC"); +$comments = $db->query("SELECT * FROM " . TABLE_PREFIX . "comment ORDER BY bugid, dateline ASC"); while ($comment = $db->fetch_array($comments)) { if (!isset($replace["$comment[bugid]"])) { - $replace["$comment[bugid]"] = array('initialreport' => $comment['commentid'], 'dateline' => $comment['dateline'], 'lastposttime' => $comment['dateline'], 'lastpostby' => $comment['userid']); + $replace["$comment[bugid]"] = array( + 'initialreport' => $comment['commentid'], + 'dateline' => $comment['dateline'], + 'lastposttime' => $comment['dateline'], + 'lastpostby' => $comment['userid'] + ); } + if (!$comment['hidden'] AND !isset($replace["$comment[bugid]"]['hiddenlastposttime'])) + { + $replace["$comment[bugid]"]['hiddenlastposttime'] = $comment['dateline']; + $replace["$comment[bugid]"]['hiddenlastpostby'] = $comment['userid']; + } + $replace["$comment[bugid]"]['lastposttime'] = $comment['dateline']; } foreach ($replace AS $bugid => $newfields) { - $db->query("UPDATE bug SET initialreport = $newfields[initialreport], dateline = $newfields[dateline], lastposttime = $newfields[lastposttime], lastpostby = $newfields[lastpostby] WHERE bugid = $bugid"); + $db->query(" + UPDATE " . TABLE_PREFIX . "bug + SET initialreport = $newfields[initialreport], + dateline = $newfields[dateline], + lastposttime = $newfields[lastposttime], + lastpostby = $newfields[lastpostby], + hiddenlastposttime = $newfields[hiddenlastposttime], + hiddenlastpostby = $newfields[hiddenlastpostby] + WHERE bugid = $bugid" + ); echo "

Updated $bugid

"; } diff --git a/editcomment.php b/editcomment.php index 1f3e767..07ebe19 100644 --- a/editcomment.php +++ b/editcomment.php @@ -81,6 +81,15 @@ if ($_POST['do'] == 'update') $log->log(); $log->log($log->diff('hidden', $comment['hidden'], intval($bugsys->in['hidden']))); + $lastgood = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "comment WHERE bugid = $bug[bugid] AND !hidden ORDER BY dateline DESC"); + print_r($lastgood); + $db->query(" + UPDATE " . TABLE_PREFIX . "bug + SET hiddenlastposttime = $lastgood[dateline], + hiddenlastpostby = $lastgood[userid] + WHERE bugid = $bug[bugid]" + ); + $message->redirect('comment saved', "showreport.php?bugid=$bug[bugid]"); } diff --git a/index.php b/index.php index bbb4c4c..812ed17 100644 --- a/index.php +++ b/index.php @@ -27,14 +27,16 @@ if (!can_perform('canviewbugs')) // #*# pagination needs to be done here $bugs_fetch = $db->query(" - SELECT bug.*, user1.displayname AS firstreport, user2.displayname AS lastpost + SELECT bug.*, user1.displayname AS firstreport, user2.displayname AS lastpost, user3.displayname AS hiddenlastpost FROM " . TABLE_PREFIX . "bug AS bug LEFT JOIN user AS user1 ON (bug.userid = user1.userid) LEFT JOIN user AS user2 - ON (bug.lastpostby = user2.userid)" . ((!can_perform('canviewhidden')) ? " + ON (bug.lastpostby = user2.userid) + LEFT JOIN user AS user3 + ON (bug.hiddenlastpostby = user3.userid)" . ((!can_perform('canviewhidden')) ? " WHERE !hidden" : "") . " - ORDER BY bug.lastposttime DESC" + ORDER BY bug." . ((can_perform('canviewhidden')) ? "lastposttime" : "hiddenlastposttime") . " DESC" ); while ($bug = $db->fetch_array($bugs_fetch)) @@ -44,7 +46,14 @@ while ($bug = $db->fetch_array($bugs_fetch)) $bug['version'] = $bugsys->datastore['version']["$bug[versionid]"]['version']; $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status']; $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution']; + + $bug['hiddendisplay'] = ((!can_perform('canviewhidden') AND $bug['hiddenlastposttime']) ? true : false); + + $bug['lastposttime'] = (($bug['hiddendisplay']) ? $bug['hiddenlastposttime'] : $bug['lastposttime']); + $bug['lastpost'] = (($bug['hiddendisplay']) ? $bug['hiddenlastpost'] : $bug['lastpost']); + $bug['lastpostinfo'] = datelike('standard', $bug['lastposttime']) . ' by ' . $bug['lastpost']; + eval('$bugs .= "' . $template->fetch('trackerhome_bits') . '";'); } diff --git a/newcomment.php b/newcomment.php index 85b6e32..055cd81 100644 --- a/newcomment.php +++ b/newcomment.php @@ -53,7 +53,14 @@ if ($_POST['do'] == 'insert') $commentid = $db->insert_id(); - $db->query("UPDATE " . TABLE_PREFIX . "bug SET lastposttime = $time, lastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = " . intval($bugsys->in['bugid'])); + $db->query(" + UPDATE " . TABLE_PREFIX . "bug + SET lastposttime = $time, + lastpostby = " . $bugsys->userinfo['userid'] . ", + hiddenlastposttime = $time, + hiddenlastpostby = " . $bugsys->userinfo['userid'] . " + WHERE bugid = " . intval($bugsys->in['bugid']) + ); // setup logging require_once('./includes/class_history.php'); diff --git a/newreport.php b/newreport.php index 3c64315..cdb56f8 100755 --- a/newreport.php +++ b/newreport.php @@ -127,7 +127,16 @@ if ($_POST['do'] == 'insert') $initialreport = $db->insert_id(); - $db->query("UPDATE " . TABLE_PREFIX . "bug SET dateline = $time, initialreport = $initialreport, lastposttime = $time, lastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = $bugid"); + $db->query(" + UPDATE " . TABLE_PREFIX . "bug + SET dateline = $time, + initialreport = $initialreport, + lastposttime = $time, + lastpostby = " . $bugsys->userinfo['userid'] . ", + hiddenlastposttime = $time, + hiddenlastpostby = " . $bugsys->userinfo['userid'] . " + WHERE bugid = $bugid" + ); $message->redirect('bug is done!', "showreport.php?bugid=$bugid"); } -- 2.22.5