From 0ce25d961af4e6ea01325478ab6b2a9e656e3bd8 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Wed, 3 Jul 2013 17:44:44 +0200 Subject: [PATCH] Added conversation import --- .../ConversationAttachmentImporter.class.php | 52 +++++++++++++++++++ .../importer/ConversationImporter.class.php | 33 ++++++++++++ .../ConversationLabelImporter.class.php | 33 ++++++++++++ .../ConversationMessageImporter.class.php | 35 +++++++++++++ .../ConversationUserImporter.class.php | 52 +++++++++++++++++++ objectType.xml | 28 ++++++++++ 6 files changed, 233 insertions(+) create mode 100644 files/lib/system/importer/ConversationAttachmentImporter.class.php create mode 100644 files/lib/system/importer/ConversationImporter.class.php create mode 100644 files/lib/system/importer/ConversationLabelImporter.class.php create mode 100644 files/lib/system/importer/ConversationMessageImporter.class.php create mode 100644 files/lib/system/importer/ConversationUserImporter.class.php diff --git a/files/lib/system/importer/ConversationAttachmentImporter.class.php b/files/lib/system/importer/ConversationAttachmentImporter.class.php new file mode 100644 index 0000000..361bca3 --- /dev/null +++ b/files/lib/system/importer/ConversationAttachmentImporter.class.php @@ -0,0 +1,52 @@ + + * @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 index 0000000..d448d72 --- /dev/null +++ b/files/lib/system/importer/ConversationImporter.class.php @@ -0,0 +1,33 @@ + + * @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 index 0000000..0e99030 --- /dev/null +++ b/files/lib/system/importer/ConversationLabelImporter.class.php @@ -0,0 +1,33 @@ + + * @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 index 0000000..de10d0f --- /dev/null +++ b/files/lib/system/importer/ConversationMessageImporter.class.php @@ -0,0 +1,35 @@ + + * @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 index 0000000..7d5742b --- /dev/null +++ b/files/lib/system/importer/ConversationUserImporter.class.php @@ -0,0 +1,52 @@ + + * @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; + } +} diff --git a/objectType.xml b/objectType.xml index 6b55088..83e22a3 100644 --- a/objectType.xml +++ b/objectType.xml @@ -87,5 +87,33 @@ wcf.user.usersOnline.location.ConversationMessageEditForm + + + + com.woltlab.wcf.conversation + com.woltlab.wcf.importer + + + + com.woltlab.wcf.conversation.label + com.woltlab.wcf.importer + + + + com.woltlab.wcf.conversation.message + com.woltlab.wcf.importer + + + + com.woltlab.wcf.conversation.user + com.woltlab.wcf.importer + + + + com.woltlab.wcf.conversation.attachment + com.woltlab.wcf.importer + + + \ No newline at end of file -- 2.20.1