Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
lock.php
1<?php
2namespace Bitrix\Landing;
3
4use \Bitrix\Main\Entity;
5use \Bitrix\Main\ORM\Query\Result as QueryResult;
6use \Bitrix\Landing\Internals\LockTable;
7
8class Lock
9{
13 const ENTITY_TYPE_SITE = 'S';
14
19
23 const LOCK_TYPE_DELETE = 'D';
24
32 protected static function isEntityLocked(int $entityId, string $entityType, string $lockType): bool
33 {
34 return LockTable::getList([
35 'select' => [
36 'ID'
37 ],
38 'filter' => [
39 'ENTITY_ID' => $entityId,
40 '=ENTITY_TYPE' => $entityType,
41 '=LOCK_TYPE' => $lockType
42 ]
43 ])->fetch() ? true : false;
44 }
45
54 protected static function lockEntity(int $entityId, string $entityType, string $lockType, bool $lock = true): bool
55 {
56 $current = LockTable::getList([
57 'select' => [
58 'ID'
59 ],
60 'filter' => [
61 'ENTITY_ID' => $entityId,
62 '=ENTITY_TYPE' => $entityType,
63 '=LOCK_TYPE' => $lockType
64 ]
65 ])->fetch();
66 if (!$lock && isset($current['ID']))
67 {
68 return LockTable::delete($current['ID'])->isSuccess();
69 }
70 if ($lock && !isset($current['ID']))
71 {
72 return LockTable::add([
73 'ENTITY_ID' => $entityId,
74 'ENTITY_TYPE' => $entityType,
75 'LOCK_TYPE' => $lockType
76 ])->isSuccess();
77 }
78 return true;
79 }
80
86 public static function isSiteDeleteLocked(int $siteId): bool
87 {
88 if (self::isEntityLocked($siteId, self::ENTITY_TYPE_SITE, self::LOCK_TYPE_DELETE))
89 {
90 return true;
91 }
92 // check status for site's landings
93 return LockTable::getList([
94 'select' => [
95 'ID'
96 ],
97 'filter' => [
98 'LANDING.SITE_ID' => $siteId,
99 '=ENTITY_TYPE' => self::ENTITY_TYPE_LANDING,
100 '=LOCK_TYPE' => self::LOCK_TYPE_DELETE
101 ],
102 'runtime' => [
103 new Entity\ReferenceField(
104 'LANDING',
105 'Bitrix\Landing\Internals\LandingTable',
106 [
107 '=this.ENTITY_ID' => 'ref.ID',
108 '=this.ENTITY_TYPE' => [
109 '?', self::ENTITY_TYPE_LANDING
110 ]
111 ]
112 )
113 ]
114 ])->fetch() ? true : false;
115 }
116
122 public static function isLandingDeleteLocked(int $landingId): bool
123 {
124 return self::isEntityLocked($landingId, self::ENTITY_TYPE_LANDING, self::LOCK_TYPE_DELETE);
125 }
126
133 public static function lockDeleteSite(int $siteId, bool $lock = true): bool
134 {
135 if (Site::ping($siteId, !$lock))
136 {
137 return self::lockEntity($siteId, self::ENTITY_TYPE_SITE, self::LOCK_TYPE_DELETE, $lock);
138 }
139 return false;
140 }
141
148 public static function lockDeleteLanding(int $landingId, bool $lock = true): bool
149 {
150 if (Landing::ping($landingId, !$lock))
151 {
152 return self::lockEntity($landingId, self::ENTITY_TYPE_LANDING, self::LOCK_TYPE_DELETE, $lock);
153 }
154 return false;
155 }
156
162 public static function getList(array $params = []): QueryResult
163 {
164 return LockTable::getList($params);
165 }
166}
static lockDeleteSite(int $siteId, bool $lock=true)
Definition lock.php:133
static isSiteDeleteLocked(int $siteId)
Definition lock.php:86
static isEntityLocked(int $entityId, string $entityType, string $lockType)
Definition lock.php:32
const LOCK_TYPE_DELETE
Definition lock.php:23
static getList(array $params=[])
Definition lock.php:162
static isLandingDeleteLocked(int $landingId)
Definition lock.php:122
static lockEntity(int $entityId, string $entityType, string $lockType, bool $lock=true)
Definition lock.php:54
const ENTITY_TYPE_SITE
Definition lock.php:13
const ENTITY_TYPE_LANDING
Definition lock.php:18
static lockDeleteLanding(int $landingId, bool $lock=true)
Definition lock.php:148