Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
domainua.php
1<?php
2
4
9
13class DomainUa extends Update
14{
15 protected const DOMAIN_UA = '.bitrix24site.ua';
16 protected const OPTION_IS_FORM_REBUILD = 'is_ua_forms_rebuild';
17
23 public static function update(int $siteId): bool
24 {
25 $site = self::getId($siteId);
26 $domainId = (int)$site['DOMAIN_ID'];
27
28
29 if (!self::isNeedDomainUpdate($domainId))
30 {
31 return true;
32 }
33
34 if (
35 !self::updateDomain($domainId, $site)
36 || !self::unPublicationPages($siteId)
37 )
38 {
39 return false;
40 }
41
42 if (self::isNeedFormsUpdate())
43 {
45 }
46
47 return true;
48 }
49
59 protected static function isNeedDomainUpdate(int $domainId): bool
60 {
61 $res = DomainTable::getList([
62 'select' => [
63 'ID', 'DOMAIN',
64 ],
65 'filter' => [
66 'ID' => $domainId,
67 ],
68 ]);
69 if ($row = $res->fetch())
70 {
71 // todo: check if it is our domain?
72 $domainLength = strlen(self::DOMAIN_UA);
73
74 return substr($row['DOMAIN'], -1 * $domainLength) === self::DOMAIN_UA;
75 }
76
77 return false;
78 }
79
87 protected static function updateDomain(int $domainId, array $site): bool
88 {
89 try
90 {
91 $siteController = Manager::getExternalSiteController();
92 if ($siteController)
93 {
94 $publicUrl = Manager::getPublicationPath($site['ID']);
95 $zone = Manager::getZone();
96 $domainName = $siteController::addRandomDomain(
97 $publicUrl,
98 $site['TYPE'],
99 $zone === 'ua' ? 'eu' : $zone
100 );
101
102
103 if ($domainName)
104 {
105 // todo: need set prev id?
106 $resDomain = DomainTable::update($domainId, [
107 'DOMAIN' => $domainName,
108 ]);
109
110 return $resDomain->isSuccess();
111 }
112 }
113 }
114 catch (SystemException $ex)
115 {
116 }
117
118 return false;
119 }
120
130 protected static function unPublicationPages(int $siteId): bool
131 {
132 $res = LandingTable::getList([
133 'select' => ['ID'],
134 'filter' => [
135 'SITE_ID' => $siteId,
136 'ACTIVE' => 'Y',
137 ],
138 ]);
139 while ($landing = $res->fetch())
140 {
141 $resUpdate = LandingTable::update($landing['ID'], [
142 'ACTIVE' => 'N',
143 'PUBLIC' => 'N',
144 ]);
145
146 if (!$resUpdate->isSuccess())
147 {
148 return false;
149 }
150 }
151
152 return true;
153 }
154
159 protected static function isNeedFormsUpdate(): bool
160 {
161 $option = Manager::getOption(self::OPTION_IS_FORM_REBUILD, 'N');
162
163
164 return $option === 'N';
165 }
166
171 protected static function updateForms(): bool
172 {
173 \CAgent::AddAgent(
174 '\\Bitrix\\Crm\\UI\\Webpack\\Guest::rebuildAgent();',
175 "crm",
176 "N",
177 60,
178 "",
179 "Y",
180 \ConvertTimeStamp(time() + \CTimeZone::GetOffset() + 60, "FULL")
181 );
182
183 \CAgent::AddAgent(
184 '\\Bitrix\\Crm\\WebForm\\Manager::updateScriptCacheAgent();',
185 "crm",
186 "N",
187 60,
188 "",
189 "Y",
190 \ConvertTimeStamp(time() + \CTimeZone::GetOffset() + 100, "FULL")
191 );
192
193 \CAgent::AddAgent(
194 '\\Bitrix\\Crm\\SiteButton\\Manager::updateScriptCacheAgent();',
195 "crm",
196 "N",
197 60,
198 "",
199 "Y",
200 \ConvertTimeStamp(time() + \CTimeZone::GetOffset() + 300, "FULL")
201 );
202
203 \CAgent::AddAgent(
204 '\\Bitrix\\Crm\\UI\\Webpack\\CallTracker::rebuildAgent();',
205 "crm",
206 "N",
207 60,
208 "",
209 "Y",
210 \ConvertTimeStamp(time() + \CTimeZone::GetOffset() + 400, "FULL")
211 );
212
213 \CAgent::AddAgent(
214 '\\Bitrix\\Crm\\UI\\Webpack\\CallTrackerEditor::rebuildAgent();',
215 "crm",
216 "N",
217 60,
218 "",
219 "Y",
220 \ConvertTimeStamp(time() + \CTimeZone::GetOffset() + 450, "FULL")
221 );
222
223 Manager::setOption(self::OPTION_IS_FORM_REBUILD, 'Y');
224
225 // now is always true. If error - rebuild forms manually, not by updater
226 return true;
227 }
228}
static getList(array $params=array())
Definition landing.php:602
static getOption($code, $default=null)
Definition manager.php:160
static setOption($code, $value)
Definition manager.php:171
static getPublicationPath($siteCode=null, $siteId=null, $createPubPath=false)
Definition manager.php:396
static getExternalSiteController()
Definition manager.php:1324
static unPublicationPages(int $siteId)
Definition domainua.php:130
static updateDomain(int $domainId, array $site)
Definition domainua.php:87
static isNeedDomainUpdate(int $domainId)
Definition domainua.php:59
static getId(int $siteId)
Definition update.php:18