Added conversation import
authorMarcel Werk <burntime@woltlab.com>
Wed, 3 Jul 2013 15:44:44 +0000 (17:44 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 3 Jul 2013 15:44:44 +0000 (17:44 +0200)
files/lib/system/importer/ConversationAttachmentImporter.class.php [new file with mode: 0644]
files/lib/system/importer/ConversationImporter.class.php [new file with mode: 0644]
files/lib/system/importer/ConversationLabelImporter.class.php [new file with mode: 0644]
files/lib/system/importer/ConversationMessageImporter.class.php [new file with mode: 0644]
files/lib/system/importer/ConversationUserImporter.class.php [new file with mode: 0644]
objectType.xml

diff --git a/files/lib/system/importer/ConversationAttachmentImporter.class.php b/files/lib/system/importer/ConversationAttachmentImporter.class.php
new file mode 100644 (file)
index 0000000..361bca3
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\conversation\message\ConversationMessageEditor;
+use wcf\data\conversation\message\ConversationMessage;
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\util\StringUtil;
+
+/**
+ * Imports conversation attachments.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.conversation
+ * @subpackage system.importer
+ * @category   Community Framework
+ */
+class ConversationAttachmentImporter extends AbstractAttachmentImporter {
+       /**
+        * Creates a new ConversationAttachmentImporter object.
+        */
+       public function __construct() {
+               $objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'com.woltlab.wcf.conversation.message');
+               $this->objectTypeID = $objectType->objectTypeID;
+       }
+       
+       /**
+        * @see wcf\system\importer\IImporter::import()
+        */
+       public function import($oldID, array $data) {
+               $data['objectID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.conversation.message', $data['objectID']);
+               if (!$data['objectID']) return 0;
+               
+               $attachmentID = parent::import($oldID, $data);
+               if ($attachmentID && $attachmentID != $oldID) {
+                       // fix embedded attachments
+                       $message = new ConversationMessage($data['objectID']);
+                       
+                       if (StringUtil::indexOfIgnoreCase($message->message, '[attach]'.$oldID.'[/attach]') !== false || StringUtil::indexOfIgnoreCase($message->message, '[attach='.$oldID.']') !== false) {
+                               $newMessage = StringUtil::replaceIgnoreCase('[attach]'.$oldID.'[/attach]', '[attach]'.$attachmentID.'[/attach]', $message->message);
+                               $newMessage = StringUtil::replaceIgnoreCase('[attach='.$oldID.']', '[attach='.$attachmentID.']', $newMessage);
+                               
+                               $editor = new ConversationMessageEditor($message);
+                               $editor->update(array(
+                                       'message' => $newMessage        
+                               ));
+                       }
+               }
+               
+               return $attachmentID;
+       }
+}
diff --git a/files/lib/system/importer/ConversationImporter.class.php b/files/lib/system/importer/ConversationImporter.class.php
new file mode 100644 (file)
index 0000000..d448d72
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\conversation\Conversation;
+use wcf\data\conversation\ConversationEditor;
+
+/**
+ * Imports conversations.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.conversation
+ * @subpackage system.importer
+ * @category   Community Framework
+ */
+class ConversationImporter implements IImporter {
+       /**
+        * @see wcf\system\importer\IImporter::import()
+        */
+       public function import($oldID, array $data) {
+               $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
+               
+               // check existing conversation
+               $existingConversation = new Conversation($oldID);
+               if (!$existingConversation->conversationID) $data['conversationID'] = $oldID;
+               
+               $conversation = ConversationEditor::create($data);
+               
+               ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.conversation', $oldID, $conversation->conversationID);
+               
+               return $conversation->conversationID;
+       }
+}
diff --git a/files/lib/system/importer/ConversationLabelImporter.class.php b/files/lib/system/importer/ConversationLabelImporter.class.php
new file mode 100644 (file)
index 0000000..0e99030
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\conversation\label\ConversationLabelAction;
+
+/**
+ * Imports conversation labels.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.conversation
+ * @subpackage system.importer
+ * @category   Community Framework
+ */
+class ConversationLabelImporter implements IImporter {
+       /**
+        * @see wcf\system\importer\IImporter::import()
+        */
+       public function import($oldID, array $data) {
+               $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
+               if (!$data['userID']) return 0;
+               
+               $action = new ConversationLabelAction(array(), 'create', array(
+                       'data' => $data         
+               ));
+               $returnValues = $action->executeAction();
+               $newID = $returnValues['returnValues']->label;
+               
+               ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.conversation.label', $oldID, $newID);
+               
+               return $newID;
+       }
+}
diff --git a/files/lib/system/importer/ConversationMessageImporter.class.php b/files/lib/system/importer/ConversationMessageImporter.class.php
new file mode 100644 (file)
index 0000000..de10d0f
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\conversation\message\ConversationMessage;
+use wcf\data\conversation\message\ConversationMessageEditor;
+
+/**
+ * Imports conversation messages.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.conversation
+ * @subpackage system.importer
+ * @category   Community Framework
+ */
+class ConversationMessageImporter implements IImporter {
+       /**
+        * @see wcf\system\importer\IImporter::import()
+        */
+       public function import($oldID, array $data) {
+               $data['conversationID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.conversation', $data['conversationID']);
+               if (!$data['conversationID']) return 0;
+               $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
+                
+               // check existing message
+               $existingMessage = new ConversationMessage($oldID);
+               if (!$existingMessage->messageID) $data['messageID'] = $oldID;
+               
+               $message = ConversationMessageEditor::create($data);
+               
+               ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.conversation.message', $oldID, $message->messageID);
+               
+               return $message->messageID;
+       }
+}
diff --git a/files/lib/system/importer/ConversationUserImporter.class.php b/files/lib/system/importer/ConversationUserImporter.class.php
new file mode 100644 (file)
index 0000000..7d5742b
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\conversation\Conversation;
+use wcf\data\conversation\ConversationEditor;
+use wcf\system\WCF;
+
+/**
+ * Imports conversation users.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.conversation
+ * @subpackage system.importer
+ * @category   Community Framework
+ */
+class ConversationUserImporter implements IImporter {
+       /**
+        * @see wcf\system\importer\IImporter::import()
+        */
+       public function import($oldID, array $data) {
+               $data['conversationID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.conversation', $data['conversationID']);
+               if (!$data['conversationID']) return 0;
+               $data['participantID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['participantID']);
+               
+               $sql = "INSERT INTO             wcf".WCF_N."_conversation_to_user
+                                               (conversationID, participantID, hideConversation, isInvisible, lastVisitTime)
+                       VALUES                  (?, ?, ?)";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array(
+                       $data['conversationID'],
+                       $data['participantID'],
+                       $data['hideConversation'],
+                       $data['isInvisible'],
+                       $data['lastVisitTime']
+               ));
+               
+               // save labels
+               if ($data['participantID'] && !empty($data['labelIDs'])) {
+                       $sql = "INSERT INTO             wcf".WCF_N."_conversation_label_to_object
+                                                       (labelID, conversationID)
+                               VALUES                  (?, ?)";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       foreach ($data['labelIDs'] as $labelIDs) {
+                               $labelID = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.conversation.label', $labelID);
+                               if ($labelID) $statement->execute(array($labelID, $data['conversationID']));
+                       }
+               }
+               
+               return 1;
+       }
+}
index 6b55088aae8cfc86cfc082683ad8884c79efd2b0..83e22a37c446a0400b67a61df3b576dd17403bfb 100644 (file)
                        <languagevariable>wcf.user.usersOnline.location.ConversationMessageEditForm</languagevariable>
                </type>
                <!-- /user online locations -->
+               
+               <!-- importers -->
+               <type>
+                       <name>com.woltlab.wcf.conversation</name>
+                       <definitionname>com.woltlab.wcf.importer</definitionname>
+                       <classname><![CDATA[wcf\system\importer\ConversationImporter]]></classname>
+               </type>
+               <type>
+                       <name>com.woltlab.wcf.conversation.label</name>
+                       <definitionname>com.woltlab.wcf.importer</definitionname>
+                       <classname><![CDATA[wcf\system\importer\ConversationLabelImporter]]></classname>
+               </type>
+               <type>
+                       <name>com.woltlab.wcf.conversation.message</name>
+                       <definitionname>com.woltlab.wcf.importer</definitionname>
+                       <classname><![CDATA[wcf\system\importer\ConversationMessageImporter]]></classname>
+               </type>
+               <type>
+                       <name>com.woltlab.wcf.conversation.user</name>
+                       <definitionname>com.woltlab.wcf.importer</definitionname>
+                       <classname><![CDATA[wcf\system\importer\ConversationUserImporter]]></classname>
+               </type>
+               <type>
+                       <name>com.woltlab.wcf.conversation.attachment</name>
+                       <definitionname>com.woltlab.wcf.importer</definitionname>
+                       <classname><![CDATA[wcf\system\importer\ConversationAttachmentImporter]]></classname>
+               </type>
+               <!-- /importers -->
        </import>
 </data>
\ No newline at end of file