Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
domainby.php
1<?php
2
4
8
12class DomainBy extends Update
13{
14 protected const DOMAIN_SITE_BY = '.bitrix24site.by';
15 protected const DOMAIN_SHOP_BY = '.bitrix24shop.by';
16 protected const DOMAIN_SITE_ONLINE = '.b24site.online';
17 protected const DOMAIN_SHOP_ONLINE = '.b24shop.online';
18
26 public static function update(int $siteId): bool
27 {
28 $site = self::getId($siteId);
29 $domainId = (int)$site['DOMAIN_ID'];
30 $domainName = self::getDomainName($domainId);
31 if ($domainName !== '')
32 {
33 $isNeedSiteDomainUpdate = self::isNeedSiteDomainUpdate($domainName);
34 $isNeedShopDomainUpdate = self::isNeedShopDomainUpdate($domainName);
35 if (!$isNeedSiteDomainUpdate && !$isNeedShopDomainUpdate)
36 {
37 return true;
38 }
39
40 if ($isNeedSiteDomainUpdate && !self::updateDomain($domainId, $domainName, 'site', $site))
41 {
42 return false;
43 }
44 if ($isNeedShopDomainUpdate && !self::updateDomain($domainId, $domainName, 'shop', $site))
45 {
46 return false;
47 }
48 }
49
50 return true;
51 }
52
53 protected static function getDomainName(int $domainId): string
54 {
55 $res = DomainTable::getList([
56 'select' => [
57 'ID', 'DOMAIN',
58 ],
59 'filter' => [
60 'ID' => $domainId,
61 ],
62 ]);
63 if (($row = $res->fetch()) && isset($row['DOMAIN']))
64 {
65 return $row['DOMAIN'];
66 }
67
68 return '';
69 }
70
77 protected static function isNeedSiteDomainUpdate(string $domainName): bool
78 {
79 if (str_ends_with($domainName, self::DOMAIN_SITE_BY))
80 {
81 return true;
82 }
83
84 return false;
85 }
86
93 protected static function isNeedShopDomainUpdate(string $domainName): bool
94 {
95 if (str_ends_with($domainName, self::DOMAIN_SHOP_BY))
96 {
97 return true;
98 }
99
100 return false;
101 }
102
113 protected static function updateDomain(int $domainId, string $domainName, string $type, array $site): bool
114 {
115 try
116 {
117 $siteController = Manager::getExternalSiteController();
118 $publicUrl = Manager::getPublicationPath($site['ID']);
119 if ($siteController)
120 {
121 $prevDomainName = $domainName;
122 if ($type === 'site')
123 {
124 $domainName = str_replace(self::DOMAIN_SITE_BY, self::DOMAIN_SITE_ONLINE, $domainName);
125 }
126 if ($type === 'shop')
127 {
128 $domainName = str_replace(self::DOMAIN_SHOP_BY, self::DOMAIN_SHOP_ONLINE, $domainName);
129 }
130
131 if ($domainName && !$siteController::isDomainExists($domainName))
132 {
133 $resDomain = DomainTable::update($domainId, [
134 'DOMAIN' => $domainName,
135 'PREV_DOMAIN' => $prevDomainName,
136 ]);
137
138 $siteController::updateDomain(
139 $prevDomainName,
140 $domainName,
141 $publicUrl
142 );
143
144 return $resDomain->isSuccess();
145 }
146
147 $domainName = $siteController::addRandomDomain(
148 $publicUrl,
149 $site['TYPE'],
150 'by'
151 );
152 $resDomain = DomainTable::update($domainId, [
153 'DOMAIN' => $domainName,
154 'PREV_DOMAIN' => $prevDomainName,
155 ]);
156
157 $siteController::updateDomain(
158 $prevDomainName,
159 $domainName,
160 $publicUrl
161 );
162
163 return $resDomain->isSuccess();
164 }
165 }
166 catch (SystemException)
167 {
168 }
169
170 return false;
171 }
172}
static getPublicationPath($siteCode=null, $siteId=null, $createPubPath=false)
Definition manager.php:396
static getExternalSiteController()
Definition manager.php:1324
static isNeedSiteDomainUpdate(string $domainName)
Definition domainby.php:77
static isNeedShopDomainUpdate(string $domainName)
Definition domainby.php:93
static getDomainName(int $domainId)
Definition domainby.php:53
static updateDomain(int $domainId, string $domainName, string $type, array $site)
Definition domainby.php:113
static getId(int $siteId)
Definition update.php:18