9b058879f4091484b203c400609b0a5836308073
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / lib / system / importer / ConversationAttachmentImporter.class.php
1 <?php
2 namespace wcf\system\importer;
3 use wcf\data\conversation\message\ConversationMessage;
4 use wcf\data\conversation\message\ConversationMessageEditor;
5 use wcf\data\object\type\ObjectTypeCache;
6 use wcf\util\StringUtil;
7
8 /**
9 * Imports conversation attachments.
10 *
11 * @author Marcel Werk
12 * @copyright 2001-2013 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package com.woltlab.wcf.conversation
15 * @subpackage system.importer
16 * @category Community Framework
17 */
18 class ConversationAttachmentImporter extends AbstractAttachmentImporter {
19 /**
20 * Creates a new ConversationAttachmentImporter object.
21 */
22 public function __construct() {
23 $objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'com.woltlab.wcf.conversation.message');
24 $this->objectTypeID = $objectType->objectTypeID;
25 }
26
27 /**
28 * @see \wcf\system\importer\IImporter::import()
29 */
30 public function import($oldID, array $data, array $additionalData = array()) {
31 $data['objectID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.conversation.message', $data['objectID']);
32 if (!$data['objectID']) return 0;
33
34 $attachmentID = parent::import($oldID, $data, $additionalData);
35 if ($attachmentID && $attachmentID != $oldID) {
36 // fix embedded attachments
37 $messageObj = new ConversationMessage($data['objectID']);
38
39 if (($newMessage = $this->fixEmbeddedAttachments($messageObj->message, $oldID, $attachmentID)) !== false) {
40 $editor = new ConversationMessageEditor($messageObj);
41 $editor->update(array(
42 'message' => $newMessage
43 ));
44 }
45 }
46
47 return $attachmentID;
48 }
49 }