/
ImportBoardSlotTemplatesRoutine.php
51 lines (45 loc) · 1.83 KB
/
ImportBoardSlotTemplatesRoutine.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
<?php
namespace Concrete\Core\Backup\ContentImporter\Importer\Routine;
use Concrete\Core\Entity\Board\SlotTemplate;
use Concrete\Core\Entity\Design\DesignTag;
class ImportBoardSlotTemplatesRoutine extends AbstractRoutine
{
public function getHandle()
{
return 'board_slot_templates';
}
public function import(\SimpleXMLElement $sx)
{
$em = \Database::connection()->getEntityManager();
$tagRepository = $em->getRepository(DesignTag::class);
if (isset($sx->boardslottemplates)) {
foreach ($sx->boardslottemplates->template as $bt) {
$pkg = static::getPackageObject($bt['package']);
$name = (string) $bt['name'];
$icon = (string) $bt['icon'];
$handle = (string) $bt['handle'];
$template = $em->getRepository(SlotTemplate::class)->findOneByHandle($handle);
if (!$template) {
$template = new SlotTemplate();
$template->setIcon($icon);
$template->setHandle($handle);
$template->setName($name);
$template->setPackage($pkg);
if (isset($bt->tags)) {
foreach ($bt->tags->children() as $templateTag) {
$templateTagValue = (string) $templateTag['value'];
if ($templateTagValue !== null) {
$tag = $tagRepository->findOneByValue($templateTagValue);
if ($tag) {
$template->getTags()->add($tag);
}
}
}
}
$em->persist($template);
}
}
}
$em->flush();
}
}