Commit | Line | Data |
---|---|---|
303387f6 | 1 | <?php |
a9229942 | 2 | |
303387f6 | 3 | namespace wcf\system\importer; |
a9229942 | 4 | |
157054c9 | 5 | use wcf\data\category\Category; |
c2836ca3 | 6 | use wcf\data\category\CategoryEditor; |
93f4707b AE |
7 | use wcf\data\object\type\ObjectTypeCache; |
8 | use wcf\data\package\Package; | |
9 | use wcf\data\package\PackageCache; | |
303387f6 MW |
10 | |
11 | /** | |
12 | * Imports categories. | |
a9229942 TD |
13 | * |
14 | * @author Marcel Werk | |
15 | * @copyright 2001-2019 WoltLab GmbH | |
16 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
17 | * @package WoltLabSuite\Core\System\Importer | |
303387f6 | 18 | */ |
a9229942 TD |
19 | class AbstractCategoryImporter extends AbstractImporter |
20 | { | |
21 | /** | |
22 | * @inheritDoc | |
23 | */ | |
24 | protected $className = Category::class; | |
25 | ||
26 | /** | |
27 | * object type id for categories | |
28 | * @var int | |
29 | */ | |
30 | protected $objectTypeID = 0; | |
31 | ||
32 | /** | |
33 | * object type name | |
34 | * @var int | |
35 | */ | |
36 | protected $objectTypeName = ''; | |
37 | ||
38 | /** | |
39 | * @inheritDoc | |
40 | */ | |
41 | public function import($oldID, array $data, array $additionalData = []) | |
42 | { | |
43 | if (!empty($data['parentCategoryID'])) { | |
44 | $data['parentCategoryID'] = ImportHandler::getInstance() | |
45 | ->getNewID($this->objectTypeName, $data['parentCategoryID']); | |
46 | } | |
47 | ||
48 | $category = CategoryEditor::create(\array_merge($data, ['objectTypeID' => $this->objectTypeID])); | |
49 | ||
50 | // handle i18n values | |
51 | if (!empty($additionalData['i18n'])) { | |
52 | $values = []; | |
53 | ||
54 | foreach (['title', 'description'] as $property) { | |
55 | if (isset($additionalData['i18n'][$property])) { | |
56 | $values[$property] = $additionalData['i18n'][$property]; | |
57 | } | |
58 | } | |
59 | ||
60 | if (!empty($values)) { | |
61 | /** @var Package $package */ | |
62 | $package = null; | |
63 | if ($this->objectTypeID) { | |
64 | $objectType = ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID); | |
65 | $package = PackageCache::getInstance()->getPackage($objectType->packageID); | |
66 | } | |
67 | ||
68 | if ($package !== null) { | |
69 | $updateData = []; | |
70 | if (isset($values['title'])) { | |
71 | $updateData['title'] = 'wcf.category.category.title.category' . $category->categoryID; | |
72 | } | |
73 | if (isset($values['description'])) { | |
74 | $updateData['description'] = 'wcf.category.category.description.category' . $category->categoryID; | |
75 | } | |
76 | ||
77 | $items = []; | |
78 | foreach ($values as $property => $propertyValues) { | |
79 | foreach ($propertyValues as $languageID => $languageItemValue) { | |
80 | $items[] = [ | |
81 | 'languageID' => $languageID, | |
82 | 'languageItem' => 'wcf.category.category.' . ($property === 'description' ? 'description' : 'title') . '.category' . $category->categoryID, | |
83 | 'languageItemValue' => $languageItemValue, | |
84 | ]; | |
85 | } | |
86 | } | |
87 | ||
88 | $this->importI18nValues($items, 'wcf.category', $package->package); | |
89 | ||
90 | (new CategoryEditor($category))->update($updateData); | |
91 | } | |
92 | } | |
93 | } | |
94 | ||
95 | ImportHandler::getInstance()->saveNewID($this->objectTypeName, $oldID, $category->categoryID); | |
96 | ||
97 | return $category->categoryID; | |
98 | } | |
303387f6 | 99 | } |