diff --git a/app/Manager/Comment.php b/app/Manager/Comment.php
index f718add1d..d3bd44b6c 100644
--- a/app/Manager/Comment.php
+++ b/app/Manager/Comment.php
@@ -67,6 +67,43 @@ public function create(int $userId, string $page, int $pageId, string $body) {
return (new $className($pageId))->setPostId($postId);
}
+ public function merge(string $page, int $pageId, int $targetPageId) {
+ $qid = $this->db->get_query_id();
+
+ $this->db->prepared_query("
+ UPDATE comments SET
+ PageID = ?
+ WHERE Page = ? AND PageID = ?
+ ", $targetPageId, $page, $pageId
+ );
+ $pageCount = $this->db->scalar("
+ SELECT ceil(count(*) / ?) AS Pages
+ FROM comments
+ WHERE Page = ? AND PageID = ?
+ GROUP BY PageID
+ ", TORRENT_COMMENTS_PER_PAGE, $page, $targetPageId
+ );
+ $last = floor((TORRENT_COMMENTS_PER_PAGE * $pageCount - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
+
+ // quote notifications
+ $this->db->prepared_query("
+ UPDATE users_notify_quoted SET
+ PageID = ?
+ WHERE Page = ? AND PageID = ?
+ ", $targetPageId, $page, $pageId
+ );
+ $this->db->set_query_id($qid);
+
+ // comment subscriptions
+ $subscription = new \Gazelle\Manager\Subscription;
+ $subscription->move($page, $pageId, $targetPageId);
+
+ for ($i = 0; $i <= $last; ++$i) {
+ $this->cache->delete_value($page . "_comments_$targetPageId" . "_catalogue_$i");
+ }
+ $this->cache->delete_value($page."_comments_$targetPageId");
+ }
+
/**
* Remove all comments on $page/$pageId (handle quote notifications and subscriptions as well)
* @param string $page
@@ -86,6 +123,7 @@ public function remove(string $page, int $pageId) {
if ($pageCount === 0) {
return false;
}
+ $last = floor((TORRENT_COMMENTS_PER_PAGE * $pageCount - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
$this->db->prepared_query("
DELETE FROM comments WHERE Page = ? AND PageID = ?
@@ -101,14 +139,13 @@ public function remove(string $page, int $pageId) {
DELETE FROM users_notify_quoted WHERE Page = ? AND PageID = ?
", $page, $pageId
);
+ $this->db->set_query_id($qid);
// Clear cache
- $last = floor((TORRENT_COMMENTS_PER_PAGE * $CommPages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
for ($i = 0; $i <= $last; ++$i) {
$this->cache->delete_value($page . '_comments_' . $pageId . '_catalogue_' . $i);
}
$this->cache->delete_value($page . '_comments_' . $pageId);
- $this->db->set_query_id($qid);
return true;
}
@@ -129,4 +166,41 @@ public function loadEdits(string $page, int $postId): array {
}
return $edits;
}
+
+ /**
+ * Load recent collage comments. Used for displaying recent comments on collage pages.
+ * @param int $CollageID ID of the collage
+ * @return array ($Comments)
+ * $Comments
+ * ID: Comment ID
+ * Body: Comment body
+ * AuthorID: Author of comment
+ * Username: Their username
+ * AddedTime: Date of comment creation
+ */
+ public function collageSummary($collageId, $count = 5): array {
+ $key = "collages_comments_recent_$collageId";
+ $list = $this->cache->get_value($key);
+ if ($list === false) {
+ $qid = $this->db->get_query_id();
+ $this->db->prepared_query("
+ SELECT c.ID AS id,
+ c.Body as body,
+ c.AuthorID as author_id,
+ c.AddedTime as added
+ FROM comments AS c
+ LEFT JOIN users_main AS um ON (um.ID = c.AuthorID)
+ WHERE c.Page = ? AND c.PageID = ?
+ ORDER BY c.ID DESC
+ LIMIT ?
+ ", 'collages', $collageId, $count
+ );
+ $list = $this->db->to_array(false, MYSQLI_ASSOC, false);
+ $this->db->set_query_id($qid);
+ if (count($list)) {
+ $this->cache->cache_value($key, $list, 7200);
+ }
+ }
+ return $list;
+ }
}
diff --git a/classes/comments.class.php b/classes/comments.class.php
deleted file mode 100644
index 573f08412..000000000
--- a/classes/comments.class.php
+++ /dev/null
@@ -1,94 +0,0 @@
-get_value($key)) === false) {
- $qid = $DB->get_query_id();
- $DB->prepared_query('
- SELECT c.ID AS id,
- c.Body as body,
- c.AuthorID as author_id,
- c.AddedTime as added
- FROM comments AS c
- LEFT JOIN users_main AS um ON (um.ID = c.AuthorID)
- WHERE c.Page = ? AND c.PageID = ?
- ORDER BY c.ID DESC
- LIMIT ?
- ', 'collages', $CollageID, $count
- );
- $list = $DB->to_array(false, MYSQLI_ASSOC);
- foreach ($list as &$c) {
- $c['body'] = Text::full_format($c['body']);
- }
- unset($c);
- $DB->set_query_id($quid);
- if (count($list)) {
- $Cache->cache_value($key, $list, 7200);
- }
- }
- return $list;
- }
-
- /**
- * Merges all comments from $Page/$PageID into $Page/$TargetPageID. This also takes care of quote notifications, subscriptions and cache.
- * @param type $Page
- * @param type $PageID
- * @param type $TargetPageID
- */
- public static function merge($Page, $PageID, $TargetPageID) {
- global $Cache, $DB;
- $QueryID = $DB->get_query_id();
-
- $DB->prepared_query("
- UPDATE comments SET
- PageID = ?
- WHERE Page = ? AND PageID = ?
- ", $TargetPageID, $Page, $PageID
- );
-
- // quote notifications
- $DB->prepared_query("
- UPDATE users_notify_quoted SET
- PageID = ?
- WHERE Page = ? AND PageID = ?
- ", $TargetPageID, $Page, $PageID
- );
-
- // comment subscriptions
- $subscription = new \Gazelle\Manager\Subscription;
- $subscription->move($Page, $PageID, $TargetPageID);
-
- // cache (we need to clear all comment catalogues)
- $CommPages = $DB->scalar("
- SELECT ceil(count(*) / ?) AS Pages
- FROM comments
- WHERE Page = ? AND PageID = ?
- GROUP BY PageID
- ", TORRENT_COMMENTS_PER_PAGE, $Page, $TargetPageID
- );
- $LastCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $CommPages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
- for ($i = 0; $i <= $LastCatalogue; ++$i) {
- $Cache->delete_value($Page . "_comments_$TargetPageID" . "_catalogue_$i");
- }
- $Cache->delete_value($Page."_comments_$TargetPageID");
- $DB->set_query_id($QueryID);
- }
-}
diff --git a/sections/artist/rename.php b/sections/artist/rename.php
index 69ad90127..f7fa92e1c 100644
--- a/sections/artist/rename.php
+++ b/sections/artist/rename.php
@@ -186,7 +186,7 @@
Requests::update_sphinx_requests($RequestID);
}
}
- Comments::merge('artist', $ArtistID, $TargetArtistID);
+ (new \Gazelle\Manager\Comment)->merge('artist', $ArtistID, $TargetArtistID);
}
}
diff --git a/sections/collages/artist_collage.php b/sections/collages/artist_collage.php
index fd88d038e..9402bede5 100644
--- a/sections/collages/artist_collage.php
+++ b/sections/collages/artist_collage.php
@@ -60,7 +60,7 @@
'can_post' => !$LoggedUser['DisablePosting'],
'category_id' => $Collage->categoryId(),
'category_name' => $CollageCats[$Collage->categoryId()],
- 'comments' => Comments::collageSummary($CollageID),
+ 'comments' => (new Gazelle\Manager\Comment)->collageSummary($CollageID),
'contributors' => array_slice($Collage->contributors(), 0, 5, true),
'contributors_n' => $Collage->numContributors(),
'description' => Text::full_format($Collage->description()),
diff --git a/sections/collages/torrent_collage.php b/sections/collages/torrent_collage.php
index e46f81489..b28529745 100644
--- a/sections/collages/torrent_collage.php
+++ b/sections/collages/torrent_collage.php
@@ -34,7 +34,7 @@
'can_post' => !$LoggedUser['DisablePosting'],
'category_id' => $Collage->categoryId(),
'category_name' => $CollageCats[$Collage->categoryId()],
- 'comments' => Comments::collageSummary($CollageID),
+ 'comments' => (new Gazelle\Manager\Comment)->collageSummary($CollageID),
'contributors_n' => $Collage->numContributors(),
'contributors' => array_slice($Collage->contributors(), 0, 5, true),
'description' => Text::full_format($Collage->description()),
diff --git a/sections/torrents/merge.php b/sections/torrents/merge.php
index a7890642d..76db4dab0 100644
--- a/sections/torrents/merge.php
+++ b/sections/torrents/merge.php
@@ -150,7 +150,7 @@
);
// Comments
- Comments::merge('torrents', $oldGroupId, $newGroupId);
+ (new \Gazelle\Manager\Comment)->merge('torrents', $oldGroupId, $newGroupId);
// Collages
$DB->prepared_query("
diff --git a/templates/collage/sidebar.twig b/templates/collage/sidebar.twig
index f9882a3ba..c26247d82 100644
--- a/templates/collage/sidebar.twig
+++ b/templates/collage/sidebar.twig
@@ -104,7 +104,7 @@ collage by {{ user_id|user_url }}
Report
-