/
ImportAttributeSetsRoutine.php
54 lines (50 loc) · 1.88 KB
/
ImportAttributeSetsRoutine.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Concrete\Core\Backup\ContentImporter\Importer\Routine;
use Concrete\Core\Attribute\Category\CategoryService;
use Concrete\Core\Attribute\SetFactory;
use Concrete\Core\Support\Facade\Application;
use SimpleXMLElement;
class ImportAttributeSetsRoutine extends AbstractRoutine
{
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Backup\ContentImporter\Importer\Routine\RoutineInterface::getHandle()
*/
public function getHandle()
{
return 'attribute_sets';
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Backup\ContentImporter\Importer\Routine\RoutineInterface::import()
*/
public function import(SimpleXMLElement $sx)
{
if (isset($sx->attributesets)) {
$app = Application::getFacadeApplication();
$setFactory = $app->make(SetFactory::class);
$categoryService = $app->make(CategoryService::class);
foreach ($sx->attributesets->attributeset as $as) {
$set = $setFactory->getByHandle((string) $as['handle']);
$akc = $categoryService->getByHandle($as['category']);
$controller = $akc->getController();
$manager = $controller->getSetManager();
if ($set === null) {
$pkg = static::getPackageObject($as['package']);
$set = $manager->addSet((string) $as['handle'], (string) $as['name'], $pkg, $as['locked']);
}
foreach ($as->children() as $ask) {
$ak = $controller->getAttributeKeyByHandle((string) $ask['handle']);
if ($ak) {
$keySets = $setFactory->getByAttributeKey($ak);
if (empty($keySets)) {
$manager->addKey($set, $ak);
}
}
}
}
}
}
}