1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
modulemanager.php
См. документацию.
1<?php
2
3namespace Bitrix\Main;
4
6{
7 protected static $installedModules = [];
8
9 public static function getInstalledModules()
10 {
11 if (empty(static::$installedModules))
12 {
14 'select' => ['ID'],
15 'order' => ['ID' => 'ASC'],
16 'cache' => ['ttl' => 86400],
17 ]);
18 while ($ar = $rs->fetch())
19 {
20 static::$installedModules[$ar['ID']] = $ar;
21 }
22 }
23
24 return static::$installedModules;
25 }
26
32 public static function getModulesFromDisk($withLocal = true, $withPartners = true, $withKernel = true)
33 {
34 $modules = [];
35
36 $folders = [
37 "/bitrix/modules",
38 ];
39
40 if ($withLocal)
41 {
42 $folders[] = "/local/modules";
43 }
44
45 foreach ($folders as $folder)
46 {
47 $folderPath = $_SERVER["DOCUMENT_ROOT"] . $folder;
48 $handle = null;
49
50 if (is_dir($folderPath) && is_readable($folderPath))
51 {
52 $handle = opendir($folderPath);
53 }
54
55 if (!empty($handle))
56 {
57 while (false !== ($dir = readdir($handle)))
58 {
59 if (
60 !isset($modules[$dir])
61 && is_dir($folderPath . '/' . $dir)
62 && !in_array($dir, ['.', '..'], true)
63 && ($withPartners || !str_contains($dir, '.'))
64 && ($withKernel || str_contains($dir, '.'))
65 )
66 {
67 if ($info = \CModule::CreateModuleObject($dir))
68 {
69 $modules[$dir]["id"] = $info->MODULE_ID;
70 $modules[$dir]["name"] = $info->MODULE_NAME;
71 $modules[$dir]["description"] = $info->MODULE_DESCRIPTION;
72 $modules[$dir]["version"] = $info->MODULE_VERSION;
73 $modules[$dir]["versionDate"] = $info->MODULE_VERSION_DATE;
74 $modules[$dir]["sort"] = $info->MODULE_SORT;
75 $modules[$dir]["partner"] = $info->PARTNER_NAME;
76 $modules[$dir]["partnerUri"] = $info->PARTNER_URI;
77 $modules[$dir]["isInstalled"] = $info->IsInstalled();
78 }
79 }
80 }
81
82 closedir($handle);
83 }
84 }
85
86 return $modules;
87 }
88
89 public static function getVersion($moduleName)
90 {
91 if (!static::isValidModule($moduleName))
92 {
93 return false;
94 }
95
96 if (!static::isModuleInstalled($moduleName))
97 {
98 return false;
99 }
100
101 if ($moduleName == 'main')
102 {
103 if (!defined("SM_VERSION"))
104 {
105 include_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/version.php");
106 }
107 $version = SM_VERSION;
108 }
109 else
110 {
111 $modulePath = getLocalPath("modules/" . $moduleName . "/install/version.php");
112 if ($modulePath === false)
113 {
114 return false;
115 }
116
117 $arModuleVersion = [];
118 include($_SERVER["DOCUMENT_ROOT"] . $modulePath);
119 $version = (array_key_exists("VERSION", $arModuleVersion) ? $arModuleVersion["VERSION"] : false);
120 }
121
122 return $version;
123 }
124
125 public static function isModuleInstalled($moduleName)
126 {
127 if (empty(static::$installedModules))
128 {
129 static::getInstalledModules();
130 }
131
132 return isset(static::$installedModules[$moduleName]);
133 }
134
135 public static function delete($moduleName)
136 {
137 ModuleTable::delete($moduleName);
138
140 $module = $con->getSqlHelper()->forSql($moduleName);
141 $con->queryExecute("UPDATE b_agent SET ACTIVE = 'N' WHERE MODULE_ID = '" . $module . "' AND ACTIVE = 'Y'");
142
143 static::clearCache($moduleName);
144 }
145
146 public static function add($moduleName)
147 {
148 ModuleTable::add(['ID' => $moduleName]);
149
151 $module = $con->getSqlHelper()->forSql($moduleName);
152 $con->queryExecute("UPDATE b_agent SET ACTIVE = 'Y' WHERE MODULE_ID = '" . $module . "' AND ACTIVE = 'N'");
153
154 static::clearCache($moduleName);
155 }
156
157 public static function registerModule($moduleName)
158 {
159 static::add($moduleName);
160
161 $event = new Event("main", "OnAfterRegisterModule", [$moduleName]);
162 $event->send();
163 }
164
165 public static function unRegisterModule($moduleName)
166 {
167 \CAgent::RemoveModuleAgents($moduleName);
168 \CMain::DelGroupRight($moduleName);
169
170 static::delete($moduleName);
171
172 $event = new Event("main", "OnAfterUnRegisterModule", [$moduleName]);
173 $event->send();
174 }
175
176 protected static function clearCache($moduleName)
177 {
178 static::$installedModules = [];
179
180 Loader::clearModuleCache($moduleName);
181 EventManager::getInstance()->clearLoadedHandlers();
182 }
183
184 public static function isValidModule(string $moduleName): bool
185 {
186 $originalModuleName = $moduleName;
187 $moduleName = preg_replace("/[^a-zA-Z0-9_.]+/i", "", trim($moduleName));
188
189 return $moduleName === $originalModuleName;
190 }
191
192 public static function decreaseVersion(string $moduleId, int $count, ?string $fromVersion = null): ?string
193 {
194 if (!self::isValidModule($moduleId))
195 {
196 return null;
197 }
198
199 if ($moduleId === 'main')
200 {
201 $versionFile = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/classes/general/version.php';
202 }
203 else
204 {
205 $versionFile = $_SERVER['DOCUMENT_ROOT'] . getLocalPath('modules/' . $moduleId . '/install/version.php');
206 }
207
208 $count = $count > 0 ? $count : 1;
209
210 if (file_exists($versionFile) && is_file($versionFile))
211 {
212 $fileContent = file_get_contents($versionFile);
213
214 if (preg_match("/(\\d+)\\.(\\d+)\\.(\\d+)/", $fileContent, $match))
215 {
216 $oldVersion = $match[0];
217
218 if ($fromVersion !== null)
219 {
220 if (!preg_match("/(\\d+)\\.(\\d+)\\.(\\d+)/", $fromVersion, $match))
221 {
222 return null;
223 }
224 }
225
226 if ($match[3] - $count >= 0)
227 {
228 $match[3] -= $count;
229 }
230 else
231 {
232 $match[3] = 10000 - $count + (int)$match[3];
233 if ($match[2] == 0)
234 {
235 $match[2] = 9999;
236 $match[1] -= 1;
237 }
238 else
239 {
240 $match[2] -= 1;
241 }
242 }
243
244 if ($match[1] > 0 && $match[2] >= 0 && $match[3] >= 0)
245 {
246 $fileContent = str_replace($oldVersion, $match[1] . '.' . $match[2] . '.' . $match[3], $fileContent);
247 file_put_contents($versionFile, $fileContent);
248
249 Application::resetAccelerator($versionFile);
250 }
251
252 return $match[1] . '.' . $match[2] . '.' . $match[3];
253 }
254 }
255
256 return null;
257 }
258}
$con
Определения admin_tab.php:7
$count
Определения admin_tab.php:4
static resetAccelerator(string $filename=null)
Определения application.php:786
static getConnection($name="")
Определения application.php:638
Определения event.php:5
static getInstance()
Определения eventmanager.php:31
static clearModuleCache($moduleName)
Определения loader.php:233
static add($moduleName)
Определения modulemanager.php:146
static getModulesFromDisk($withLocal=true, $withPartners=true, $withKernel=true)
Определения modulemanager.php:32
static isValidModule(string $moduleName)
Определения modulemanager.php:184
static clearCache($moduleName)
Определения modulemanager.php:176
static unRegisterModule($moduleName)
Определения modulemanager.php:165
static getInstalledModules()
Определения modulemanager.php:9
static $installedModules
Определения modulemanager.php:7
static registerModule($moduleName)
Определения modulemanager.php:157
static isModuleInstalled($moduleName)
Определения modulemanager.php:125
static getVersion($moduleName)
Определения modulemanager.php:89
static decreaseVersion(string $moduleId, int $count, ?string $fromVersion=null)
Определения modulemanager.php:192
static getList(array $parameters=array())
Определения datamanager.php:431
static delete($primary)
Определения datamanager.php:1644
static add(array $data)
Определения datamanager.php:877
$fileContent
Определения file_property.php:47
$handle
Определения include.php:55
$moduleId
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
const SM_VERSION
Определения version.php:2
$modules
Определения bitrix.php:26
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
getLocalPath($path, $baseFolder="/bitrix")
Определения tools.php:5092
$event
Определения prolog_after.php:141
$ar
Определения options.php:199
$dir
Определения quickway.php:303
$rs
Определения action.php:82