From c0232e6fce4739d9b797515a4a8ba28db8f602c1 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Wed, 29 Oct 2014 16:03:38 +0000 Subject: [PATCH] Use regular tread save in "Thread::closeOldThreads" method --- src/mibew/libs/classes/Mibew/Thread.php | 29 ++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/mibew/libs/classes/Mibew/Thread.php b/src/mibew/libs/classes/Mibew/Thread.php index 43b82647..3ab4a37e 100644 --- a/src/mibew/libs/classes/Mibew/Thread.php +++ b/src/mibew/libs/classes/Mibew/Thread.php @@ -394,11 +394,7 @@ class Thread // Get the lock Settings::set('_threads_close_old_lock_time', time()); - $query = "UPDATE {thread} SET " - . "lrevision = :next_revision, " - . "dtmmodified = :now, " - . "dtmclosed = :now, " - . "istate = :state_closed " + $query = "SELECT * FROM {thread} " . "WHERE istate <> :state_closed " . "AND istate <> :state_left " // Check created timestamp @@ -432,18 +428,31 @@ class Thread . ") " . ")"; - // Perform the cleaning - Database::getInstance()->query( + // Get appropriate threads + $now = time(); + $rows = Database::getInstance()->query( $query, array( - ':next_revision' => self::nextRevision(), - ':now' => time(), + ':now' => $now, ':state_closed' => self::STATE_CLOSED, ':state_left' => self::STATE_LEFT, ':thread_lifetime' => Settings::get('thread_lifetime'), - ) + ), + array('return_rows' => Database::RETURN_ALL_ROWS) ); + // Perform the cleaning + $revision = self::nextRevision(); + foreach ($rows as $row) { + $thread = Thread::createFromDbInfo($row); + $thread->lastRevision = $revision; + $thread->modified = $now; + $thread->closed = $now; + $thread->state = self::STATE_CLOSED; + $thread->save(); + unset($thread); + } + // Release the lock Settings::set('_threads_close_old_lock_time', '0'); }