Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
domainbyupdate.php
1<?php
2
4
7
12{
13 protected const DOMAIN_SITE_BY = '.bitrix24site.by';
14 protected const DOMAIN_SHOP_BY = '.bitrix24shop.by';
15 protected const DOMAIN_SITE_ONLINE = '.b24site.online';
16 protected const DOMAIN_SHOP_ONLINE = '.b24shop.online';
17
25 public static function update(int $siteId): bool
26 {
27 $site = self::getId($siteId);
29
30 return true;
31 }
32
40 protected static function updateDomainIfNeeded(array $site): void
41 {
42 $domainId = (int)$site['DOMAIN_ID'];
43 $domainName = self::getDomainName($domainId);
44 $siteController = Manager::getExternalSiteController();
45 $publicUrl = Manager::getPublicationPath($site['ID']);
46
47 //for site
48 $domainSite = '';
49 $prevDomainSite = '';
50 if (str_ends_with($domainName, self::DOMAIN_SITE_ONLINE))
51 {
52 $res = DomainTable::getList([
53 'select' => [
54 'ID', 'DOMAIN', 'PREV_DOMAIN',
55 ],
56 'filter' => [
57 'ID' => $domainId,
58 ],
59 ]);
60 if (($row = $res->fetch()) && isset($row['DOMAIN']))
61 {
62 $domainSite = $row['DOMAIN'];
63 $prevDomainSite = $row['PREV_DOMAIN'];
64 }
65 if ($domainSite !== '' && $prevDomainSite !== '' && str_ends_with($prevDomainSite, self::DOMAIN_SITE_BY))
66 {
67 $subDomainSite = str_replace(self::DOMAIN_SITE_ONLINE, '', $domainSite);
68 $prevSubDomainSite = str_replace(self::DOMAIN_SITE_BY, '', $prevDomainSite);
69 if ($subDomainSite === $prevSubDomainSite)
70 {
71 $siteController::updateDomain(
72 $prevDomainSite,
73 $domainSite,
74 $publicUrl
75 );
76 }
77 }
78 }
79
80 //for shop
81 $domainShop = '';
82 $prevDomainShop = '';
83 if (str_ends_with($domainName, self::DOMAIN_SHOP_ONLINE))
84 {
85 $res = DomainTable::getList([
86 'select' => [
87 'ID', 'DOMAIN', 'PREV_DOMAIN',
88 ],
89 'filter' => [
90 'ID' => $domainId,
91 ],
92 ]);
93 if (($row = $res->fetch()) && isset($row['DOMAIN']))
94 {
95 $domainShop = $row['DOMAIN'];
96 $prevDomainShop = $row['PREV_DOMAIN'];
97 }
98 if ($domainShop !== '' && $prevDomainShop !== '' && str_ends_with($prevDomainShop, self::DOMAIN_SHOP_BY))
99 {
100 $subDomainShop = str_replace(self::DOMAIN_SHOP_ONLINE, '', $domainShop);
101 $prevSubDomainShop = str_replace(self::DOMAIN_SHOP_BY, '', $prevDomainShop);
102 if ($subDomainShop === $prevSubDomainShop)
103 {
104 $siteController::updateDomain(
105 $prevDomainShop,
106 $domainShop,
107 $publicUrl
108 );
109 }
110 }
111 }
112 }
113
114 protected static function getDomainName(int $domainId): string
115 {
116 $res = DomainTable::getList([
117 'select' => [
118 'ID', 'DOMAIN',
119 ],
120 'filter' => [
121 'ID' => $domainId,
122 ],
123 ]);
124 if (($row = $res->fetch()) && isset($row['DOMAIN']))
125 {
126 return $row['DOMAIN'];
127 }
128
129 return '';
130 }
131}
static getPublicationPath($siteCode=null, $siteId=null, $createPubPath=false)
Definition manager.php:396
static getExternalSiteController()
Definition manager.php:1324
static getId(int $siteId)
Definition update.php:18