Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sitesdata.php
1<?php
2namespace Bitrix\Scale;
4
10{
16 public static function getSite($siteName, $dbName = false)
17 {
18 if($siteName == '')
19 throw new \Bitrix\Main\ArgumentNullException("siteName");
20
21 $result = array();
22 $sites = self::getList($dbName);
23
24 if(isset($sites[$siteName]))
25 $result = $sites[$siteName];
26
27 return $result;
28 }
29
33 public static function getKernelSite()
34 {
35 foreach(self::getList() as $siteId => $siteParams)
36 if($siteParams['SiteInstall'] == 'kernel')
37 return $siteId;
38
39 return '';
40 }
41
45 public static function getKernelsList()
46 {
47 $result = array();
48
49 foreach(self::getList() as $siteId => $siteParams)
50 if($siteParams['SiteInstall'] == 'kernel')
51 $result[$siteId] = isset($siteParams['NAME']) ? $siteParams['NAME'] : $siteId;
52
53 return $result;
54 }
55
59 public static function getKernelRoot()
60 {
61 foreach(self::getList() as $siteId => $siteParams)
62 if($siteParams['SiteInstall'] == 'kernel')
63 return $siteParams['DocumentRoot'];
64
65 return '';
66 }
67
72 public static function getList($dbName = false)
73 {
74 static $hitCache = null;
75
76 if($hitCache === null)
77 {
78 $resSite = array();
79 $shellAdapter = new ShellAdapter();
80 $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-sites -o json -a list --hiden");
81 $sitesData = $shellAdapter->getLastOutput();
82
83 if($execRes)
84 {
85 $arData = json_decode($sitesData, true);
86
87 if(isset($arData["params"]))
88 $resSite = $arData["params"];
89
90 $domains = array();
91 $sdRes = SiteDomainTable::getList();
92
93 while($dom = $sdRes->fetch())
94 {
95 if(isset($domains[$dom['LID']]))
96 $domains[$dom['LID']] .= ', ';
97 else
98 $domains[$dom['LID']] = '';
99
100 $domains[$dom['LID']] .= $dom['DOMAIN'];
101 }
102
103 $rsSite = \Bitrix\Main\SiteTable::getList();
104
105 while ($site = $rsSite->fetch())
106 {
107 foreach($resSite as $siteId => $siteInfo)
108 {
109 $docRoot = $site["DOC_ROOT"] <> '' ? $site["DOC_ROOT"] : \Bitrix\Main\Application::getDocumentRoot();
110
111 if($siteInfo["DocumentRoot"] == $docRoot)
112 {
113 $resSite[$siteId]["NAME"] = $site["NAME"]." (".$site["LID"].") ";
114 $resSite[$siteId]["LID"] = $site["LID"];
115 $resSite[$siteId]["EMAIL"] = $site["EMAIL"];
116 $resSite[$siteId]["DOMAINS"] = isset($domains[$site["LID"]]) ? $domains[$site["LID"]] : '';
117 }
118 else
119 {
120 $resSite[$siteId]["NAME"] = $siteId;
121 }
122
123 $resSite[$siteId]["SMTP_USE_AUTH"] = ($siteInfo['SMTPPassword'] !== null && $siteInfo['SMTPUser'] !== null) ? 'Y' : 'N';
124 }
125 }
126 }
127
128 $hitCache = $resSite;
129 }
130
131 if($dbName != false && !empty($hitCache))
132 {
133 $result = array();
134
135 foreach($hitCache as $siteId => $siteInfo)
136 if($siteInfo['DBName'] == $dbName)
137 $result[$siteId] = $siteInfo;
138 }
139 else
140 {
141 $result = $hitCache;
142 }
143
144 return $result;
145 }
146}
static getList($dbName=false)
Definition sitesdata.php:72
static getSite($siteName, $dbName=false)
Definition sitesdata.php:16