/
ImportPackagesRoutine.php
54 lines (46 loc) · 1.92 KB
/
ImportPackagesRoutine.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\Type;
use Concrete\Core\Block\BlockType\BlockType;
use Concrete\Core\Package\Package;
use Concrete\Core\Permission\Category;
use Concrete\Core\Support\Facade\Facade;
use Concrete\Core\Validation\BannedWord\BannedWord;
use Concrete\Core\Package\PackageService;
use Concrete\Core\Validation\CSRF\Token;
class ImportPackagesRoutine extends AbstractRoutine
{
public function getHandle()
{
return 'packages';
}
public function import(\SimpleXMLElement $sx)
{
if (isset($sx->packages)) {
foreach ($sx->packages->package as $p) {
$pkg = Package::getByHandle((string) $p['handle']);
if (!$pkg) {
$pkgClass = Package::getClass((string) $p['handle']);
if ($pkgClass) {
$app = Facade::getFacadeApplication();
$service = $app->make(PackageService::class);
/** @var Token $token */
$token = $app->make(Token::class);
$data = [];
if (isset($p['full-content-swap'])) {
$data["pkgDoFullContentSwap"] = true;
// set this token to perform a full content swap when installing starting point packages
$data["ccm_token"] = $token->generate("install_options_selected");
if (isset($p['content-swap-file'])) {
$data["contentSwapFile"] = (string)$p['content-swap-file'];
} else {
$data["contentSwapFile"] = "content.xml";
}
}
$service->install($pkgClass, $data);
}
}
}
}
}
}