418 $result =
new Entity\EventResult();
419 $fields = $event->getParameter(
'fields');
420 $primary = $event->getParameter(
'primary');
421 $unsetFields = array();
422 $modifyFields = array();
426 self::$touchMode = isset($fields[
'TOUCH']) && $fields[
'TOUCH'] ==
'Y';
428 if ($actionType == self::ACTION_TYPE_ADD)
431 \Bitrix\Landing\Debug::log(
432 $fields[
'TITLE'] ??
'Noname',
433 print_r([$fields, \
Bitrix\Main\Diag\Helper::getBackTrace(15)],
true),
434 'LANDING_SITE_CREATE'
440 isset($fields[
'CODE']) ||
441 isset($fields[
'TITLE']) ||
442 isset($fields[
'DELETED'])
447 \Bitrix\Landing\Binding\Entity::onSiteChange(
454 isset($fields[
'DOMAIN_ID']) &&
455 $fields[
'DOMAIN_ID'] ===
''
458 unset($fields[
'DOMAIN_ID']);
459 $unsetFields[] =
'DOMAIN_ID';
463 if (isset($fields[
'DELETED']))
466 $modifyFields[
'ACTIVE'] =
'N';
467 $fields[
'ACTIVE'] =
'N';
469 if ($primary && $fields[
'DELETED'] ==
'N')
471 $fields[
'TYPE'] = self::getValueByCode(
479 'type' => $fields[
'TYPE'],
480 'filter' => [
'!ID' => $primary[
'ID']]
487 Restriction\Manager::getSystemErrorMessage(
'limit_sites_number'),
494 else if ($primary && $fields[
'DELETED'] ==
'Y')
496 $fields[
'DOMAIN_PROVIDER'] = self::getValueByCode(
501 if ($fields[
'DOMAIN_PROVIDER'] && ModuleManager::isModuleInstalled(
'bitrix24'))
506 'ACCESS_DENIED_DELETED'
515 if (!$primary && isset($fields[
'TYPE']))
518 if (!in_array($fields[
'TYPE'], $allowedTypes))
520 $result->setErrors(array(
531 if (!$primary && !array_key_exists(
'DOMAIN_ID', $fields))
533 $fields[
'DOMAIN_ID'] = \Bitrix\Landing\Site\Type::getDomainId();
534 $modifyFields[
'DOMAIN_ID'] = $fields[
'DOMAIN_ID'];
543 $freeAccessFields = [
552 $freeAccessFields = $fields;
553 if (isset($freeAccessFields[
'ACTIVE']))
555 unset($freeAccessFields[
'ACTIVE']);
557 if (isset($freeAccessFields[
'DELETED']))
559 unset($freeAccessFields[
'DELETED']);
561 $freeAccessFields = array_keys($freeAccessFields);
565 $freeAccessFields[] =
'ACTIVE';
569 $freeAccessFields[] =
'DELETED';
570 $freeAccessFields[] =
'DOMAIN_PROVIDER';
574 $freeAccessFields[] =
'ACTIVE';
577 foreach ($fields as $key => $val)
579 if (!in_array($key, $freeAccessFields))
582 'LANDING_TABLE_ERROR_ACCESS_DENIED_' . $key
587 'LANDING_TABLE_ERROR_ACCESS_DENIED'
590 $result->setErrors(array(
607 $result->setErrors(array(
618 if (array_key_exists(
'ADDITIONAL_FIELDS', $fields))
620 self::$additionalFields = $fields[
'ADDITIONAL_FIELDS'];
621 $unsetFields[] =
'ADDITIONAL_FIELDS';
625 self::$additionalFields = array();
630 array_key_exists(
'DOMAIN_ID', $fields) &&
635 $res = Domain::getList(array(
640 'ID' => $fields[
'DOMAIN_ID']
645 $result->unsetFields($unsetFields);
646 $result->setErrors(array(
658 isset($fields[
'ACTIVE']) &&
659 $fields[
'ACTIVE'] ==
'Y'
664 $fields[
'TYPE'] = self::getValueByCode(
672 $fields[
'TYPE'] =
null;
674 $special = self::getValueByCode(
681 $canPublicSite =
true;
685 $domainProvider = self::getValueByCode(
692 if (!Restriction\Manager::isAllowed(
'limit_free_domen', [
'trueOnNotNull' =>
true]))
694 $result->unsetFields($unsetFields);
695 $result->setErrors(array(
697 Restriction\Manager::getSystemErrorMessage(
'limit_free_domen'),
698 'FREE_DOMAIN_IS_NOT_ALLOWED'
709 '!ID' => $primary[
'ID']
711 'type' => $fields[
'TYPE']
714 'type' => $fields[
'TYPE']
721 ?
'PUBLIC_SITE_REACHED_FREE'
722 :
'PUBLIC_SITE_REACHED';
724 ?
'limit_sites_number_free'
725 :
'limit_sites_number';
726 $result->unsetFields($unsetFields);
727 $result->setErrors(array(
729 Restriction\Manager::getSystemErrorMessage($msgCode),
738 if (array_key_exists(
'CODE', $fields))
740 $fields[
'CODE'] = trim(trim(trim($fields[
'CODE']),
'/'));
741 if (mb_strpos($fields[
'CODE'],
'/') !==
false)
743 $result->unsetFields($unsetFields);
744 $result->setErrors(array(
747 'SLASH_IS_NOT_ALLOWED'
753 if (!$fields[
'CODE'])
755 $fields[
'CODE'] = \CUtil::translit(
756 (array_key_exists(
'TITLE', $fields) && trim($fields[
'TITLE']))
757 ? $fields[
'TITLE'] :
'site',
760 if (!$fields[
'CODE'])
762 $fields[
'CODE'] = randString(12);
766 if (preg_match(
'/^[\d]+$/', $fields[
'CODE']))
768 $fields[
'CODE'] =
'site' . $fields[
'CODE'];
770 $fields[
'CODE'] = mb_substr($fields[
'CODE'], 0, 253);
773 if (!array_key_exists(
'DOMAIN_ID', $fields) && $primary)
775 $domainId = self::getValueByCode(
781 else if (array_key_exists(
'DOMAIN_ID', $fields))
783 $domainId = $fields[
'DOMAIN_ID'];
786 if ($domainId !==
null)
789 $originalCode = $fields[
'CODE'];
793 '/' . $fields[
'CODE'] .
'/',
794 $primary ? $primary[
'ID'] : 0,
799 $fields[
'CODE'] = $originalCode . (++$checkCount);
803 $fields[
'CODE'] =
'/' . $fields[
'CODE'] .
'/';
804 $modifyFields[
'CODE'] = $fields[
'CODE'];
809 array_key_exists(
'DOMAIN_ID', $fields) &&
810 $fields[
'DOMAIN_ID'] !== 0 &&
812 preg_replace(
'/[\d]/',
'', trim($fields[
'DOMAIN_ID'])) !=
'' ||
818 $domainName = mb_strtolower(trim($fields[
'DOMAIN_ID']));
822 if ($domainName !=
'')
824 $puny = new \CBXPunycode;
825 $domainName = $puny->encode($domainName);
827 if (!preg_match(
'/^[a-z0-9\-\.]+\.[a-z0-9\-]{2,20}$/i', $domainName))
829 $result->unsetFields($unsetFields);
830 $result->setErrors(array(
833 'DOMAIN_IS_INCORRECT'
841 if ($actionType == self::ACTION_TYPE_ADD)
843 $modifyFields[
'DOMAIN_ID'] = 0;
852 'DOMAIN_NAME' =>
'DOMAIN.DOMAIN'
855 'ID' => $primary[
'ID'],
856 'CHECK_PERMISSIONS' =>
'N'
859 if ($row = $res->fetch())
861 $domainNameOld = mb_strtolower($row[
'DOMAIN_NAME']);
862 $domainId = $row[
'DOMAIN_ID'];
865 $unsetFields[] =
'DOMAIN_ID';
869 if ($domainId && array_key_exists(
'CODE', $fields))
873 $primary ? $primary[
'ID'] : 0,
878 $result->unsetFields($unsetFields);
879 $result->setErrors(array(
891 $domainName != $domainNameOld ||
892 $actionType == self::ACTION_TYPE_ADD
895 $domainExist =
false;
898 if ($domainName !=
'')
900 $resDomain = Domain::getList(array(
905 '=DOMAIN' => $domainName
908 if ($rowDomain = $resDomain->fetch())
911 $resSite = Site::getList(array(
916 'DOMAIN_ID' => $rowDomain[
'ID'],
918 'CHECK_PERMISSIONS' =>
'N'
921 if ($resSite->fetch())
940 !str_ends_with($domainName,
'.b24site.online')
941 && !str_ends_with($domainName,
'.b24shop.online')
944 $domainExist = $siteController::isDomainExists($domainName);
949 if (str_ends_with($domainName,
'.b24site.online'))
951 $byDomainName = str_replace(
'.b24site.online',
'.bitrix24site.by', $domainName);
953 if (str_ends_with($domainName,
'.b24shop.online'))
955 $byDomainName = str_replace(
'.b24shop.online',
'.bitrix24shop.by', $domainName);
957 if ($byDomainName !==
'' && $siteController::isDomainExists($byDomainName))
963 $domainExist = $siteController::isDomainExists($domainName);
969 $result->unsetFields($unsetFields);
970 $result->setErrors(array(
971 self::customizeControllerError($ex)
979 $result->unsetFields($unsetFields);
980 if (self::checkBitrixUse($domainName))
1009 $siteController::isDomainExists(
'repo.bitrix24.site');
1013 $result->unsetFields($unsetFields);
1014 $result->setErrors(array(
1015 self::customizeControllerError($ex)
1021 $eventManager = \Bitrix\Main\EventManager::getInstance();
1022 $eventManager->addEventHandler(
1024 $actionType == self::ACTION_TYPE_ADD
1025 ?
'\\' . __NAMESPACE__ .
'\\Site::onAfterAdd'
1026 :
'\\' . __NAMESPACE__ .
'\\Site::onAfterUpdate',
1027 function(Entity\Event $event) use ($domainId, $domainName, $domainNameOld, $result, $unsetFields, $siteController)
1029 $primary = $event->getParameter(
'primary');
1030 $fields = $event->getParameter(
'fields');
1050 'ID' => $primary[
'ID']
1053 if ($row[
'TYPE'] ==
'STORE')
1055 $row[
'TYPE'] =
'shop';
1059 $siteController::addDomain(
1069 $domainName = $siteController::addRandomDomain(
1078 $result->unsetFields($unsetFields);
1079 $result->setErrors(array(
1080 self::customizeControllerError($ex)
1088 $resDomain = Domain::add(array(
1090 'DOMAIN' => $domainName
1092 $domainId = $resDomain->getId();
1096 SiteTable::update($primary[
'ID'], array(
1097 'DOMAIN_ID' => $domainId
1106 $res = Domain::update($domainId, array(
1107 'DOMAIN' => $domainName,
1108 'FAIL_COUNT' =>
null,
1111 if ($res->isSuccess())
1120 $siteController::updateDomain(
1128 $result->unsetFields($unsetFields);
1129 $result->setErrors(array(
1130 self::customizeControllerError($ex)
1143 $result->unsetFields($unsetFields);
1144 $result->modifyFields($modifyFields);