<definitionname>com.woltlab.wcf.importer</definitionname>
<classname>wcf\system\importer\SmileyCategoryImporter</classname>
</type>
+ <type>
+ <name>com.woltlab.wcf.article.category</name>
+ <definitionname>com.woltlab.wcf.importer</definitionname>
+ <classname>wcf\system\importer\ArticleCategoryImporter</classname>
+ </type>
+ <type>
+ <name>com.woltlab.wcf.article</name>
+ <definitionname>com.woltlab.wcf.importer</definitionname>
+ <classname>wcf\system\importer\ArticleImporter</classname>
+ </type>
+ <type>
+ <name>com.woltlab.wcf.media</name>
+ <definitionname>com.woltlab.wcf.importer</definitionname>
+ <classname>wcf\system\importer\MediaImporter</classname>
+ </type>
+ <type>
+ <name>com.woltlab.wcf.article.comment</name>
+ <definitionname>com.woltlab.wcf.importer</definitionname>
+ <classname>wcf\system\importer\ArticleCommentImporter</classname>
+ </type>
+ <type>
+ <name>com.woltlab.wcf.article.comment.response</name>
+ <definitionname>com.woltlab.wcf.importer</definitionname>
+ <classname>wcf\system\importer\ArticleCommentResponseImporter</classname>
+ </type>
<!-- /importers -->
<!-- rebuild data workers -->
--- /dev/null
+<?php
+namespace wcf\system\importer;
+use wcf\data\object\type\ObjectTypeCache;
+
+/**
+ * Imports article categories.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Importer
+ */
+class ArticleCategoryImporter extends AbstractCategoryImporter {
+ /**
+ * @inheritDoc
+ */
+ protected $objectTypeName = 'com.woltlab.wcf.article.category';
+
+ /**
+ * Creates a new ArticleCategoryImporter object.
+ */
+ public function __construct() {
+ $objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.category', 'com.woltlab.wcf.article.category');
+ $this->objectTypeID = $objectType->objectTypeID;
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\importer;
+use wcf\data\article\Article;
+use wcf\data\object\type\ObjectTypeCache;
+
+/**
+ * Imports article comments.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Importer
+ */
+class ArticleCommentImporter extends AbstractCommentImporter {
+ /**
+ * @inheritDoc
+ */
+ protected $objectTypeName = 'com.woltlab.wcf.article.comment';
+
+ /**
+ * Creates a new ArticleCommentImporter object.
+ */
+ public function __construct() {
+ $objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.comment.commentableContent', 'com.woltlab.wcf.articleComment');
+ $this->objectTypeID = $objectType->objectTypeID;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function import($oldID, array $data, array $additionalData = []) {
+ $articleID = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.article', $additionalData['articleID']);
+ if (!$articleID) return 0;
+ $article = new Article($articleID);
+ $contents = $article->getArticleContents();
+ $data['objectID'] = reset($contents)->articleContentID;
+
+ return parent::import($oldID, $data);
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\importer;
+
+/**
+ * Imports article comment response.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Importer
+ */
+class ArticleCommentResponseImporter extends AbstractCommentResponseImporter {
+ /**
+ * @inheritDoc
+ */
+ protected $objectTypeName = 'com.woltlab.wcf.article.comment';
+}
--- /dev/null
+<?php
+namespace wcf\system\importer;
+use wcf\data\article\Article;
+use wcf\data\article\ArticleEditor;
+use wcf\data\article\content\ArticleContentEditor;
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\language\LanguageFactory;
+use wcf\system\tagging\TagEngine;
+use wcf\system\WCF;
+
+/**
+ * Imports cms articles.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Importer
+ */
+class ArticleImporter extends AbstractImporter {
+ /**
+ * @inheritDoc
+ */
+ protected $className = Article::class;
+
+ /**
+ * category for orphaned articles
+ * @var integer
+ */
+ private $importCategoryID = 0;
+
+ /**
+ * @inheritDoc
+ */
+ public function import($oldID, array $data, array $additionalData = []) {
+ $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
+
+ $contents = [];
+ foreach ($additionalData['contents'] as $languageCode => $contentData) {
+ $languageID = 0;
+ if ($languageCode) {
+ if (($language = LanguageFactory::getInstance()->getLanguageByCode($languageCode)) !== null) {
+ $languageID = $language->languageID;
+ }
+ else {
+ continue;
+ }
+ }
+
+ $imageID = null;
+ if (!empty($contentData['imageID'])) {
+ $imageID = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.media', $contentData['imageID']);
+ }
+
+ $contents[$languageID] = [
+ 'title' => (!empty($contentData['title']) ? $contentData['title'] : ''),
+ 'teaser' => (!empty($contentData['teaser']) ? $contentData['teaser'] : ''),
+ 'content' => (!empty($contentData['content']) ? $contentData['content'] : ''),
+ 'imageID' => $imageID,
+ 'tags' => (!empty($contentData['tags']) ? $contentData['tags'] : [])
+
+ ];
+ }
+ if (empty($contents)) return 0;
+ if (count($contents) > 1) {
+ $data['isMultilingual'] = 1;
+ }
+
+ // check old id
+ if (is_numeric($oldID)) {
+ $article = new Article($oldID);
+ if (!$article->articleID) $data['articleID'] = $oldID;
+ }
+
+ // category
+ $categoryID = 0;
+ if (!empty($data['categoryID'])) {
+ $categoryID = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.article.category', $data['categoryID']);
+ }
+ if (!$categoryID) {
+ $categoryID = $this->getImportCategoryID();
+ }
+ $data['categoryID'] = $categoryID;
+
+ // save article
+ $article = ArticleEditor::create($data);
+
+ // save article content
+ foreach ($contents as $languageID => $contentData) {
+ $articleContent = ArticleContentEditor::create([
+ 'articleID' => $article->articleID,
+ 'languageID' => $languageID ?: null,
+ 'title' => $contentData['title'],
+ 'teaser' => $contentData['teaser'],
+ 'content' => $contentData['content'],
+ 'imageID' => $contentData['imageID']
+ ]);
+
+ // save tags
+ if (!empty($contentData['tags'])) {
+ TagEngine::getInstance()->addObjectTags('com.woltlab.wcf.article', $articleContent->articleContentID, $contentData['tags'], $languageID ?: LanguageFactory::getInstance()->getDefaultLanguageID());
+ }
+ }
+
+ ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.article', $oldID, $article->articleID);
+ return $article->articleID;
+ }
+
+ /**
+ * Returns the id of the category used for articles without previous categories.
+ *
+ * @return integer
+ */
+ private function getImportCategoryID() {
+ if (!$this->importCategoryID) {
+ $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.category', 'com.woltlab.wcf.article.category');
+
+ $sql = "SELECT categoryID
+ FROM wcf".WCF_N."_category
+ WHERE objectTypeID = ?
+ AND parentCategoryID = ?
+ AND title = ?
+ ORDER BY categoryID";
+ $statement = WCF::getDB()->prepareStatement($sql, 1);
+ $statement->execute([$objectTypeID, 0, 'Import']);
+ $categoryID = $statement->fetchSingleColumn();
+ if ($categoryID) {
+ $this->importCategoryID = $categoryID;
+ }
+ else {
+ $sql = "INSERT INTO wcf".WCF_N."_category
+ (objectTypeID, parentCategoryID, title, showOrder, time)
+ VALUES (?, ?, ?, ?, ?)";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute([$objectTypeID, 0, 'Import', 0, TIME_NOW]);
+ $this->importCategoryID = WCF::getDB()->getInsertID("wcf".WCF_N."_category", 'categoryID');
+ }
+ }
+
+ return $this->importCategoryID;
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\importer;
+use wcf\data\media\Media;
+use wcf\data\media\MediaAction;
+use wcf\data\media\MediaEditor;
+use wcf\system\exception\SystemException;
+use wcf\system\language\LanguageFactory;
+use wcf\system\upload\DefaultUploadFileSaveStrategy;
+use wcf\system\WCF;
+
+/**
+ * Imports cms media.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Importer
+ */
+class MediaImporter extends AbstractImporter {
+ /**
+ * @inheritDoc
+ */
+ protected $className = Media::class;
+
+ /**
+ * @var DefaultUploadFileSaveStrategy
+ */
+ private $saveStrategy;
+
+ /**
+ * @inheritDoc
+ */
+ public function import($oldID, array $data, array $additionalData = []) {
+ $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
+
+ $contents = [];
+ foreach ($additionalData['contents'] as $languageCode => $contentData) {
+ $languageID = 0;
+ if (!$languageCode) {
+ if (($language = LanguageFactory::getInstance()->getLanguageByCode($languageCode)) !== null) {
+ $languageID = $language->languageID;
+ }
+ else {
+ continue;
+ }
+ }
+
+ $contents[$languageID] = [
+ 'title' => (!empty($contentData['title']) ? $contentData['title'] : ''),
+ 'caption' => (!empty($contentData['caption']) ? $contentData['caption'] : ''),
+ 'altText' => (!empty($contentData['altText']) ? $contentData['altText'] : '')
+ ];
+ }
+ if (count($contents) > 1) {
+ $data['isMultilingual'] = 1;
+ }
+
+ // handle language
+ if (!empty($additionalData['languageCode'])) {
+ if (($language = LanguageFactory::getInstance()->getLanguageByCode($additionalData['languageCode'])) !== null) {
+ $data['languageID'] = $language->languageID;
+ }
+ }
+
+ // check old id
+ if (is_numeric($oldID)) {
+ $media = new Media($oldID);
+ if (!$media->mediaID) $data['mediaID'] = $oldID;
+ }
+
+ // save media
+ $media = MediaEditor::create($data);
+
+ // check media directory
+ // and create subdirectory if necessary
+ $dir = dirname($media->getLocation());
+ if (!@file_exists($dir)) {
+ @mkdir($dir, 0777);
+ }
+
+ // copy file
+ try {
+ if (!copy($additionalData['fileLocation'], $media->getLocation())) {
+ throw new SystemException();
+ }
+ }
+ catch (SystemException $e) {
+ // copy failed; delete media
+ $editor = new MediaEditor($media);
+ $editor->delete();
+
+ return 0;
+ }
+
+ // save media content
+ $sql = "INSERT INTO wcf".WCF_N."_media_content
+ (mediaID, languageID, title, caption, altText)
+ VALUES (?, ?, ?, ?, ?)";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ foreach ($contents as $languageID => $contentData) {
+ $statement->execute([$media->mediaID, $languageID ?: null, $contentData['title'], $contentData['caption'], $contentData['altText']]);
+ }
+
+ // create thumbnails
+ if ($media->isImage) {
+ $this->getSaveStrategy()->generateThumbnails($media);
+ }
+
+ ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.media', $oldID, $media->mediaID);
+ return $media->mediaID;
+ }
+
+ /**
+ * @return DefaultUploadFileSaveStrategy
+ */
+ private function getSaveStrategy() {
+ if ($this->saveStrategy === null) {
+ $this->saveStrategy = new DefaultUploadFileSaveStrategy(MediaAction::class);
+ }
+
+ return $this->saveStrategy;
+ }
+}