<?php
namespace wcf\system\importer;
+use wcf\data\package\PackageCache;
+use wcf\system\WCF;
/**
* Basic implementation of IImporter.
public function getClassName() {
return $this->className;
}
+
+ /**
+ * Imports a list of language items.
+ *
+ * @param string[][] $items
+ * @param string $languageCategory
+ * @param string $package
+ */
+ protected function importI18nValues(array $items, $languageCategory, $package) {
+ // get package id
+ $packageID = PackageCache::getInstance()->getPackageID($package);
+
+ $sql = "INSERT INTO wcf".WCF_N."_language_item
+ (languageID, languageItem, languageItemValue, languageCategoryID, packageID)
+ VALUES (?, ?, ?, ?, ?)
+ ON DUPLICATE KEY
+ UPDATE languageItemValue = VALUES(languageItemValue)";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ WCF::getDB()->beginTransaction();
+ foreach ($items as $itemData) {
+ $statement->execute([
+ $itemData['languageID'],
+ $itemData['languageItem'],
+ $itemData['languageItemValue'],
+ $this->getLanguageCategoryID($languageCategory),
+ $packageID
+ ]);
+ }
+ WCF::getDB()->commitTransaction();
+ }
+
+ /**
+ * Returns the language category id.
+ *
+ * @param string $languageCategory
+ * @return integer
+ */
+ protected function getLanguageCategoryID($languageCategory) {
+ static $languageCategoryIDs = [];
+
+ if (!isset($languageCategoryIDs[$languageCategory])) {
+ // get language category id
+ $sql = "SELECT languageCategoryID
+ FROM wcf" . WCF_N . "_language_category
+ WHERE languageCategory = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute([$languageCategory]);
+
+ $languageCategoryIDs[$languageCategory] = $statement->fetchSingleColumn();
+ }
+
+ return $languageCategoryIDs[$languageCategory];
+ }
}
namespace wcf\system\importer;
use wcf\data\user\group\UserGroup;
use wcf\data\user\group\UserGroupAction;
+use wcf\data\user\group\UserGroupEditor;
/**
* Imports user groups.
*
- * @author Marcel Werk
+ * @author Alexander Ebert, Marcel Werk
* @copyright 2001-2017 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package WoltLabSuite\Core\System\Importer
'data' => $data
]);
$returnValues = $action->executeAction();
- $newGroupID = $returnValues['returnValues']->groupID;
+ $group = $returnValues['returnValues'];
+ $newGroupID = $group->groupID;
+
+ // handle i18n values
+ if (!empty($additionalData['i18n'])) {
+ $values = [];
+
+ foreach (['groupName', 'groupDescription'] as $property) {
+ if (isset($additionalData['i18n'][$property])) {
+ $values[$property] = $additionalData['i18n'][$property];
+ }
+ }
+
+ if (!empty($values)) {
+ $updateData = [];
+ if (isset($values['groupName'])) $updateData['groupName'] = 'wcf.acp.group.group' . $newGroupID;
+ if (isset($values['groupDescription'])) $updateData['groupDescription'] = 'wcf.acp.group.groupDescription' . $newGroupID;
+
+ $items = [];
+ foreach ($values as $property => $propertyValues) {
+ foreach ($propertyValues as $languageID => $languageItemValue) {
+ $items[] = [
+ 'languageID' => $languageID,
+ 'languageItem' => 'wcf.acp.group.' . ($property === 'description' ? 'groupDescription' : 'group') . $newGroupID,
+ 'languageItemValue' => $languageItemValue
+ ];
+ }
+ }
+
+ $this->importI18nValues($items, 'wcf.acp.group', 'com.woltlab.wcf');
+
+ (new UserGroupEditor($group))->update($updateData);
+ }
+ }
}
ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user.group', $oldID, $newGroupID);