6use \Bitrix\Landing\Hook;
7use \Bitrix\Landing\Template;
8use \Bitrix\Landing\TemplateRef;
9use \Bitrix\Landing\PublicAction;
10use \Bitrix\Landing\Site\Type;
11use \Bitrix\Landing\Transfer\AppConfiguration;
12use \Bitrix\Rest\Marketplace;
13use \Bitrix\Main\Event;
38 public static function getUrl(
string $type,
int $siteId): string
40 if (!\
Bitrix\Main\Loader::includeModule(
'rest'))
44 return Marketplace\Url::getConfigurationExportElementUrl(
45 AppConfiguration::PREFIX_CODE . strtolower($type), $siteId
58 $res = \Bitrix\Rest\AppTable::getList([
66 while ($row = $res->fetch())
68 $appIds[$row[
'CODE']] = $row[
'ID'];
82 $siteType = substr($code, strlen(AppConfiguration::PREFIX_CODE));
87 $usedApp = PublicAction::getRestStat(
89 $siteId ? [
'SITE_ID' => $siteId] : []
91 $usedApp = array_merge(
92 array_keys($usedApp[PublicAction::REST_USAGE_TYPE_BLOCK]),
93 array_keys($usedApp[PublicAction::REST_USAGE_TYPE_PAGE])
95 $usedApp = array_unique($usedApp);
98 $usedApp = array_values(self::getRestAppIds($usedApp));
106 'SITE_ID' => $siteId,
107 'SITE_TYPE' => $siteType,
108 'APP_USES_REQUIRED' => $usedApp
114 $res = SiteCore::getList([
121 'limit' => self::MAX_SITE_FOR_EXPORT
123 while ($row = $res->fetch())
125 $lastSiteId = $row[
'ID'];
129 'FINISH_ID' => $lastSiteId,
130 'APP_USES_REQUIRED' => $usedApp
141 private static function getFolders(
int $siteId): array
145 foreach (SiteCore::getFolders($siteId) as $folder)
147 $folders[$folder[
'ID']] = [
148 'PARENT_ID' => $folder[
'PARENT_ID'],
149 'ACTIVE' => $folder[
'ACTIVE'],
150 'TITLE' => $folder[
'TITLE'],
151 'CODE' => $folder[
'CODE'],
152 'INDEX_ID' => $folder[
'INDEX_ID']
168 $site = SiteCore::getList([
178 $site[
'DATE_CREATE'] = (string)$site[
'DATE_CREATE'];
179 $site[
'DATE_MODIFY'] = (string)$site[
'DATE_MODIFY'];
180 $site[
'SYS_PAGES'] = \Bitrix\Landing\Syspage::get($siteId);
181 $site[
'FOLDERS_NEW'] = self::getFolders($siteId);
184 $site[
'TEMPLATES'] = [];
185 $res = Template::getList([
190 while ($row = $res->fetch())
192 $site[
'TEMPLATES'][$row[
'ID']] = $row[
'XML_ID'];
196 $site[
'TEMPLATE_REF'] = [];
206 if ($hookCode ==
'SETTINGS')
210 foreach ($hook->getFields() as $fCode => $field)
212 $hookCodeFull = $hookCode .
'_' . $fCode;
213 $hookFields[$hookCodeFull] = $field->getValue();
214 if (!$hookFields[$hookCodeFull])
216 unset($hookFields[$hookCodeFull]);
220 if ($hookFields[$hookCodeFull] > 0)
222 $files[] = [
'ID' => $hookFields[$hookCodeFull]];
227 $site[
'ADDITIONAL_FIELDS'] = $hookFields;
230 'FILE_NAME' => str_replace(
'#site_id#', $siteId, self::FILENAME_EXPORT_STEP_META),
247 $siteType = substr($manifest[
'CODE'], strlen(AppConfiguration::PREFIX_CODE));
251 LandingCore::setEditMode();
253 if (!$next || $next ===
'false')
257 'EXPORTED_SITES_META' => []
262 $next = unserialize(htmlspecialcharsback($next), [
'allowed_classes' =>
false]);
273 if (isset($settings[
'FINISH_ID']))
275 $filter[
'<=SITE_ID'] = $settings[
'FINISH_ID'];
280 $filter[
'SITE_ID'] = $itemCode;
294 if ($row = $res->fetch())
296 if (!in_array($row[
'SITE_ID'], $next[
'EXPORTED_SITES_META']))
298 $exportSiteMeta = self::exportSiteMeta($row[
'SITE_ID']);
299 if (!$exportSiteMeta)
301 return $defaultReturn;
303 $next[
'EXPORTED_SITES_META'][] = $row[
'SITE_ID'];
304 $exportSiteMeta[
'NEXT'] = serialize($next);
306 return $exportSiteMeta;
308 $exportLanding = Landing::exportLanding(
310 self::FILENAME_EXPORT_STEP_PAGE
314 return $defaultReturn;
316 $next[
'ID'] = $row[
'ID'];
317 $exportLanding[
'NEXT'] = serialize($next);
318 return $exportLanding;
321 return $defaultReturn;
static setEditMode(bool $mode=true)
const FILENAME_EXPORT_STEP_PAGE
static getUrl(string $type, int $siteId)
const MAX_SITE_FOR_EXPORT
static nextStep(Event $event)
static getInitManifest(Event $event)
static exportSiteMeta(int $siteId)
static onFinish(Event $event)
static getRestAppIds(array $appCodes)
const FILENAME_EXPORT_STEP_META
static getList(array $parameters=array())