Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
landing.php
1<?php
3
4use \Bitrix\Main\Localization\Loc;
5use \Bitrix\Main\Entity;
6use \Bitrix\Landing\Landing;
7use \Bitrix\Landing\Manager;
8use \Bitrix\Landing\Rights;
9use \Bitrix\Landing\Role;
10use \Bitrix\Landing\TemplateRef;
11use \Bitrix\Landing\Landing\Cache;
12
13Loc::loadMessages(__FILE__);
14
31class LandingTable extends Entity\DataManager
32{
36 const ACTION_TYPE_ADD = 'add';
37
41 const ACTION_TYPE_UPDATE = 'update';
42
47 protected static $additionalFields = array();
48
53 public static function getTableName()
54 {
55 return 'b_landing';
56 }
57
62 public static function getMap()
63 {
64 return array(
65 'ID' => new Entity\IntegerField('ID', array(
66 'primary' => true,
67 'autocomplete' => true,
68 'title' => 'ID'
69 )),
70 'CODE' => new Entity\StringField('CODE', array(
71 'title' => Loc::getMessage('LANDING_TABLE_FIELD_LANDING_CODE')
72 )),
73 'INITIATOR_APP_CODE' => new Entity\StringField('INITIATOR_APP_CODE', array(
74 'title' => Loc::getMessage('LANDING_TABLE_FIELD_LANDING_INITIATOR_APP_CODE')
75 )),
76 'RULE' => new Entity\StringField('RULE', array(
77 'title' => Loc::getMessage('LANDING_TABLE_FIELD_RULE')
78 )),
79 'ACTIVE' => new Entity\StringField('ACTIVE', array(
80 'title' => Loc::getMessage('LANDING_TABLE_FIELD_LANDING_ACTIVE'),
81 'default_value' => 'Y'
82 )),
83 'DELETED' => new Entity\StringField('DELETED', array(
84 'title' => Loc::getMessage('LANDING_TABLE_FIELD_SITE_DELETED'),
85 'default_value' => 'N'
86 )),
87 'PUBLIC' => new Entity\StringField('PUBLIC', array(
88 'title' => Loc::getMessage('LANDING_TABLE_FIELD_LANDING_PUBLIC'),
89 'default_value' => 'Y'
90 )),
91 'SYS' => new Entity\StringField('SYS', array(
92 'title' => Loc::getMessage('LANDING_TABLE_FIELD_LANDING_SYSTEM'),
93 'default_value' => 'N'
94 )),
95 'VIEWS' => new Entity\IntegerField('VIEWS', array(
96 'title' => Loc::getMessage('LANDING_TABLE_FIELD_LANDING_VIEWS'),
97 'default_value' => 0
98 )),
99 'TITLE' => new Entity\StringField('TITLE', array(
100 'title' => Loc::getMessage('LANDING_TABLE_FIELD_LANDING_TITLE'),
101 'required' => true,
102 'save_data_modification' => array('\Bitrix\Main\Text\Emoji', 'getSaveModificator'),
103 'fetch_data_modification' => array('\Bitrix\Main\Text\Emoji', 'getFetchModificator'),
104 )),
105 'XML_ID' => new Entity\StringField('XML_ID', array(
106 'title' => Loc::getMessage('LANDING_TABLE_FIELD_XML_ID')
107 )),
108 'DESCRIPTION' => new Entity\StringField('DESCRIPTION', array(
109 'title' => Loc::getMessage('LANDING_TABLE_FIELD_DESCRIPTION')
110 )),
111 'TPL_ID' => new Entity\IntegerField('TPL_ID', array(
112 'title' => Loc::getMessage('LANDING_TABLE_FIELD_TPL_ID')
113 )),
114 'TPL_CODE' => new Entity\StringField('TPL_CODE', array(
115 'title' => Loc::getMessage('LANDING_TABLE_FIELD_TPL_CODE')
116 )),
117 'SITE_ID' => new Entity\IntegerField('SITE_ID', array(
118 'title' => Loc::getMessage('LANDING_TABLE_FIELD_SITE_ID'),
119 'required' => true
120 )),
121 'SITE' => new Entity\ReferenceField(
122 'SITE',
123 'Bitrix\Landing\Internals\SiteTable',
124 array('=this.SITE_ID' => 'ref.ID')
125 ),
126 'AREAS' => new Entity\ReferenceField(
127 'AREAS',
128 'Bitrix\Landing\Internals\TemplateRefTable',
129 array('=this.ID' => 'ref.LANDING_ID')
130 ),
131 'SITEMAP' => new Entity\StringField('SITEMAP', array(
132 'title' => Loc::getMessage('LANDING_TABLE_FIELD_LANDING_SITEMAP'),
133 'default_value' => 'N'
134 )),
135 'FOLDER' => new Entity\StringField('FOLDER', array(
136 'title' => Loc::getMessage('LANDING_TABLE_FIELD_FOLDER'),
137 'default_value' => 'N'
138 )),
139 'FOLDER_ID' => new Entity\IntegerField('FOLDER_ID', array(
140 'title' => Loc::getMessage('LANDING_TABLE_FIELD_FOLDER_ID')
141 )),
142 'SEARCH_CONTENT' => new Entity\StringField('SEARCH_CONTENT', array(
143 'title' => Loc::getMessage('LANDING_TABLE_FIELD_SEARCH_CONTENT')
144 )),
145 'VERSION' => new Entity\IntegerField('VERSION', array(
146 'title' => Loc::getMessage('LANDING_TABLE_FIELD_VERSION'),
147 'default_value' => 10
148 )),
149 'HISTORY_STEP' => new Entity\IntegerField('HISTORY_STEP', array(
150 'title' => 'History step',
151 'default_value' => 0
152 )),
153 'CREATED_BY_ID' => new Entity\IntegerField('CREATED_BY_ID', array(
154 'title' => Loc::getMessage('LANDING_TABLE_FIELD_CREATED_BY_ID'),
155 'required' => true
156 )),
157 'CREATED_BY' => new Entity\ReferenceField(
158 'CREATED_BY',
159 'Bitrix\Main\UserTable',
160 array('=this.CREATED_BY_ID' => 'ref.ID')
161 ),
162 'MODIFIED_BY_ID' => new Entity\IntegerField('MODIFIED_BY_ID', array(
163 'title' => Loc::getMessage('LANDING_TABLE_FIELD_MODIFIED_BY_ID'),
164 'required' => true
165 )),
166 'MODIFIED_BY' => new Entity\ReferenceField(
167 'MODIFIED_BY',
168 'Bitrix\Main\UserTable',
169 array('=this.MODIFIED_BY_ID' => 'ref.ID')
170 ),
171 'DATE_CREATE' => new Entity\DatetimeField('DATE_CREATE', array(
172 'title' => Loc::getMessage('LANDING_TABLE_FIELD_DATE_CREATE'),
173 'required' => true
174 )),
175 'DATE_MODIFY' => new Entity\DatetimeField('DATE_MODIFY', array(
176 'title' => Loc::getMessage('LANDING_TABLE_FIELD_DATE_MODIFY'),
177 'required' => true
178 )),
179 'DATE_PUBLIC' => new Entity\DatetimeField('DATE_PUBLIC', array(
180 'title' => Loc::getMessage('LANDING_TABLE_FIELD_DATE_PUBLIC')
181 ))
182 );
183 }
184
190 public static function setAccessFilter($params)
191 {
192 if (
193 isset($params['filter']['CHECK_PERMISSIONS']) &&
194 $params['filter']['CHECK_PERMISSIONS'] == 'N'
195 )
196 {
197 return $params;
198 }
199
200 // build filter
201 $allowedSites = Rights::getAllowedSites();
202 $buildFilter = Rights::getAccessFilter(
203 $allowedSites ? ['SITE_ID' => $allowedSites] : []
204 );
205 if (empty($buildFilter))
206 {
207 return $params;
208 }
209
210 // create runtime/filter keys if no exists
211 if (
212 !isset($params['filter']) ||
213 !is_array($params['filter'])
214 )
215 {
216 $params['filter'] = [];
217 }
218 if (
219 !isset($params['runtime']) ||
220 !is_array($params['runtime'])
221 )
222 {
223 $params['runtime'] = [];
224 }
225 if (
226 !isset($params['group']) ||
227 !is_array($params['group'])
228 )
229 {
230 $params['group'] = [];
231 }
232
233 //$tasks = Rights::getAccessTasksReferences();
234 //$readCode = Rights::ACCESS_TYPES['read'];
235 $extendedRights = Rights::isExtendedMode();
236 static $expectedRoles = null;
237 if ($expectedRoles === null)
238 {
239 $expectedRoles = Role::getExpectedRoleIds();
240 }
241
242 // create runtime fields
243 $runtimeParams = [];
244 $runtimeParams[] = [
245 'LOGIC' => 'OR',
246 '=this.SITE_ID' => 'ref.ENTITY_ID',
247 '=ref.ENTITY_ID' => [0]
248 ];
249 if ($extendedRights)
250 {
251 $runtimeParams['=ref.ROLE_ID'] = [0];
252 }
253 else
254 {
255 $runtimeParams['=ref.ENTITY_TYPE'] = ['?', Rights::ENTITY_TYPE_SITE];
256 $runtimeParams['@ref.ROLE_ID'] = [implode(',', $expectedRoles)];
257 }
258 $params['runtime'][] = new Entity\ReferenceField(
259 'RIGHTS',
260 'Bitrix\Landing\Internals\RightsTable',
261 $runtimeParams,
262 ['join_type' => 'INNER']
263 );
264
265 $params['group'][] = 'SITE_ID';
266
267 // build filter
268 $params['filter'][] = $buildFilter;
269
270 return $params;
271 }
272
279 protected static function prepareChange(Entity\Event $event, $actionType)
280 {
281 $result = new Entity\EventResult();
282 $primary = $event->getParameter('primary');
283 $fields = $event->getParameter('fields');
284 $modifyFields = array();
285 $existFields = array();
286 $deleteMode = false;
287
288 // get all fields, which we need
289 if ($primary)
290 {
291 $res = self::getList([
292 'select' => [
293 'CODE',
294 'SITE_ID', 'FOLDER_ID',
295 'INITIATOR_APP_CODE',
296 'ID_INDEX' => 'SITE.LANDING_ID_INDEX'
297 ],
298 'filter' => [
299 'ID' => $primary['ID'],
300 '=DELETED' => ['Y', 'N']
301 ]
302 ]);
303 $existFields = $res->fetch();
304 unset($res);
305 }
306
307 // check that folder within landing's site
308 if (($fields['FOLDER_ID'] ?? null) && ($fields['FOLDER_SKIP_CHECK'] ?? 'N') !== 'Y')
309 {
310 if (empty($existFields['SITE_ID']))
311 {
312 $existFields['SITE_ID'] = $fields['SITE_ID'];
313 }
314 $res = FolderTable::getList([
315 'select' => [
316 'ID'
317 ],
318 'filter' => [
319 'SITE_ID' => $existFields['SITE_ID'],
320 'ID' => $fields['FOLDER_ID']
321 ]
322 ]);
323 if (!$res->fetch())
324 {
325 $result->setErrors(array(
327 Loc::getMessage('LANDING_TABLE_ERROR_FOLDER_NOT_FOUND'),
328 'FOLDER_NOT_FOUND'
329 )
330 ));
331 return $result;
332 }
333 }
334
335 // check CODE mask
336 if (
337 isset($fields['CODE']) &&
338 (
339 !isset($existFields['CODE']) ||
340 $existFields['CODE'] != $fields['CODE']
341 )
342 )
343 {
344 if (preg_match('#^([\w]+)\_([\d]+)\_([\d]+)$#', $fields['CODE'], $matches))
345 {
346 $result->setErrors(array(
348 Loc::getMessage('LANDING_TABLE_ERROR_WRONG_CODE_FORMAT'),
349 'WRONG_CODE_FORMAT'
350 )
351 ));
352 return $result;
353 }
354 }
355
356 // if page have't blocks of page's app, we clear this mark
357 if (isset($fields['INITIATOR_APP_CODE']))
358 {
359 $existFields['INITIATOR_APP_CODE'] = $fields['INITIATOR_APP_CODE'];
360 }
361
362 // if delete, set unpublic always
363 if (isset($fields['DELETED']))
364 {
365 $deleteMode = true;
366 $modifyFields['ACTIVE'] = 'N';
367 $fields['ACTIVE'] = 'N';
368 // disable main page deleting
369 if ($fields['DELETED'] == 'Y' && $primary)
370 {
371 if ($existFields['ID_INDEX'] == $primary['ID'])
372 {
373 // disable only for a few pages in the site
374 $sitesCheck = self::getList([
375 'select' => [
376 'ID'
377 ],
378 'filter' => [
379 'SITE_ID' => $existFields['SITE_ID'],
380 '=DELETED' => 'N'
381 ],
382 'limit' => 2
383 ])->fetchAll();
384 if (count($sitesCheck) > 1)
385 {
386 $result->setErrors([
388 Loc::getMessage('LANDING_TABLE_ERROR_LD_CANT_DELETE_MAIN'),
389 'CANT_DELETE_MAIN'
390 )
391 ]);
392 return $result;
393 }
394 }
395 }
396 }
397
398 // get real site id, for check rights call upper level
399 if (array_key_exists('SITE_ID', $fields))
400 {
401 $res = \Bitrix\Landing\Site::getList(array(
402 'select' => array(
403 'ID'
404 ),
405 'filter' => array(
406 'ID' => $fields['SITE_ID']
407 )
408 ));
409 if (!$res->fetch())
410 {
411 $result->setErrors(array(
413 Loc::getMessage('LANDING_TABLE_ERROR_SITE_NOT_FOUND'),
414 'SITE_NOT_FOUND'
415 )
416 ));
417 return $result;
418 }
419 }
420 else if ($existFields)
421 {
422 if ($existFields['SITE_ID'])
423 {
424 $fields['SITE_ID'] = $existFields['SITE_ID'];
425 }
426 else
427 {
428 $result->setErrors(array(
430 Loc::getMessage('LANDING_TABLE_ERROR_SITE_NOT_FOUND'),
431 'SITE_NOT_FOUND'
432 )
433 ));
434 return $result;
435 }
436 }
437 else
438 {
439 $fields['SITE_ID'] = 0;
440 }
441
442 // check rights
443 if ($fields['SITE_ID'] && Rights::isOn())
444 {
446 $fields['SITE_ID']
447 );
448 if (!\Bitrix\Landing\Site\Type::isPublicScope())
449 {
450 $rights[] = Rights::ACCESS_TYPES['public'];
451 }
452 // can create new landing in site
453 if (!$primary)
454 {
455 if (!in_array(Rights::ACCESS_TYPES['edit'], $rights))
456 {
457 $errMessage = Loc::getMessage(
458 'LANDING_TABLE_ERROR_LD_ACCESS_DENIED_ADD'
459 );
460 $result->setErrors(array(
462 $errMessage,
463 'ACCESS_DENIED'
464 )
465 ));
466 return $result;
467 }
468 }
469 else
470 {
471 $freeAccessFields = [
472 'CREATED_BY_ID',
473 'MODIFIED_BY_ID',
474 'DATE_CREATE',
475 'DATE_MODIFY',
476 'SITE_ID',
477 'PUBLIC'
478 ];
479 if (in_array(Rights::ACCESS_TYPES['sett'], $rights))
480 {
481 $freeAccessFields = $fields;
482 $higherAccess = [
483 'ACTIVE', 'DATE_PUBLIC', 'DELETED'
484 ];
485 foreach ($higherAccess as $key)
486 {
487 if (isset($freeAccessFields[$key]))
488 {
489 unset($freeAccessFields[$key]);
490 }
491 }
492 $freeAccessFields = array_keys($freeAccessFields);
493 }
494 if (in_array(Rights::ACCESS_TYPES['public'], $rights))
495 {
496 $freeAccessFields[] = 'ACTIVE';
497 $freeAccessFields[] = 'DATE_PUBLIC';
498 }
499 if (in_array(Rights::ACCESS_TYPES['delete'], $rights))
500 {
501 $freeAccessFields[] = 'DELETED';
502 // allow unpublic in delete case
503 if ($deleteMode)
504 {
505 $freeAccessFields[] = 'ACTIVE';
506 }
507 }
508 foreach ($fields as $key => $val)
509 {
510 if (!in_array($key, $freeAccessFields))
511 {
512 $errMessage = Loc::getMessage(
513 'LANDING_TABLE_ERROR_LD_ACCESS_DENIED_' . $key
514 );
515 if (!$errMessage)
516 {
517 $errMessage = Loc::getMessage(
518 'LANDING_TABLE_ERROR_LD_ACCESS_DENIED'
519 );
520 }
521 $result->setErrors(array(
523 $errMessage,
524 'ACCESS_DENIED'
525 )
526 ));
527 return $result;
528 }
529 }
530 }
531 }
532
533 // additional fields save after
534 if (array_key_exists('ADDITIONAL_FIELDS', $fields))
535 {
536 self::$additionalFields = $fields['ADDITIONAL_FIELDS'];
537 $result->unsetFields(array('ADDITIONAL_FIELDS'));
538 }
539 else
540 {
541 self::$additionalFields = array();
542 }
543
544 // slash in CODE is not allowed
545 if (
546 array_key_exists('CODE', $fields) &&
547 mb_strpos($fields['CODE'], '/') !== false
548 )
549 {
550 $result->setErrors(array(
552 Loc::getMessage('LANDING_TABLE_ERROR_SLASH_IS_NOT_ALLOWED'),
553 'SLASH_IS_NOT_ALLOWED'
554 )
555 ));
556 return $result;
557 }
558 // CODE can't be empty
559 elseif (
560 array_key_exists('CODE', $fields) &&
561 $fields['CODE'] == '' &&
562 !isset($fields['FOLDER'])
563 )
564 {
565 $result->setErrors(array(
567 Loc::getMessage('LANDING_TABLE_ERROR_CANT_BE_EMPTY'),
568 'CANT_BE_EMPTY'
569 )
570 ));
571 return $result;
572 }
573 elseif (
574 $actionType == self::ACTION_TYPE_ADD && array_key_exists('TITLE', $fields) &&
575 (!array_key_exists('CODE', $fields) || trim($fields['CODE']) == '')
576 )
577 {
578 $fields['CODE'] = \CUtil::translit(
579 trim($fields['TITLE']),
580 LANGUAGE_ID,
581 array(
582 'replace_space' => '',
583 'replace_other' => ''
584 ));
585 if (!$fields['CODE'])
586 {
587 $fields['CODE'] = randString(12);
588 }
589 $modifyFields['CODE'] = $fields['CODE'];
590 }
591
592 $result->modifyFields($modifyFields);
593
594 return $result;
595 }
596
602 public static function getList(array $params = array())
603 {
605 {
606 if (
607 !isset($params['filter']) ||
608 !is_array($params['filter'])
609 )
610 {
611 $params['filter'] = array();
612 }
613 if (
614 !isset($params['filter']['DELETED']) &&
615 !isset($params['filter']['=DELETED'])
616 )
617 {
618 $params['filter']['=DELETED'] = 'N';
619 }
620 if (
621 !isset($params['filter']['SITE.DELETED']) &&
622 !isset($params['filter']['=SITE.DELETED'])
623 )
624 {
625 $params['filter']['=SITE.DELETED'] = 'N';
626 }
627 }
628 if (isset($params['filter']['CHECK_PERMISSIONS']))
629 {
630 unset($params['filter']['CHECK_PERMISSIONS']);
631 }
632
633 // strict filter by type
634 $type = null;
635 if (isset($params['filter']['SITE.TYPE']))
636 {
637 $type = $params['filter']['SITE.TYPE'];
638 unset($params['filter']['SITE.TYPE']);
639 }
640 if (isset($params['filter']['=SITE.TYPE']))
641 {
642 $type = $params['filter']['=SITE.TYPE'];
643 unset($params['filter']['=SITE.TYPE']);
644 }
645 $allowedTypes = \Bitrix\Landing\Site\Type::getFilterType();
646 $params['filter']['=SITE.TYPE'] = in_array($type, (array)$allowedTypes)
647 ? $type
648 : $allowedTypes;
649
650 return parent::getList($params);
651 }
652
658 public static function OnBeforeAdd(Entity\Event $event)
659 {
660 return self::prepareChange($event, self::ACTION_TYPE_ADD);
661 }
662
668 public static function OnBeforeUpdate(Entity\Event $event)
669 {
670 return self::prepareChange($event, self::ACTION_TYPE_UPDATE);
671 }
672
678 public static function OnBeforeDelete(Entity\Event $event)
679 {
680 $result = new Entity\EventResult();
681 $primary = $event->getParameter('primary');
682 if ($primary)
683 {
684 $res = self::getList([
685 'select' => [
686 'SITE_ID'
687 ],
688 'filter' => [
689 'ID' => $primary['ID'],
690 'CHECK_PERMISSIONS' => 'N',
691 '=SITE.DELETED' => ['Y', 'N'],
692 '=DELETED' => ['Y', 'N']
693 ]
694 ]);
695 if ($site = $res->fetch())
696 {
697 // check delete access
698 $hasAccess = Rights::hasAccessForSite(
699 $site['SITE_ID'],
700 Rights::ACCESS_TYPES['delete']
701 );
702 if (!$hasAccess)
703 {
704 $result->setErrors(array(
706 Loc::getMessage('LANDING_TABLE_ERROR_LD_ACCESS_DENIED_DELETED'),
707 'ACCESS_DENIED'
708 )
709 ));
710 return $result;
711 }
712 }
713 // check lock status
714 if (\Bitrix\Landing\Lock::isLandingDeleteLocked($primary['ID']))
715 {
716 $result->setErrors(array(
718 Loc::getMessage('LANDING_TABLE_ERROR_LD_IS_LOCK'),
719 'LANDING_IS_LOCK'
720 )
721 ));
722 return $result;
723 }
724 }
725 return $result;
726 }
727
733 protected static function saveAdditionalFields(Entity\Event $event)
734 {
735 $result = new Entity\EventResult();
736
737 if (!empty(self::$additionalFields))
738 {
739 $primary = $event->getParameter('primary');
741 $primary['ID'],
742 self::$additionalFields
743 );
744 }
745
746 return $result;
747 }
748
754 protected static function revertCode(Entity\Event $event): void
755 {
756 $primary = $event->getParameter('primary');
757 $fields = $event->getParameter('fields');
758
760 {
761 return;
762 }
763
764 if (isset($primary['ID']) && array_key_exists('CODE', $fields))
765 {
766 $landingId = (int)$primary['ID'];
767 $updateCode = false;
768
770
771 $landing = Landing::createInstance($landingId);
772
773 if ($landing->getMeta()['RULE'])
774 {
776 return;
777 }
778
779 if ($landing->exist())
780 {
781 if ($fields['FOLDER_ID'] ?? null)
782 {
783 $res = self::getList([
784 'select' => [
785 'ID'
786 ],
787 'filter' => [
788 '!ID' => $primary['ID'],
789 'FOLDER_ID' => $fields['FOLDER_ID'],
790 '=CODE' => $fields['CODE']
791 ]
792 ]);
793 if ($res->fetch())
794 {
795 $updateCode = true;
796 }
797 }
798 else
799 {
800 $landingUrl = $landing->getPublicUrl(false, false);
801 $resolvedId = Landing::resolveIdByPublicUrl($landingUrl, $landing->getSiteId());
802 if ($resolvedId && $landingId !== $resolvedId)
803 {
804 $updateCode = true;
805 }
806 }
807 }
808
810
811 if ($updateCode)
812 {
814 $reUpdate = [
815 'CODE' => $fields['CODE'] . '_' . Manager::getRandomString(4)
816 ];
817 if (self::$additionalFields)
818 {
819 $reUpdate['ADDITIONAL_FIELDS'] = self::$additionalFields;
820 }
821 parent::update($landingId, $reUpdate);
823 }
824 }
825 }
826
832 public static function OnAfterAdd(Entity\Event $event)
833 {
834 $primary = $event->getParameter('primary');
835 $fields = $event->getParameter('fields');
836
837 // set current landing as index, if this is single page
838 if ($primary && isset($fields['SITE_ID']))
839 {
840 $res = self::getList(array(
841 'select' => array(
842 'ID'
843 ),
844 'filter' => array(
845 'SITE_ID' => $fields['SITE_ID'],
846 'CHECK_PERMISSIONS' => 'N'
847 ),
848 'limit' => 2
849 ));
850 if (count($res->fetchAll()) == 1)
851 {
853 SiteTable::update($fields['SITE_ID'], array(
854 'LANDING_ID_INDEX' => $primary['ID']
855 ));
857 }
858 }
859
860 self::revertCode($event);
861
862 return self::saveAdditionalFields($event);
863 }
864
870 public static function OnAfterUpdate(Entity\Event $event)
871 {
872 $primary = $event->getParameter('primary');
873 $fields = $event->getParameter('fields');
874
875 if ($primary)
876 {
877 Cache::clear($primary['ID']);
878 }
879
880 // for B24 we must update domain
881 if (
882 array_key_exists('SITE_ID', $fields) &&
884 )
885 {
886 \Bitrix\Landing\Site::update(
887 $fields['SITE_ID'],
888 array()
889 );
890 }
891
892 self::revertCode($event);
893
894 return self::saveAdditionalFields($event);
895 }
896
902 public static function OnAfterDelete(Entity\Event $event)
903 {
904 $primary = $event->getParameter('primary');
905
906 if (isset($primary['ID']))
907 {
909
910 \Bitrix\Landing\File::deleteFromLanding($primary['ID']);
911 \Bitrix\Landing\Syspage::deleteForLanding($primary['ID']);
912 \Bitrix\Landing\Hook::deleteForLanding($primary['ID']);
913 \Bitrix\Landing\TemplateRef::deleteArea($primary['ID']);
914 \Bitrix\Landing\TemplateRef::setForLanding($primary['ID'], array());
915 \Bitrix\Landing\UrlRewrite::removeForLanding($primary['ID']);
916
917 // if delete index page, make new page is index
918 $res = \Bitrix\Landing\Site::getList(array(
919 'select' => array(
920 'ID'
921 ),
922 'filter' => array(
923 'LANDING_ID_INDEX' => $primary['ID']
924 )
925 ));
926 if ($site = $res->fetch())
927 {
928 $res = Landing::getList(array(
929 'select' => array(
930 'ID'
931 ),
932 'filter' => array(
933 'SITE_ID' => $site['ID']
934 ),
935 'order' => array(
936 'ID' => 'asc'
937 )
938 ));
939 while ($page = $res->fetch())
940 {
941 if (!TemplateRef::landingIsArea($page['ID']))
942 {
943 \Bitrix\Landing\Site::update(
944 $site['ID'],
945 array(
946 'LANDING_ID_INDEX' => $page['ID']
947 )
948 );
949 break;
950 }
951 }
952 }
953
955 }
956 }
957}
static getList(array $params=array())
Definition landing.php:602
static prepareChange(Entity\Event $event, $actionType)
Definition landing.php:279
static OnBeforeDelete(Entity\Event $event)
Definition landing.php:678
static revertCode(Entity\Event $event)
Definition landing.php:754
static OnAfterDelete(Entity\Event $event)
Definition landing.php:902
static OnAfterUpdate(Entity\Event $event)
Definition landing.php:870
static OnBeforeAdd(Entity\Event $event)
Definition landing.php:658
static saveAdditionalFields(Entity\Event $event)
Definition landing.php:733
static OnBeforeUpdate(Entity\Event $event)
Definition landing.php:668
static OnAfterAdd(Entity\Event $event)
Definition landing.php:832
static disableCheckDeleted()
Definition landing.php:469
static disableCheckUniqueAddress()
Definition landing.php:514
static isCheckUniqueAddress()
Definition landing.php:505
static resolveIdByPublicUrl(string $landingUrl, int $siteId)
Definition landing.php:1096
static enableCheckDeleted()
Definition landing.php:478
static createInstance($id, array $params=array())
Definition landing.php:534
static saveAdditionalFields($id, array $data)
Definition landing.php:782
static enableCheckUniqueAddress()
Definition landing.php:523
static isLandingDeleteLocked(int $landingId)
Definition lock.php:122
static getRandomString(int $length)
Definition manager.php:551
static getAccessFilter(array $additionalFilterOr=[])
Definition rights.php:724
static getOperationsForSite($siteId)
Definition rights.php:518
static isExtendedMode()
Definition rights.php:781
static getAllowedSites()
Definition rights.php:156
static hasAccessForSite($siteId, $accessType, $deleted=false)
Definition rights.php:544
static getExpectedRoleIds()
Definition role.php:566
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getList(array $parameters=array())