-
Notifications
You must be signed in to change notification settings - Fork 452
/
ImportPageContentRoutine.php
65 lines (57 loc) · 1.99 KB
/
ImportPageContentRoutine.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
<?php
namespace Concrete\Core\Backup\ContentImporter\Importer\Routine;
use Concrete\Core\Attribute\Key\CollectionKey;
use Concrete\Core\Attribute\Type;
use Concrete\Core\Block\BlockType\BlockType;
use Concrete\Core\Page\Page;
use Concrete\Core\Permission\Category;
use Concrete\Core\Validation\BannedWord\BannedWord;
class ImportPageContentRoutine extends AbstractPageContentRoutine implements SpecifiableHomePageRoutineInterface
{
public function getHandle()
{
return 'page_content';
}
/**
* Useful when we're calling this from another routine that imports a new home page.
* @param $c
*/
public function setHomePage($c)
{
$this->home = $c;
}
public function import(\SimpleXMLElement $sx)
{
$siteTree = null;
if (isset($this->home)) {
$siteTree = $this->home->getSiteTreeObject();
}
if (isset($sx->pages)) {
foreach ($sx->pages->page as $px) {
if ($px['path'] != '') {
$page = Page::getByPath($px['path'], 'RECENT', $siteTree);
} else {
if (isset($this->home)) {
$page = $this->home;
} else {
$page = Page::getByID(Page::getHomePageID(), 'RECENT');
}
}
if (isset($px->area)) {
$this->importPageAreas($page, $px);
}
if (isset($px->attributes)) {
foreach ($px->attributes->children() as $attr) {
$handle = (string) $attr['handle'];
$ak = CollectionKey::getByHandle($handle);
if (is_object($ak)) {
$value = $ak->getController()->importValue($attr);
$page->setAttribute($handle, $value);
}
}
}
$page->reindex();
}
}
}
}