Add importer for trophies
authorJoshua Rüsweg <josh@bastelstu.be>
Mon, 27 Nov 2017 20:02:13 +0000 (21:02 +0100)
committerJoshua Rüsweg <josh@bastelstu.be>
Mon, 27 Nov 2017 20:03:15 +0000 (21:03 +0100)
See #2485

com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/system/importer/TrophyCategoryImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/TrophyImporter.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/importer/UserTrophyImporter.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index f2884c29a23c63fb925293885f23c9b3c7158cb2..85dc78abc0b05feb9a522b296a9d414efa0f36b3 100644 (file)
                        <definitionname>com.woltlab.wcf.importer</definitionname>
                        <classname>wcf\system\importer\ArticleCommentResponseImporter</classname>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.trophy.category</name>
+                       <definitionname>com.woltlab.wcf.importer</definitionname>
+                       <classname>wcf\system\importer\TrophyCategoryImporter</classname>
+               </type>
+               <type>
+                       <name>com.woltlab.wcf.trophy</name>
+                       <definitionname>com.woltlab.wcf.importer</definitionname>
+                       <classname>wcf\system\importer\TrophyImporter</classname>
+               </type>
+               <type>
+                       <name>com.woltlab.wcf.userTrophy</name>
+                       <definitionname>com.woltlab.wcf.importer</definitionname>
+                       <classname>wcf\system\importer\UserTrophyImporter</classname>
+               </type>
                <!-- /importers -->
                
                <!-- rebuild data workers -->
diff --git a/wcfsetup/install/files/lib/system/importer/TrophyCategoryImporter.class.php b/wcfsetup/install/files/lib/system/importer/TrophyCategoryImporter.class.php
new file mode 100644 (file)
index 0000000..974c13f
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\object\type\ObjectTypeCache;
+
+/**
+ * Represents a trophy category importer.
+ *
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Importer
+ * @since      3.1
+ */
+class TrophyCategoryImporter extends AbstractCategoryImporter {
+       /**
+        * @inheritDoc
+        */
+       protected $objectTypeName = 'com.woltlab.wcf.trophy.category';
+       
+       /**
+        * Creates a new TrophyCategoryImporter object.
+        */
+       public function __construct() {
+               $objectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.category', $this->objectTypeName);
+               $this->objectTypeID = $objectType->objectTypeID;
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/importer/TrophyImporter.class.php b/wcfsetup/install/files/lib/system/importer/TrophyImporter.class.php
new file mode 100644 (file)
index 0000000..974c41c
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\trophy\Trophy;
+use wcf\data\trophy\TrophyEditor;
+use wcf\system\WCF;
+use wcf\util\StringUtil;
+
+/**
+ * Represents a trophy importer.
+ *
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Importer
+ * @since      3.1
+ */
+class TrophyImporter extends AbstractImporter {
+       /**
+        * @inheritDoc
+        */
+       protected $className = Trophy::class;
+       
+       /**
+        * category for orphaned trophies
+        * @var integer
+        */
+       private $importCategoryID = 0;
+       
+       /**
+        * @inheritDoc
+        */
+       public function import($oldID, array $data, array $additionalData = []) {
+               if (isset($data['categoryID'])) {
+                       $data['categoryID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.trophy.category', $data['categoryID']);
+               }
+               
+               if (!$data['categoryID']) {
+                       $data['categoryID'] = $this->getImportCategoryID();
+               }
+               
+               if ($data['type'] == Trophy::TYPE_IMAGE) {
+                       if (!@file_exists($additionalData['fileLocation'])) {
+                               return 0;
+                       }
+                       
+                       $filename = basename($additionalData['fileLocation']);
+                       while (file_exists(WCF_DIR.'images/trophy/' . $filename)) {
+                               $filename = substr(StringUtil::getRandomID(), 0, 5) . '_' . basename($additionalData['fileLocation']);
+                       }
+                       
+                       if (!@copy($additionalData['fileLocation'], WCF_DIR.'images/trophy/' . $filename)) {
+                               return 0;
+                       }
+                       
+                       $data['iconFile'] = $filename;
+               }
+               
+               $trophy = TrophyEditor::create($data);
+               
+               if (!empty($additionalData['i18n'])) {
+                       $values = [];
+                       
+                       foreach (['title', 'description'] as $property) {
+                               if (isset($additionalData['i18n'][$property])) {
+                                       $values[$property] = $additionalData['i18n'][$property];
+                               }
+                       }
+                       
+                       if (!empty($values)) {
+                               $updateData = [];
+                               if (isset($values['title'])) $updateData['title'] = 'wcf.user.trophy.title' . $trophy->trophyID;
+                               if (isset($values['description'])) $updateData['description'] = 'wcf.user.trophy.description' . $trophy->trophyID;
+                               
+                               $items = [];
+                               foreach ($values as $property => $propertyValues) {
+                                       foreach ($propertyValues as $languageID => $languageItemValue) {
+                                               $items[] = [
+                                                       'languageID' => $languageID,
+                                                       'languageItem' => 'wcf.user.trophy.' . $property . $trophy->trophyID,
+                                                       'languageItemValue' => $languageItemValue
+                                               ];
+                                       }
+                               }
+                               
+                               $this->importI18nValues($items, 'wcf.user.trophy', 'com.woltlab.wcf');
+                               
+                               (new TrophyEditor($trophy))->update($updateData);
+                       }
+               }
+               
+               ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.trophy', $oldID, $trophy->trophyID);
+               
+               return $trophy->trophyID;
+       }
+       
+       /**
+        * Returns a categoryID for trophies without categoryID.
+        *
+        * @return integer
+        */
+       private function getImportCategoryID() {
+               if (!$this->importCategoryID) {
+                       $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.category', 'com.woltlab.wcf.trophy.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;
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/importer/UserTrophyImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserTrophyImporter.class.php
new file mode 100644 (file)
index 0000000..b49726f
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+namespace wcf\system\importer;
+use wcf\data\user\trophy\UserTrophy;
+use wcf\data\user\trophy\UserTrophyEditor;
+
+/**
+ * Represents a user trophy importer.
+ *
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Importer
+ * @since      3.1
+ */
+class UserTrophyImporter extends AbstractImporter {
+       /**
+        * @inheritDoc
+        */
+       protected $className = UserTrophy::class;
+       
+       /**
+        * @inheritDoc
+        */
+       public function import($oldID, array $data, array $additionalData = []) {
+               if (isset($data['trophyID'])) {
+                       $data['trophyID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.trophy', $data['trophyID']);
+               }
+               
+               if (isset($data['userID'])) {
+                       $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
+               }
+               
+               if (!$data['userID'] || !$data['trophyID']) {
+                       return 0;
+               }
+               
+               $userTrophy = UserTrophyEditor::create($data);
+               
+               if (isset($additionalData['i18n']['description'])) {
+                       $updateData['description'] = 'wcf.user.trophy.description' . $userTrophy->userTrophyID;
+                       
+                       $items = [];
+                       foreach ($additionalData['i18n']['description'] as $languageID => $languageItemValue) {
+                               $items[] = [
+                                       'languageID' => $languageID,
+                                       'languageItem' => 'wcf.user.trophy.description' . $userTrophy->userTrophyID,
+                                       'languageItemValue' => $languageItemValue
+                               ];
+                       }
+                       
+                       
+                       $this->importI18nValues($items, 'wcf.user.trophy', 'com.woltlab.wcf');
+                       
+                       (new UserTrophyEditor($userTrophy))->update($updateData);
+               }
+               
+               ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.userTrophy', $oldID, $userTrophy->getObjectID());
+               
+               return $userTrophy->getObjectID();
+       }
+}
index d5f2226f9e1d4f10fe2956eb2b0036ddeeef9ed8..54ea8628b1ad9a4225ad8d10bd6270b96c3a8d2f 100644 (file)
                <item name="wcf.acp.dataImport.data.com.woltlab.wcf.article.category"><![CDATA[Artikel-Kategorien]]></item>
                <item name="wcf.acp.dataImport.data.com.woltlab.wcf.article.comment"><![CDATA[Artikel-Kommentare]]></item>
                <item name="wcf.acp.dataImport.data.com.woltlab.wcf.media"><![CDATA[Medien]]></item>
+               <item name="wcf.acp.dataImport.data.com.woltlab.wcf.trophy.category"><![CDATA[Trophäen-Kategorien]]></item>
+               <item name="wcf.acp.dataImport.data.com.woltlab.wcf.trophy"><![CDATA[Trophäen]]></item>
+               <item name="wcf.acp.dataImport.data.com.woltlab.wcf.userTrophy"><![CDATA[Vergebene Trophäen]]></item>
                <item name="wcf.acp.dataImport.existingMapping.confirmMessage"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} die bestehenden Zuordnungen wirklich löschen?]]></item>
                <item name="wcf.acp.dataImport.existingMapping.notice"><![CDATA[Es existieren Zuordnungen eines früheren Import-Vorganges, diese werden verwendet, um Inhalte aus dem importierten Forum einwandfrei zuzuordnen. Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} den Import-Vorgang vollständig abgeschlossen {if LANGUAGE_USE_INFORMAL_VARIANT}hast{else}haben{/if}, {if LANGUAGE_USE_INFORMAL_VARIANT}kannst du{else}können Sie{/if} diese Zuordnungen <a id="deleteMapping">löschen</a>. {if LANGUAGE_USE_INFORMAL_VARIANT}Du solltest{else}Sie sollten{/if} die Zuordnungen nicht löschen, wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} jetzt oder zukünftig noch weitere Inhalte aus dem selben Forum übernehmen {if LANGUAGE_USE_INFORMAL_VARIANT}willst{else}wollen{/if}.]]></item>
                <item name="wcf.acp.dataImport.exporter"><![CDATA[Datenquelle]]></item>
index d22bbeec2c42bd1c57536dac11b501d8fd677149..e5c8c94fcc0d49498318d42c3ea1db3ae776a5b2 100644 (file)
                <item name="wcf.acp.dataImport.data.com.woltlab.wcf.article.category"><![CDATA[Article categories]]></item>
                <item name="wcf.acp.dataImport.data.com.woltlab.wcf.article.comment"><![CDATA[Article comments]]></item>
                <item name="wcf.acp.dataImport.data.com.woltlab.wcf.media"><![CDATA[Media]]></item>
+               <item name="wcf.acp.dataImport.data.com.woltlab.wcf.trophy.category"><![CDATA[Trophy categories]]></item>
+               <item name="wcf.acp.dataImport.data.com.woltlab.wcf.trophy"><![CDATA[Trophies]]></item>
+               <item name="wcf.acp.dataImport.data.com.woltlab.wcf.userTrophy"><![CDATA[Assigned trophies]]></item>
                <item name="wcf.acp.dataImport.existingMapping.confirmMessage"><![CDATA[Do you really want to delete the existing import mappings?]]></item>
                <item name="wcf.acp.dataImport.existingMapping.notice"><![CDATA[There are import mappings created by a previous import process, these mappings are used to properly handle connections between data from the imported forum and this one. In case you have imported all the desired data, you can <a id="deleteMapping">delete</a> the mappings. It is strongly recommended to keep these mappings as long as there is still data to be imported now or in the future.]]></item>
                <item name="wcf.acp.dataImport.exporter"><![CDATA[Data Source]]></item>