From 932b0b9e6331111671d6aed7224f2c8c38531ace Mon Sep 17 00:00:00 2001 From: PupperWoff Date: Wed, 7 Jun 2017 15:02:20 +0200 Subject: [PATCH] Bugfix - Bugfix to Archive code --- inc/archive.php | 14 ++++++++++---- inc/functions.php | 6 ++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/inc/archive.php b/inc/archive.php index 614f4c1c..b4eca253 100644 --- a/inc/archive.php +++ b/inc/archive.php @@ -82,16 +82,16 @@ class Archive { } // Insert Archive Data in Database - $query = prepare(sprintf("INSERT INTO ``archive_%s`` VALUES (:thread_id, :snippet, :time, :files, 0)", $board['uri'])); + $query = prepare(sprintf("INSERT INTO ``archive_%s`` VALUES (:thread_id, :snippet, :lifetime, :files, 0)", $board['uri'])); $query->bindValue(':thread_id', $thread_id, PDO::PARAM_INT); $query->bindValue(':snippet', $thread_data['snippet'], PDO::PARAM_STR); - $query->bindValue(':time', (!$config['archive']['lifetime'])?0:strtotime("+".$config['archive']['lifetime']." days"), PDO::PARAM_INT); + $query->bindValue(':lifetime', time(), PDO::PARAM_INT); $query->bindValue(':files', json_encode($file_list)); $query->execute() or error(db_error($query)); // Purge Threads that have timed out - if(!$config['archive']['cron_job']) + if(!$config['archive']['cron_job']['purge']) self::purgeArchive(); // Rebuild Archive Index @@ -108,8 +108,14 @@ class Archive { static public function purgeArchive() { global $config, $board; + // If archive is set to live forever return + if(!$config['archive']['lifetime']) + return; + // Delete all static pages and files for archived threads that has timed out - $query = query(sprintf("SELECT `id`, `files` FROM ``archive_%s`` WHERE `lifetime` < %d AND `featured` = 0", $board['uri'], time())) or error(db_error()); + $query = prepare(sprintf("SELECT `id`, `files` FROM ``archive_%s`` WHERE `lifetime` < :lifetime AND `featured` = 0", $board['uri'])); + $query->bindValue(':lifetime', strtotime("+".$config['archive']['lifetime']." days"), PDO::PARAM_INT); + $query->execute() or error(db_error($query)); while($thread = $query->fetch(PDO::FETCH_ASSOC)) { // Delete Files foreach (json_decode($thread['files']) as $f) { diff --git a/inc/functions.php b/inc/functions.php index 4520cea6..f5536355 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1534,10 +1534,12 @@ function clean($pid = false) { while ($post = $query->fetch(PDO::FETCH_ASSOC)) { if($config['archive']['threads']) { Archive::archiveThread($post['id']); + deletePost($post['id'], false, false); if ($pid) modLog("Automatically archived thread #{$post['id']} due to new thread #{$pid}"); + } else { + deletePost($post['id'], false, false); + if ($pid) modLog("Automatically deleting thread #{$post['id']} due to new thread #{$pid}"); } - deletePost($post['id'], false, false); - if ($pid) modLog("Automatically deleting thread #{$post['id']} due to new thread #{$pid}"); } // Bump off threads with X replies earlier, spam prevention method