From: <ir...@us...> - 2012-10-15 09:27:21
|
Revision: 10215 http://sourceforge.net/p/xoops/svn/10215 Author: irmtfan Date: 2012-10-15 09:27:16 +0000 (Mon, 15 Oct 2012) Log Message: ----------- bug fix: read_mode = 2 (DB) in viewpost.php?status=new AND viewforum.php?forum=FFF&status=unread and list.topic.php?status=unread Modified Paths: -------------- XoopsModules/newbb/branches/irmtfan/newbb/admin/admin_synchronization.php XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev10109.txt XoopsModules/newbb/branches/irmtfan/newbb/class/forum.php XoopsModules/newbb/branches/irmtfan/newbb/class/read.php XoopsModules/newbb/branches/irmtfan/newbb/class/topic.renderer.php XoopsModules/newbb/branches/irmtfan/newbb/docs/lang_diff.txt XoopsModules/newbb/branches/irmtfan/newbb/include/plugin.php XoopsModules/newbb/branches/irmtfan/newbb/language/english/admin.php XoopsModules/newbb/branches/irmtfan/newbb/language/persian/admin.php XoopsModules/newbb/branches/irmtfan/newbb/list.topic.php XoopsModules/newbb/branches/irmtfan/newbb/sql/mysql.430.sql XoopsModules/newbb/branches/irmtfan/newbb/sql/mysql.sql XoopsModules/newbb/branches/irmtfan/newbb/viewpost.php Modified: XoopsModules/newbb/branches/irmtfan/newbb/admin/admin_synchronization.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/admin/admin_synchronization.php 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/admin/admin_synchronization.php 2012-10-15 09:27:16 UTC (rev 10215) @@ -211,7 +211,15 @@ $stats_handler =& xoops_getmodulehandler('stats', 'newbb'); $stats_handler->reset(); break; - + // START irmtfan add read sync + case "read": + mod_loadFunctions("recon", "newbb"); + $result = newbb_synchronization("read"); + if (!empty($result)) { + redirect_header("admin_synchronization.php", 2, _AM_NEWBB_SYNC_TYPE_READ . "<br />" . _AM_NEWBB_DATABASEUPDATED); + } + exit(); + // END irmtfan add read sync case "misc": default: mod_loadFunctions("recon", "newbb"); @@ -257,6 +265,15 @@ $form .= '<input type="submit" name="submit" value=' . _SUBMIT . ' />'; $form .= '</div>'; $form .= '</form>'; +// START irmtfan add read sync +$form .= '<form action="admin_synchronization.php" method="get">'; +$form .= '<div style="padding: 10px 2px;">'; +$form .= '<h2>'._AM_NEWBB_SYNC_TYPE_READ.'</h2>'; +$form .= '<input type="hidden" name="type" value="read">'; +$form .= '<input type="submit" name="submit" value=' . _SUBMIT . ' />'; +$form .= '</div>'; +$form .= '</form>'; +// END irmtfan add read sync $form .= '<form action="admin_synchronization.php" method="get">'; $form .= '<div style="padding: 10px 2px;">'; Modified: XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev10109.txt =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev10109.txt 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev10109.txt 2012-10-15 09:27:16 UTC (rev 10215) @@ -1,3 +1,21 @@ +date 2012-10-15 +=================================== +1- bug fix: viewpost.php?status=new AND viewforum.php?forum=FFF&status=unread and list.topic.php?status=unread criteria was wrong when read_mode = 2(important) +in newbb/viewpost.php, newbb/class/forum.php, newbb/class/topic.renderer.php + +2- bug fix: in view all topic page: if empty($_GET(status)) it will show all topics include deleted and pendings. + the last solution removed in list.topic.php and move to topic.renderer.php because the last solution cause double query and error. +in newbb/list.topic.php, newbb/class/topic.renderer.php + +3- bug fix: add read_item_uid indexes to avoid duplicate (read_item, uid) when submit a post (very important) +newbb/sql/mysql.sql, newbb/sql/mysql.430.sql + +4- bug fix: add clearDuplicate function for clear duplicate rows in bb_reads_topic and bb_reads_forum tables. old newbb users should click on "Read Data" in newbb -> admin -> syncronization page. (very important) +in newbb/class/read.php, newbb/admin/admin_synchronization.php, newbb/language/LANG/admin.php, newbb/docs/lang_diff.txt + +5- improve: add read_expire = 0 => no clean up reads tables +in newbb/class/read.php, newbb/include/plugin.php + date 2012-10-11 =================================== 1- bug fix: viewpost.php?status=new was wrongly return the new posts and new posts counts based on read_mode=1 (cookie) when the read_mode=2 (database) (important) Modified: XoopsModules/newbb/branches/irmtfan/newbb/class/forum.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/class/forum.php 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/class/forum.php 2012-10-15 09:27:16 UTC (rev 10215) @@ -211,8 +211,15 @@ case 'unread': if (empty($xoopsModuleConfig["read_mode"])) { } elseif ($xoopsModuleConfig["read_mode"] ==2) { - $leftjoin .= ' LEFT JOIN ' . $this->db->prefix('bb_reads_topic') . ' r ON r.read_item = t.topic_id'; - $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; + // START irmtfan use read_uid to find the unread posts when the user is logged in + global $xoopsUser; + $read_uid = is_object($xoopsUser)?$xoopsUser->getVar("uid"):0; + if (!empty($read_uid)) { + $leftjoin .= ' LEFT JOIN ' . $this->db->prefix('bb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; + $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; + } else { + } + // END irmtfan use read_uid to find the unread posts when the user is logged in } elseif ($xoopsModuleConfig["read_mode"] == 1) { $topics = array(); $topic_lastread = newbb_getcookie('LT', true); @@ -477,8 +484,15 @@ case 'unread': if (empty($xoopsModuleConfig["read_mode"])) { } elseif ($xoopsModuleConfig["read_mode"] ==2) { - $leftjoin .= ' LEFT JOIN ' . $this->db->prefix('bb_reads_topic') . ' r ON r.read_item = t.topic_id'; - $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; + // START irmtfan use read_uid to find the unread posts when the user is logged in + global $xoopsUser; + $read_uid = is_object($xoopsUser)?$xoopsUser->getVar("uid"):0; + if (!empty($read_uid)) { + $leftjoin .= ' LEFT JOIN ' . $this->db->prefix('bb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; + $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; + } else { + } + // END irmtfan use read_uid to find the unread posts when the user is logged in } elseif ($xoopsModuleConfig["read_mode"] == 1) { $criteria_post = ' p.post_time > ' . max($GLOBALS['last_visit'], $startdate); $topics = array(); Modified: XoopsModules/newbb/branches/irmtfan/newbb/class/read.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/class/read.php 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/class/read.php 2012-10-15 09:27:16 UTC (rev 10215) @@ -101,7 +101,8 @@ $this->ArtObjectHandler($db, 'bb_reads_'.$type, 'Read'.$type, 'read_id', 'post_id'); $this->type = $type; $newbbConfig = newbb_load_config(); - $this->lifetime = !empty($newbbConfig["read_expire"]) ? $newbbConfig["read_expire"] *24*3600 : 30*24*3600; + // irmtfan if read_expire = 0 dont clean + $this->lifetime = isset($newbbConfig["read_expire"]) ? intval($newbbConfig["read_expire"]) *24*3600 : 30*24*3600; $this->mode = isset($newbbConfig["read_mode"]) ? $newbbConfig["read_mode"] : 2; } @@ -110,10 +111,12 @@ * * Delete all expired and duplicated records */ + // START irmtfan rephrase function to 1- add clearDuplicate and 2- dont clean when read_expire = 0 function clearGarbage() { - $expire = time() - intval($this->lifetime); - $sql = "DELETE FROM ".$this->table." WHERE read_time < ". $expire; - $this->db->queryF($sql); + // irmtfan clear duplicaed rows + if(!$result = $this->clearDuplicate()) { + return false; + } /* for MySQL 4.1+ */ if ($this->mysql_major_version() >= 4): @@ -130,9 +133,18 @@ //xoops_error($this->db->error()); return false; } + // irmtfan if read_expire = 0 dont clean + if (empty($this->lifetime)) return true; + // irmtfan move here and rephrase + $expire = time() - intval($this->lifetime); + $sql = "DELETE FROM ".$this->table." WHERE read_time < ". $expire; + if (!$result = $this->db->queryF($sql)) { + //xoops_error($this->db->error()); + return false; + } return true; } - + // END irmtfan rephrase function to 1- add clearDuplicate and 2- dont clean when read_expire = 0 function getRead($read_item, $uid = null) { if (empty($this->mode)) return null; @@ -259,6 +271,45 @@ } return $ret; } - + // START irmtfan add clear duplicated rows function + function clearDuplicate() + { + $sql = "CREATE TABLE " . $this->table . "_duplicate like " . $this->table . "; "; + if (!$result = $this->db->queryF($sql)) { + xoops_error($this->db->error().'<br />'.$sql); + return false; + } + $sql = "INSERT " . $this->table . "_duplicate SELECT * FROM " . $this->table . " GROUP BY read_item, uid; "; + if (!$result = $this->db->queryF($sql)) { + xoops_error($this->db->error().'<br />'.$sql); + return false; + } + $sql = "RENAME TABLE " . $this->table . " TO " . $this->table . "_with_duplicate; "; + if (!$result = $this->db->queryF($sql)) { + xoops_error($this->db->error().'<br />'.$sql); + return false; + } + $sql = "RENAME TABLE " . $this->table . "_duplicate TO " . $this->table . "; "; + if (!$result = $this->db->queryF($sql)) { + xoops_error($this->db->error().'<br />'.$sql); + return false; + } + $sql = "SHOW INDEX FROM " . $this->table . " WHERE KEY_NAME = 'read_item_uid'"; + $result = $this->db->queryF($sql); + if (empty($result)) { + $sql.= "ALTER TABLE " . $this->table . " ADD INDEX read_item_uid ( read_item, uid ); "; + if (!$result = $this->db->queryF($sql)) { + xoops_error($this->db->error().'<br />'.$sql); + return false; + } + } + $sql = "DROP TABLE " . $this->table . "_with_duplicate; "; + if (!$result = $this->db->queryF($sql)) { + xoops_error($this->db->error().'<br />'.$sql); + return false; + } + return true; + } + // END irmtfan add clear duplicated rows function } ?> \ No newline at end of file Modified: XoopsModules/newbb/branches/irmtfan/newbb/class/topic.renderer.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/class/topic.renderer.php 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/class/topic.renderer.php 2012-10-15 09:27:16 UTC (rev 10215) @@ -160,8 +160,15 @@ if (empty($this->config["read_mode"])) { // Use database } elseif ($this->config["read_mode"] == 2) { - $this->query["join"][] = 'LEFT JOIN ' . $this->handler->db->prefix('bb_reads_topic') . ' AS r ON r.read_item = t.topic_id'; - $this->query["where"][] = '(r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; + // START irmtfan use read_uid to find the unread posts when the user is logged in + global $xoopsUser; + $read_uid = is_object($xoopsUser)?$xoopsUser->getVar("uid"):0; + if (!empty($read_uid)) { + $this->query["join"][] = 'LEFT JOIN ' . $this->handler->db->prefix('bb_reads_topic') . ' AS r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; + $this->query["where"][] = '(r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; + } else { + } + // END irmtfan change criteria to get from uid p.uid = last post submit user id // User cookie } elseif ($this->config["read_mode"] == 1) { if ($lastvisit =$GLOBALS['last_visit']) { @@ -263,6 +270,8 @@ if (isset($parsed)) return true; if (!isset($this->vars["forum"])) $this->vars["forum"] = null; + //irmtfan parse status for rendering topic correctly - if empty($_GET(status)) it will show all topics include deleted and pendings. + if (!isset($this->vars["status"])) $this->vars["status"] = all; foreach ($this->vars as $var => $val) { $this->parseVar($var, $val); Modified: XoopsModules/newbb/branches/irmtfan/newbb/docs/lang_diff.txt =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/docs/lang_diff.txt 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/docs/lang_diff.txt 2012-10-15 09:27:16 UTC (rev 10215) @@ -67,4 +67,6 @@ --------- define('_AM_NEWBB_REPORTSAVE','Selected Reports have been processed successfully'); define('_AM_NEWBB_REPORTDELETE','Selected Reports have been deleted from database successfully'); -define('_AM_NEWBB_REPORTNOTSELECT','No Report is selected!'); \ No newline at end of file +define('_AM_NEWBB_REPORTNOTSELECT','No Report is selected!'); +define("_AM_NEWBB_SYNC_TYPE_READ","Read Data"); +define("_AM_NEWBB_DATABASEUPDATED","Database Updated Successfully!"); \ No newline at end of file Modified: XoopsModules/newbb/branches/irmtfan/newbb/include/plugin.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/include/plugin.php 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/include/plugin.php 2012-10-15 09:27:16 UTC (rev 10215) @@ -57,8 +57,8 @@ // storage method for reading records: 0 - none; 1 - cookie; 2 - db $customConfig["read_mode"] = 2; -// expire time for reading records, in days -$customConfig["read_expire"] = 30; +// expire time for reading records, in days; irmtfan add feature: 0 or no cleanup +$customConfig["read_expire"] = 0; // maximum records per forum for one user $customConfig["read_items"] = 100; Modified: XoopsModules/newbb/branches/irmtfan/newbb/language/english/admin.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/language/english/admin.php 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/language/english/admin.php 2012-10-15 09:27:16 UTC (rev 10215) @@ -301,4 +301,6 @@ define('_AM_NEWBB_REPORTSAVE','Selected Reports have been processed successfully'); define('_AM_NEWBB_REPORTDELETE','Selected Reports have been deleted from database successfully'); define('_AM_NEWBB_REPORTNOTSELECT','No Report is selected!'); +define("_AM_NEWBB_SYNC_TYPE_READ","Read Data"); +define("_AM_NEWBB_DATABASEUPDATED","Database Updated Successfully!"); ?> \ No newline at end of file Modified: XoopsModules/newbb/branches/irmtfan/newbb/language/persian/admin.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/language/persian/admin.php 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/language/persian/admin.php 2012-10-15 09:27:16 UTC (rev 10215) @@ -300,4 +300,6 @@ define('_AM_NEWBB_UPLOAD','حداکثر اندازه هر فایل برای آپلود:'); define('_AM_NEWBB_MEMLIMITTOLARGE','توجه کنید که متغیر \'memory_limit\' در فایل PHP.INI کمتر از متغیر \'post_max_size\' است.'); define('_AM_NEWBB_MEMLIMITOK','فایل های با حداکثر اندازه %s قابل آپلود در این سایت هستند.'); +define("_AM_NEWBB_SYNC_TYPE_READ","اطلاعات جدول خوانده شده ها"); +define("_AM_NEWBB_DATABASEUPDATED","پایگاه داده با موفقیت به روز شد!"); ?> \ No newline at end of file Modified: XoopsModules/newbb/branches/irmtfan/newbb/list.topic.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/list.topic.php 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/list.topic.php 2012-10-15 09:27:16 UTC (rev 10215) @@ -35,8 +35,8 @@ $type = intval( @$_GET['type'] ); $status = (!empty($_GET['status']) && in_array($_GET['status'], array("active", "pending", "deleted", "digest", "unreplied", "unread")))? $_GET['status'] : "all"; -//irmtfan parse status for rendering topic correctly - if empty($_GET(status)) it will show all topics include deleted and pendings. -$topic_renderer->parseVar('status',$status); +//irmtfan parse status for rendering topic correctly - remove here and move to topic.renderer.php +//$topic_renderer->parseVar('status',$status); $mode = (!empty($status) && in_array($status, array("active", "pending", "deleted"))) ? 2 : (!empty($_GET['mode']) ? intval($_GET['mode']) : 0); $isadmin = $GLOBALS["xoopsUserIsAdmin"]; Modified: XoopsModules/newbb/branches/irmtfan/newbb/sql/mysql.430.sql =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/sql/mysql.430.sql 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/sql/mysql.430.sql 2012-10-15 09:27:16 UTC (rev 10215) @@ -2,4 +2,10 @@ ALTER TABLE `bb_posts` ADD INDEX `forumid_uid` ( `forum_id` , `uid` ); ALTER TABLE `bb_posts` ADD INDEX `topicid_uid` ( `topic_id` , `uid` ); -ALTER TABLE `bb_posts` ADD INDEX `forumid_approved_postid` ( `forum_id` , `approved` , `post_id` ); \ No newline at end of file +ALTER TABLE `bb_posts` ADD INDEX `forumid_approved_postid` ( `forum_id` , `approved` , `post_id` ); +-- irmtfan add read_time indexes +ALTER TABLE `bb_reads_topic` + ADD INDEX `read_item_uid` ( `read_item`, `uid` ); + +ALTER TABLE `bb_reads_forum` + ADD INDEX `read_item_uid` ( `read_item`, `uid` ); \ No newline at end of file Modified: XoopsModules/newbb/branches/irmtfan/newbb/sql/mysql.sql =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/sql/mysql.sql 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/sql/mysql.sql 2012-10-15 09:27:16 UTC (rev 10215) @@ -220,7 +220,8 @@ PRIMARY KEY (`read_id`), KEY `uid` (`uid`), KEY `read_item` (`read_item`), - KEY `post_id` (`post_id`) + KEY `post_id` (`post_id`), + KEY `read_item_uid` (`read_item`, `uid`) ) ENGINE=MyISAM; -- -------------------------------------------------------- @@ -239,7 +240,8 @@ PRIMARY KEY (`read_id`), KEY `uid` (`uid`), KEY `read_item` (`read_item`), - KEY `post_id` (`post_id`) + KEY `post_id` (`post_id`), + KEY `read_item_uid` (`read_item`, `uid`) ) ENGINE=MyISAM; -- -------------------------------------------------------- Modified: XoopsModules/newbb/branches/irmtfan/newbb/viewpost.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/viewpost.php 2012-10-12 00:38:13 UTC (rev 10214) +++ XoopsModules/newbb/branches/irmtfan/newbb/viewpost.php 2012-10-15 09:27:16 UTC (rev 10215) @@ -99,10 +99,16 @@ //$criteria_status_count->add(new Criteria("approved", 1));// irmtfan commented and removed //$criteria_status_post->add(new Criteria("p.approved", 1));// irmtfan commented and removed } elseif ($xoopsModuleConfig["read_mode"] ==2) { - $join = ' LEFT JOIN ' . $xoopsDB->prefix('bb_reads_topic') . ' AS r ON r.read_item = p.topic_id'; // irmtfan corrected add AS - $criteria_status_post = new CriteriaCompo();// irmtfan new criteria - $criteria_status_post->add(new Criteria("p.post_id", "r.`post_id`", ">")); // irmtfan corrected - should use $value="r.``" to render in XOOPS/class/criteria.php - $criteria_status_post->add(new Criteria("r.read_id", NULL, "IS NULL"), "OR");// irmtfan corrected - should use "IS NULL" to render in XOOPS/class/criteria.php + // START irmtfan use read_uid to find the unread posts when the user is logged in + $read_uid = is_object($xoopsUser)?$xoopsUser->getVar("uid"):0; + if (!empty($read_uid)) { + $join = ' LEFT JOIN ' . $xoopsDB->prefix('bb_reads_topic') . ' AS r ON r.read_item = p.topic_id AND r.uid = ' . $read_uid . ' '; // irmtfan corrected add AS + $criteria_status_post = new CriteriaCompo();// irmtfan new criteria + $criteria_status_post->add(new Criteria("p.post_id", "r.`post_id`", ">")); // irmtfan corrected - should use $value="r.``" to render in XOOPS/class/criteria.php + $criteria_status_post->add(new Criteria("r.read_id", NULL, "IS NULL"), "OR");// irmtfan corrected - should use "IS NULL" to render in XOOPS/class/criteria.php + } else { + } + // END irmtfan use read_uid to find the unread posts when the user is logged in //$criteria_status_post->add(new Criteria("p.approved", 1)); // irmtfan commented and removed //$criteria_status_count =& $criteria_status_post; $criteria_post->add($criteria_status_post); // irmtfan add the status criteria to post criteria |