--- /dev/null
+<?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;
+ }
+}
--- /dev/null
+<?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;
+ }
+}
--- /dev/null
+<?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;
+ }
+}
--- /dev/null
+<?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;
+ }
+}
--- /dev/null
+<?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;
+ }
+}
<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