/
ImportExpressEntitiesRoutine.php
72 lines (64 loc) · 3.24 KB
/
ImportExpressEntitiesRoutine.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Concrete\Core\Backup\ContentImporter\Importer\Routine;
use Concrete\Core\Attribute\Category\ExpressCategory;
use Concrete\Core\Block\BlockType\BlockType;
use Concrete\Core\Entity\Express\Entity;
use Concrete\Core\Permission\Category;
use Concrete\Core\Support\Facade\Facade;
use Concrete\Core\Tree\Type\ExpressEntryResults;
use Concrete\Core\Validation\BannedWord\BannedWord;
use Doctrine\ORM\Id\UuidGenerator;
class ImportExpressEntitiesRoutine extends AbstractRoutine
{
public function getHandle()
{
return 'express_entities';
}
public function import(\SimpleXMLElement $sx)
{
$em = \Database::connection()->getEntityManager();
$em->getClassMetadata('Concrete\Core\Entity\Express\Entity')->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
if (isset($sx->expressentities)) {
foreach ($sx->expressentities->entity as $entityNode) {
$entity = $em->find('Concrete\Core\Entity\Express\Entity', (string) $entityNode['id']);
if (!is_object($entity)) {
$entity = new Entity();
$entity->setId((string) $entityNode['id']);
$tree = ExpressEntryResults::get();
$node = $tree->getNodeByDisplayPath((string) $entityNode['results-folder']);
$node = \Concrete\Core\Tree\Node\Type\ExpressEntryResults::add((string) $entityNode['name'], $node);
$entity->setEntityResultsNodeId($node->getTreeNodeID());
}
$entity->setPluralHandle((string) $entityNode['plural_handle']);
$entity->setHandle((string) $entityNode['handle']);
$entity->setDescription((string) $entityNode['description']);
$entity->setName((string) $entityNode['name']);
$entity->setPackage(static::getPackageObject($entityNode['package']));
if (((string) $entityNode['include_in_public_list']) == '') {
$entity->setIncludeInPublicList(false);
}
if (((string) $entityNode['use_separate_site_result_buckets']) === '1') {
$entity->setUseSeparateSiteResultBuckets(true);
}
$entity->setHandle((string) $entityNode['handle']);
$em->persist($entity);
// Import the attributes
if (isset($entityNode->attributekeys)) {
$app = Facade::getFacadeApplication();
$category = new ExpressCategory($entity, $app, $em);
foreach($entityNode->attributekeys->attributekey as $keyNode) {
$attributeKey = $category->getAttributeKeyByHandle((string) $keyNode['handle']);
if (!$attributeKey) {
$type = $app->make('Concrete\Core\Attribute\TypeFactory')->getByHandle(
(string)$keyNode['type']
);
$category->import($type, $keyNode);
}
}
}
}
}
$em->flush();
$em->getClassMetadata('Concrete\Core\Entity\Express\Entity')->setIdGenerator(new UuidGenerator());
}
}