Merge branch '3.1' into 5.2
[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
7 /**
8 * Imports conversation attachments.
9 *
10 * @author Marcel Werk
11 * @copyright 2001-2019 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\System\Importer
14 */
15 class ConversationAttachmentImporter extends AbstractAttachmentImporter {
16 /**
17 * Creates a new ConversationAttachmentImporter object.
18 */
19 public function __construct() {
20 $objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'com.woltlab.wcf.conversation.message');
21 $this->objectTypeID = $objectType->objectTypeID;
22 }
23
24 /**
25 * @inheritDoc
26 */
27 public function import($oldID, array $data, array $additionalData = []) {
28 $data['objectID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.conversation.message', $data['objectID']);
29 if (!$data['objectID']) return 0;
30
31 $attachmentID = parent::import($oldID, $data, $additionalData);
32 if ($attachmentID && $attachmentID != $oldID) {
33 // fix embedded attachments
34 $messageObj = new ConversationMessage($data['objectID']);
35
36 if (($newMessage = $this->fixEmbeddedAttachments($messageObj->message, $oldID, $attachmentID)) !== false) {
37 $editor = new ConversationMessageEditor($messageObj);
38 $editor->update([
39 'message' => $newMessage
40 ]);
41 }
42 }
43
44 return $attachmentID;
45 }
46 }