69 $code = isset($data[
'CODE']) ? $data[
'CODE'] :
null;
73 'ID',
'DOMAIN_ID',
'DATE_CREATE',
'DATE_MODIFY',
74 'CREATED_BY_ID',
'MODIFIED_BY_ID',
'CODE'
76 foreach ($notAllowedKeys as $key)
78 if (isset($data[$key]))
87 $check = SiteCore::getList([
102 $code = strtolower(\randString(10));
104 $data[
'CODE'] = $code;
105 $data[
'ACTIVE'] =
'Y';
109 foreach (Hook::HOOKS_CODES_FILES as $hookCode)
112 isset($data[
'ADDITIONAL_FIELDS'][$hookCode]) &&
113 $data[
'ADDITIONAL_FIELDS'][$hookCode] > 0
116 $unpackFile = $structure->getUnpackFile($data[
'ADDITIONAL_FIELDS'][$hookCode]);
119 $files[] = $data[
'ADDITIONAL_FIELDS'][$hookCode] = AppConfiguration::saveFile(
125 unset($data[
'ADDITIONAL_FIELDS'][$hookCode]);
130 $res = SiteCore::add($data);
133 if ($files && $res->isSuccess())
135 foreach ($files as $fileId)
156 $additional = $event->
getParameter(
'ADDITIONAL_OPTION');
157 $structure =
new Configuration\Structure($contextUser);
159 'RATIO' => isset($ratio[$code]) ? $ratio[$code] : [],
160 'ERROR_EXCEPTION' => []
163 if (!isset($content[
'~DATA']))
174 $isPageImport = $return[
'RATIO'][
'IS_PAGE_IMPORT'] ??
false;
178 $isReplaceLanding = $additional && (int)($additional[
'replaceLid'] ?? 0) > 0;
179 if (isset($ratio[$code][
'SITE_ID']) && (int)$ratio[$code][
'SITE_ID'] > 0)
184 $additional && (
int)$additional[
'siteId'] > 0
187 $return[
'RATIO'][
'SITE_ID'] = (int)$additional[
'siteId'];
188 $isPageImport = $return[
'RATIO'][
'IS_PAGE_IMPORT'] ??
true;
191 if ($isReplaceLanding)
193 $return[
'RATIO'][
'REPLACE_ID'] = (int)$additional[
'replaceLid'];
197 $data = self::prepareData($content[
'~DATA']);
198 $data = self::prepareAdditionalFields($data, $additional);
199 if ($isReplaceLanding && !$isPageStep)
201 $return[
'RATIO'][
'ADDITIONAL_FIELDS_SITE'] = $data[
'ADDITIONAL_FIELDS'];
203 if (!isset($return[
'RATIO'][
'SPECIAL_PAGES']))
205 $return[
'RATIO'][
'SPECIAL_PAGES'] = [
206 'LANDING_ID_INDEX' => isset($data[
'LANDING_ID_INDEX']) ? (int)$data[
'LANDING_ID_INDEX'] : 0,
207 'LANDING_ID_404' => isset($data[
'LANDING_ID_404']) ? (int)$data[
'LANDING_ID_404'] : 0,
208 'LANDING_ID_503' => isset($data[
'LANDING_ID_503']) ? (int)$data[
'LANDING_ID_503'] : 0
211 $return[
'RATIO'][
'IS_PAGE_IMPORT'] = $isPageImport;
212 $return[
'RATIO'][
'TYPE'] = $data[
'TYPE'];
215 if (!$isPageImport && !$isPageStep && !$isReplaceLanding)
218 $res = self::importSite($data, $structure);
219 if ($res->isSuccess())
221 $return[
'RATIO'][
'BLOCKS'] = [];
222 $return[
'RATIO'][
'BLOCKS_PENDING'] = [];
223 $return[
'RATIO'][
'LANDINGS'] = [];
224 $return[
'RATIO'][
'TEMPLATES'] = [];
225 $return[
'RATIO'][
'TEMPLATE_LINKING'] = [];
226 $return[
'RATIO'][
'SITE_ID'] = $res->getId();
227 $return[
'RATIO'][
'FOLDERS_NEW'] = $data[
'FOLDERS_NEW'] ?? [];
228 $return[
'RATIO'][
'SYS_PAGES'] = $data[
'SYS_PAGES'];
230 if (isset($data[
'TEMPLATES']) && is_array($data[
'TEMPLATES']))
232 $return[
'RATIO'][
'TEMPLATES'] = $data[
'TEMPLATES'];
234 if (isset($data[
'TPL_ID']) && $data[
'TPL_ID'])
236 $return[
'RATIO'][
'TEMPLATE_LINKING'][-1 * $res->getId()] = [
237 'TPL_ID' => (int) $data[
'TPL_ID'],
238 'TEMPLATE_REF' => isset($data[
'TEMPLATE_REF'])
239 ? (array) $data[
'TEMPLATE_REF']
246 $return[
'ERROR_EXCEPTION'] = $res->getErrorMessages();
252 if (!isset($return[
'RATIO'][
'SITE_ID']))
254 $return[
'ERROR_EXCEPTION'][] =
Loc::getMessage(
'LANDING_IMPORT_ERROR_SITE_ID_NOT_FOUND');
259 if (!isset($data[
'SITE_ID']))
265 if (isset($return[
'RATIO'][
'REPLACE_ID']) && $return[
'RATIO'][
'REPLACE_ID'] > 0)
267 return Landing::replaceLanding($event);
270 return Landing::importLanding($event);
352 $replaceEncoded = base64_encode(serialize($replace));
353 $res = BlockTable::getList([
361 while ($row = $res->fetch())
363 $blockInstance =
new Block($row[
'ID']);
364 if ($blockInstance->exist())
366 $blockInstance->updateNodes([
367 AppConfiguration::SYSTEM_COMPONENT_REST_PENDING => [
368 'REPLACE' => $replaceEncoded
371 $blockInstance->save();
411 protected static function addFolders(
int $siteId, array $foldersNew, array $landingMapIds): void
419 foreach ($foldersNew as $folderId => $folder)
423 if (!$folder[
'PARENT_ID'])
425 unset($folder[
'PARENT_ID']);
428 if ($folder[
'INDEX_ID'] ??
null)
430 $indexId = $landingMapIds[$folder[
'INDEX_ID']] ??
null;
431 unset($folder[
'INDEX_ID']);
434 $res = SiteCore::addFolder($siteId, $folder);
435 if ($res->isSuccess())
440 'FOLDER_ID' => $res->getId()
442 if ($resLanding->isSuccess())
444 \Bitrix\Landing\Folder::update($res->getId(), [
445 'INDEX_ID' => $indexId
449 $folderMapIds[$folderId] = $res->getId();
453 $newFolders = SiteCore::getFolders($siteId);
454 foreach ($newFolders as $folder)
456 if ($folderMapIds[$folder[
'PARENT_ID']] ??
null)
458 \Bitrix\Landing\Folder::update($folder[
'ID'], [
459 'PARENT_ID' => $folderMapIds[$folder[
'PARENT_ID']]
464 self::updateFolderIds($siteId, $folderMapIds);
482 if (isset($ratio[
'LANDING']))
485 $siteType = $ratio[
'LANDING'][
'TYPE'];
486 $siteId = $ratio[
'LANDING'][
'SITE_ID'];
487 $blocks = $ratio[
'LANDING'][
'BLOCKS'];
488 $landings = $ratio[
'LANDING'][
'LANDINGS'];
489 $blocksPending = $ratio[
'LANDING'][
'BLOCKS_PENDING'];
490 $foldersRef = $ratio[
'LANDING'][
'FOLDERS_REF'];
491 $templatesOld = $ratio[
'LANDING'][
'TEMPLATES'];
492 $templateLinking = $ratio[
'LANDING'][
'TEMPLATE_LINKING'];
493 $specialPages = $ratio[
'LANDING'][
'SPECIAL_PAGES'];
494 $sysPages = $ratio[
'LANDING'][
'SYS_PAGES'];
495 $foldersNew = $ratio[
'LANDING'][
'FOLDERS_NEW'];
496 $additional = $event->
getParameter(
'ADDITIONAL_OPTION') ?? [];
499 $isPageImport =
false;
500 $isReplaceLanding = isset($additional[
'replaceLid']) && (int)$additional[
'replaceLid'] > 0;
502 (isset($additional[
'siteId']) && (
int)$additional[
'siteId'] > 0)
506 $isPageImport =
true;
511 if (!empty($landings))
515 $mainPageId = reset($landings);
520 && $specialPages[
'LANDING_ID_INDEX']
521 && $landings[$specialPages[
'LANDING_ID_INDEX']]
524 $mainPageId = $landings[$specialPages[
'LANDING_ID_INDEX']];
531 self::linkingPendingBlocks($blocksPending, [
533 'landing' => $landings
542 $blocks = array_reverse($blocks,
true);
543 $landings = array_reverse($landings,
true);
544 foreach ($blocks as $oldId => $newId)
546 $replace[
'/#block' . $oldId .
'([^\d]{1})/'] =
'#block' . $newId .
'$1';
548 foreach ($landings as $oldId => $newId)
550 $replace[
'/#landing' . $oldId .
'([^\d]{1})/'] =
'#landing' . $newId .
'$1';
553 $res = BlockTable::getList([
558 'ID' => array_values($blocks),
559 '!ID' => $blocksPending
562 while ($row = $res->fetch())
565 $row[
'CONTENT'] = preg_replace(
566 array_keys($replace),
567 array_values($replace),
574 BlockTable::update($row[
'ID'], [
575 'CONTENT' => $row[
'CONTENT']
591 'SITE_ID' => $siteId,
592 'FOLDER_ID' => array_keys($foldersRef),
595 while ($row = $res->fetch())
598 'FOLDER_ID' => $foldersRef[$row[
'FOLDER_ID']],
603 self::addFolders($siteId, $foldersNew, $landings);
607 $res = Template::getList([
612 while ($row = $res->fetch())
614 $templatesNew[$row[
'XML_ID']] = $row[
'ID'];
616 foreach ($templatesOld as $oldId => $oldXmlId)
618 if (is_string($oldXmlId) && isset($templatesNew[$oldXmlId]))
620 $templatesRefs[$oldId] = $templatesNew[$oldXmlId];
625 foreach ($templateLinking as $entityId => $templateItem)
627 $tplId = $templateItem[
'TPL_ID'];
629 if (isset($templatesRefs[$tplId]))
631 $tplId = $templatesRefs[$tplId];
632 foreach ($templateItem[
'TEMPLATE_REF'] as $areaId => $landingId)
634 if (intval($landingId) && isset($landings[$landingId]))
636 $tplRefs[$areaId] = $landings[$landingId];
641 SiteCore::update(-1 * $entityId, [
657 if ($specialPages && $siteId)
659 foreach ($specialPages as $code => $id)
661 $specialPages[$code] = isset($landings[$id]) ? $landings[$id] : 0;
663 SiteCore::update($siteId, $specialPages);
667 if (is_array($sysPages) && $siteId)
669 foreach ($sysPages as $sysPage)
671 if (isset($landings[$sysPage[
'LANDING_ID']]))
673 Syspage::set($siteId, $sysPage[
'TYPE'], $landings[$sysPage[
'LANDING_ID']]);
680 if ($mainPageId && !$isReplaceLanding)
682 self::setAdditionalPageFields($mainPageId, $additional);
689 'class' =>
'ui-btn ui-btn-md ui-btn-success ui-btn-round',
690 'data-is-site' =>
'Y',
691 'data-site-id' => $siteId,
692 'href' =>
'#' . $siteId,
697 $linkAttrs[
'data-is-landing'] =
'Y';
698 $linkAttrs[
'data-landing-id'] = $mainPageId;
701 if ($siteType ===
'KNOWLEDGE')
703 $linkAttrs[
'href'] = \Bitrix\Landing\Site::getPublicUrl($siteId);
705 elseif ($siteType ===
'PAGE' && empty($additional))
709 if ($url ===
'' && ModuleManager::isModuleInstalled(
'bitrix24'))
711 $linkAttrs[
'href'] =
'/sites/';
715 $linkAttrs[
'href'] = str_replace(
729 if ($isReplaceLanding)
731 $linkAttrs[
'data-replace-lid'] = (int)$additional[
'replaceLid'];
738 'attrs' => $linkAttrs,
744 if (mb_strpos($linkAttrs[
'href'],
'#') !== 0)
749 'html' =>
"top.window.location.href='" . $linkAttrs[
'href'] .
"'",
754 $isNewAnalytic =
false;
757 && array_key_exists(
'st_category', $additional)
758 && array_key_exists(
'st_event', $additional)
761 $isNewAnalytic =
true;
764 'category' => $additional[
'st_category'],
765 'event' => $additional[
'st_event'],
767 if (array_key_exists(
'st_section', $additional))
769 $analyticData[
'c_section'] = $additional[
'st_section'];
771 if (array_key_exists(
'st_element', $additional))
773 $analyticData[
'c_element'] = $additional[
'st_element'];
775 if (array_key_exists(
'app_code', $additional))
777 $analyticData[
'params'] = [
778 'appCode' => $additional[
'app_code'],
782 $script =
"if (typeof BX.Landing.Metrika !== 'undefined') {";
783 $script .=
"const metrika = new BX.Landing.Metrika(true);";
784 $script .=
"metrika.sendData(" . \CUtil::PhpToJSObject($analyticData) .
")";
795 'CREATE_DOM_LIST' => $domList,
798 'publicUrl' => \Bitrix\Landing\Site::getPublicUrl($siteId),
801 'isNewAnalytic' => $isNewAnalytic ?
'Y' :
'N',