Support XF 2.1 reactions
authorTim Düsterhus <tim@bastelstu.be>
Wed, 2 Oct 2019 21:15:59 +0000 (23:15 +0200)
committerTim Düsterhus <tim@bastelstu.be>
Wed, 2 Oct 2019 21:15:59 +0000 (23:15 +0200)
files/lib/system/exporter/XF2xExporter.class.php

index 396770e82765cbae1fe171624de1eb3887f97450..b4c150386363711bdcdfb91ee01cf71a349fb26c 100644 (file)
@@ -1521,11 +1521,20 @@ class XF2xExporter extends AbstractExporter {
         * @param       string          $objectType
         */
        private function countLikes($objectType) {
-               $sql = "SELECT  COUNT(*) AS count
-                       FROM    xf_liked_content
-                       WHERE   content_type = ?";
-               $statement = $this->database->prepareStatement($sql);
-               $statement->execute([$objectType]);
+               try {
+                       $sql = "SELECT  COUNT(*) AS count
+                               FROM    xf_reaction_content
+                               WHERE   content_type = ?";
+                       $statement = $this->database->prepareStatement($sql);
+                       $statement->execute([$objectType]);
+               }
+               catch (SystemException $e) {
+                       $sql = "SELECT  COUNT(*) AS count
+                               FROM    xf_liked_content
+                               WHERE   content_type = ?";
+                       $statement = $this->database->prepareStatement($sql);
+                       $statement->execute([$objectType]);
+               }
                $row = $statement->fetchArray();
                return $row['count'];
        }
@@ -1539,19 +1548,40 @@ class XF2xExporter extends AbstractExporter {
         * @param       integer         $limit
         */
        private function exportLikes($objectType, $importer, $offset, $limit) {
-               $sql = "SELECT          *
-                       FROM            xf_liked_content
-                       WHERE           content_type = ?
-                       ORDER BY        like_id";
-               $statement = $this->database->prepareStatement($sql, $limit, $offset);
-               $statement->execute([$objectType]);
+               try {
+                       $sql = "SELECT          rc.*, r.reaction_score
+                               FROM            xf_reaction_content rc
+                               INNER JOIN      xf_reaction r
+                                       ON      r.reaction_id = rc.reaction_id
+                               WHERE           rc.content_type = ?
+                               ORDER BY        rc.reaction_content_id";
+                       $statement = $this->database->prepareStatement($sql, $limit, $offset);
+                       $statement->execute([$objectType]);
+               }
+               catch (SystemException $e) {
+                       $sql = "SELECT          *
+                               FROM            xf_liked_content
+                               WHERE           content_type = ?
+                               ORDER BY        like_id";
+                       $statement = $this->database->prepareStatement($sql, $limit, $offset);
+                       $statement->execute([$objectType]);
+               }
                while ($row = $statement->fetchArray()) {
+                       if (!isset($row['reaction_user_id'])) {
+                               $row['reaction_user_id'] = $row['like_user_id'];
+                       }
+                       if (!isset($row['reaction_date'])) {
+                               $row['reaction_date'] = $row['like_date'];
+                       }
+                       if (!isset($row['reaction_score'])) {
+                               $row['reaction_score'] = 1;
+                       }
                        ImportHandler::getInstance()->getImporter($importer)->import(0, [
                                'objectID' => $row['content_id'],
                                'objectUserID' => $row['content_user_id'],
-                               'userID' => $row['like_user_id'],
-                               'likeValue' => Like::LIKE,
-                               'time' => $row['like_date']
+                               'userID' => $row['reaction_user_id'],
+                               'likeValue' => $row['reaction_score'] >= 0 ? Like::LIKE : Like::DISLIKE,
+                               'time' => $row['reaction_date']
                        ]);
                }
        }