Don't import direct messages as topics
authorMarcel Werk <burntime@woltlab.com>
Mon, 30 Oct 2023 14:11:12 +0000 (15:11 +0100)
committerMarcel Werk <burntime@woltlab.com>
Mon, 30 Oct 2023 14:11:12 +0000 (15:11 +0100)
files/lib/system/exporter/DiscourseExporter.class.php

index 720638662e6a7b7e5379ca8f71e79bd2ce2df869..f3fedcd783fb7d4edc89300c8168dd21746a0d90 100644 (file)
@@ -270,7 +270,13 @@ final class DiscourseExporter extends AbstractExporter
 
     public function countThreads(): int
     {
-        return $this->countRows('topics');
+        $sql = "SELECT  COUNT(*)
+                FROM    topics
+                WHERE   archetype = ?";
+        $statement = $this->database->prepareStatement($sql);
+        $statement->execute(['regular']);
+
+        return $statement->fetchSingleColumn();
     }
 
     public function exportThreads(int $offset, int $limit): void
@@ -278,9 +284,10 @@ final class DiscourseExporter extends AbstractExporter
         $sql = "SELECT      topics.*, users.username
                 FROM        topics
                 LEFT JOIN   users ON (users.id = topics.user_id)
+                WHERE       topics.archetype = ?
                 ORDER BY    id";
         $statement = $this->database->prepareStatement($sql, $limit, $offset);
-        $statement->execute();
+        $statement->execute(['regular']);
         while ($row = $statement->fetchArray()) {
             $data = [
                 'boardID' => $row['category_id'] ?: 1,
@@ -305,7 +312,13 @@ final class DiscourseExporter extends AbstractExporter
 
     public function countPosts(): int
     {
-        return $this->countRows('posts');
+        $sql = "SELECT  COUNT(*)
+                FROM    posts
+                WHERE   topic_id IN (SELECT id FROM topics WHERE archetype = ?)";
+        $statement = $this->database->prepareStatement($sql);
+        $statement->execute(['regular']);
+
+        return $statement->fetchSingleColumn();
     }
 
     public function exportPosts(int $offset, int $limit): void
@@ -315,9 +328,10 @@ final class DiscourseExporter extends AbstractExporter
                 FROM        posts
                 LEFT JOIN   users
                 ON          users.id = posts.user_id
+                WHERE       posts.topic_id IN (SELECT id FROM topics WHERE archetype = ?)
                 ORDER BY    posts.id";
         $statement = $this->database->prepareStatement($sql, $limit, $offset);
-        $statement->execute();
+        $statement->execute(['regular']);
         while ($row = $statement->fetchArray()) {
             $data = [
                 'threadID' => $row['topic_id'],