Export conversations (SMF)
authorTim Düsterhus <timwolla@bastelstu.be>
Wed, 11 Sep 2013 15:45:03 +0000 (17:45 +0200)
committerTim Düsterhus <timwolla@bastelstu.be>
Wed, 11 Sep 2013 15:45:03 +0000 (17:45 +0200)
files/lib/system/exporter/SMF2xExporter.class.php

index a427bcd0ca9ba9d9bf4192c665391c36480768d2..e5faf5e1163f099edad1a7c63d28eb472ecfe5c6 100644 (file)
@@ -154,8 +154,9 @@ class SMF2xExporter extends AbstractExporter {
                        if (in_array('com.woltlab.wcf.conversation', $this->selectedData)) {
                                if (in_array('com.woltlab.wcf.conversation.label', $this->selectedData)) $queue[] = 'com.woltlab.wcf.conversation.label';
                                
-                               /*$queue[] = 'com.woltlab.wcf.conversation';
-                               $queue[] = 'com.woltlab.wcf.conversation.user';*/
+                               $queue[] = 'com.woltlab.wcf.conversation';
+                               $queue[] = 'com.woltlab.wcf.conversation.message';
+                               /*$queue[] = 'com.woltlab.wcf.conversation.user';*/
                        }
                }
                /*
@@ -435,4 +436,94 @@ class SMF2xExporter extends AbstractExporter {
                        }
                }
        }
+       
+       /**
+        * Counts conversations.
+        */
+       public function countConversations() {
+               $sql = "SELECT  COUNT(*) AS count
+                       FROM    ".$this->databasePrefix."personal_messages
+                       WHERE   id_pm = id_pm_head";
+               $statement = $this->database->prepareStatement($sql);
+               $statement->execute();
+               $row = $statement->fetchArray();
+               return $row['count'];
+       }
+       
+       /**
+        * Exports conversations.
+        */
+       public function exportConversations($offset, $limit) {
+               $sql = "INSERT IGNORE INTO      wcf".WCF_N."_conversation_to_user
+                                               (conversationID, participantID, hideConversation, isInvisible, lastVisitTime)
+                       VALUES                  (?, ?, ?, ?, ?)";
+               $insertStatement = WCF::getDB()->prepareStatement($sql);
+               
+               $sql = "SELECT          *
+                       FROM            ".$this->databasePrefix."personal_messages
+                       WHERE           id_pm = id_pm_head
+                       ORDER BY        id_pm";
+               $statement = $this->database->prepareStatement($sql, $limit, $offset);
+               $statement->execute(array(0));
+               while ($row = $statement->fetchArray()) {
+                       $conversationID = ImportHandler::getInstance()->getImporter('com.woltlab.wcf.conversation')->import($row['id_pm'], array(
+                               'subject' => $row['subject'],
+                               'time' => $row['msgtime'],
+                               'userID' => $row['id_member_from'],
+                               'username' => $row['from_name'],
+                               'isDraft' => 0 // TODO: isDraft
+                       ));
+                       
+                       // add author
+                       $insertStatement->execute(array(
+                               $conversationID,
+                               ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $row['id_member_from']),
+                               0,
+                               0,
+                               TIME_NOW
+                       ));
+               }
+       }
+       
+       /**
+        * Counts conversation messages.
+        */
+       public function countConversationMessages() {
+               $sql = "SELECT  COUNT(*) AS count
+                       FROM    ".$this->databasePrefix."personal_messages";
+               $statement = $this->database->prepareStatement($sql);
+               $statement->execute();
+               $row = $statement->fetchArray();
+               return $row['count'];
+       }
+       
+       /**
+        * Exports conversation messages.
+        */
+       public function exportConversationMessages($offset, $limit) {
+               $sql = "SELECT          *
+                       FROM            ".$this->databasePrefix."personal_messages
+                       ORDER BY        id_pm";
+               $statement = $this->database->prepareStatement($sql, $limit, $offset);
+               $statement->execute();
+               while ($row = $statement->fetchArray()) {
+                       ImportHandler::getInstance()->getImporter('com.woltlab.wcf.conversation.message')->import($row['id_pm'], array(
+                               'conversationID' => $row['id_pm_head'],
+                               'userID' => $row['id_member_from'],
+                               'username' => $row['from_name'],
+                               'message' => self::fixBBCodes($row['body']),
+                               'time' => $row['msgtime'],
+                               'attachments' => 0, // not supported
+                               'enableSmilies' => 1,
+                               'enableHtml' => 0,
+                               'enableBBCodes' => 1,
+                               'showSignature' => 1
+                       ));
+               }
+       }
+       
+       private static function fixBBCodes($message) {
+               // TODO: This is a identity function right now...
+               return $message;
+       }
 }