1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Installer.php
См. документацию.
1<?php
2
3namespace Bitrix\Landing\Mainpage;
4
5use Bitrix\AI\Integration;
6use Bitrix\Landing;
7use Bitrix\Landing\Site\Type;
8use Bitrix\Main\Loader;
9use Bitrix\Rest\AppTable;
10use Bitrix\Rest\Configuration\Action\Import;
11use Bitrix\Rest\Marketplace;
12
17{
18 private const DEFAULT_TEMPLATE = 'empty';
19
20 private int $siteId;
21
22 public function __construct(int $siteId)
23 {
24 $this->siteId = $siteId;
25 }
26
27 public function createDemoPage(): ?int
28 {
29 $result = Landing\Landing::addByTemplate(
30 $this->siteId,
31 self::DEFAULT_TEMPLATE,
32 [
33 'SITE_TYPE' => Type::SCOPE_CODE_MAINPAGE,
34 ]
35 );
36 if (
37 !$result->isSuccess()
38 || !$result->getId()
39 )
40 {
41 return null;
42 }
43
44 return (int)$result->getId();
45 }
46
47 public function createPageByTemplate(Templates $code): ?int
48 {
49 if (!Loader::includeModule('rest'))
50 {
51 return false;
52 }
53
55 if (!$appCode)
56 {
57 return null;
58 }
59
60 $app = AppTable::getByClientId($appCode);
61 $isAppInstalled =
62 !empty($app['ACTIVE'])
63 && $app['ACTIVE'] === 'Y'
64 && !empty($app['INSTALLED'])
65 && $app['INSTALLED'] === 'Y';
66 if (!$isAppInstalled)
67 {
68 $installResult = Marketplace\Application::install($appCode);
69 if (
70 !isset($installResult['success'])
71 || !$installResult['success']
72 || isset($installResult['error'])
73 )
74 {
75 return null;
76 }
77 }
78
79 $appSite = Marketplace\Client::getSiteList([
80 'code' => $appCode,
81 'siteType' => mb_strtolower(Type::SCOPE_CODE_MAINPAGE),
82 ]);
83 $zipId = (int)($appSite['ITEMS'][0]['ID'] ?? 0);
84 if ($zipId <= 0)
85 {
86 return null;
87 }
88
89 ob_start();
91 $componentName = 'bitrix:rest.configuration.import';
92 $className = \CBitrixComponent::includeComponentClass($componentName);
93 $importComponent = new $className;
94 $importComponent->initComponent($componentName);
95 $importComponent->arParams = [
96 'ZIP_ID' => $zipId,
97 'ADDITIONAL' => [
98 'siteId' => $this->siteId,
99 ],
100 'MODE' => 'ZIP',
101 'SET_TITLE' => 'Y',
102 ];
103 $importComponent->executeComponent();
104 ob_end_clean();
105
106 $importId = $importComponent->arResult['IMPORT_PROCESS_ID'] ?? null;
107 if (!$importId)
108 {
109 return null;
110 }
111
112 $importId = (int)$importId;
113 $import = new Import($importId);
114 $newLandingId = null;
115 while (true)
116 {
117 if (!$newLandingId)
118 {
119 $ratio = $import->getSetting()->get('SETTING_RATIO');
120 if (
121 $ratio
122 && isset($ratio['LANDING']['SPECIAL_PAGES']['LANDING_ID_INDEX'])
123 )
124 {
125 $landingIdByTemplate = $ratio['LANDING']['SPECIAL_PAGES']['LANDING_ID_INDEX'];
126 $newLandingId = $ratio['LANDING']['LANDINGS'][$landingIdByTemplate] ?? null;
127 }
128 }
129
130 $data = $import->get();
131 if ($data['status'] !== 'F' && $data['status'] !== 'E' && $data['status'] !== 'U')
132 {
133 Import::runAgent($importId);
134 }
135 else
136 {
137 break;
138 }
139 }
140
141 return $newLandingId;
142 }
143}
__construct(int $siteId)
Определения Installer.php:22
static runAgent(int $processId)
Определения base.php:448
$componentName
Определения component_props2.php:49
$data['IS_AVAILABLE']
Определения .description.php:13
$result
Определения get_property_values.php:14
$app
Определения proxy.php:8
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$siteId
Определения ajax.php:8
Templates
Определения Templates.php:8