Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
modulemanager.php
1<?php
2namespace Bitrix\Main;
3
5{
6 protected const CACHE_ID = 'b_module';
7
8 protected static $installedModules = [];
9
10 public static function getInstalledModules()
11 {
12 if (empty(self::$installedModules))
13 {
14 $cacheManager = Application::getInstance()->getManagedCache();
15 if ($cacheManager->read(3600, self::CACHE_ID))
16 {
17 self::$installedModules = $cacheManager->get(self::CACHE_ID);
18 }
19
20 if (empty(self::$installedModules))
21 {
22 self::$installedModules = [];
24 $rs = $con->query("SELECT ID FROM b_module ORDER BY ID");
25 while ($ar = $rs->fetch())
26 {
27 self::$installedModules[$ar['ID']] = $ar;
28 }
29 $cacheManager->set(self::CACHE_ID, self::$installedModules);
30 }
31 }
32
34 }
35
36 public static function getVersion($moduleName)
37 {
38 $moduleName = preg_replace("/[^a-zA-Z0-9_.]+/i", "", trim($moduleName));
39 if ($moduleName == '')
40 return false;
41
42 if (!self::isModuleInstalled($moduleName))
43 return false;
44
45 if ($moduleName == 'main')
46 {
47 if (!defined("SM_VERSION"))
48 {
49 include_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/classes/general/version.php");
50 }
51 $version = SM_VERSION;
52 }
53 else
54 {
55 $modulePath = getLocalPath("modules/".$moduleName."/install/version.php");
56 if ($modulePath === false)
57 return false;
58
59 $arModuleVersion = [];
60 include($_SERVER["DOCUMENT_ROOT"].$modulePath);
61 $version = (array_key_exists("VERSION", $arModuleVersion)? $arModuleVersion["VERSION"] : false);
62 }
63
64 return $version;
65 }
66
67 public static function isModuleInstalled($moduleName)
68 {
69 $arInstalledModules = self::getInstalledModules();
70 return isset($arInstalledModules[$moduleName]);
71 }
72
73 public static function delete($moduleName)
74 {
76 $module = $con->getSqlHelper()->forSql($moduleName);
77
78 $con->queryExecute("DELETE FROM b_module WHERE ID = '" . $module . "'");
79 $con->queryExecute("UPDATE b_agent SET ACTIVE = 'N' WHERE MODULE_ID = '" . $module . "' AND ACTIVE = 'Y'");
80
81 static::clearCache($moduleName);
82 }
83
84 public static function add($moduleName)
85 {
87 $module = $con->getSqlHelper()->forSql($moduleName);
88
89 $con->queryExecute("INSERT INTO b_module(ID) VALUES('" . $module . "')");
90 $con->queryExecute("UPDATE b_agent SET ACTIVE = 'Y' WHERE MODULE_ID = '" . $module . "' AND ACTIVE = 'N'");
91
92 static::clearCache($moduleName);
93 }
94
95 public static function registerModule($moduleName)
96 {
97 static::add($moduleName);
98
99 $event = new Event("main", "OnAfterRegisterModule", array($moduleName));
100 $event->send();
101 }
102
103 public static function unRegisterModule($moduleName)
104 {
105 $con = Application::getInstance()->getConnection();
106
107 $con->queryExecute("DELETE FROM b_agent WHERE MODULE_ID='".$con->getSqlHelper()->forSql($moduleName)."'");
108 \CMain::DelGroupRight($moduleName);
109
110 static::delete($moduleName);
111
112 $event = new Event("main", "OnAfterUnRegisterModule", array($moduleName));
113 $event->send();
114 }
115
116 protected static function clearCache($moduleName)
117 {
118 self::$installedModules = [];
119 Application::getInstance()->getManagedCache()->clean(self::CACHE_ID);
120
121 Loader::clearModuleCache($moduleName);
122 EventManager::getInstance()->clearLoadedHandlers();
123 }
124
125 public static function isValidModule(string $moduleName): bool
126 {
127 $originalModuleName = $moduleName;
128 $moduleName = preg_replace("/[^a-zA-Z0-9_.]+/i", "", trim($moduleName));
129
130 return $moduleName === $originalModuleName;
131 }
132}
static getConnection($name="")
static clearModuleCache($moduleName)
Definition loader.php:233
static add($moduleName)
static isValidModule(string $moduleName)
static clearCache($moduleName)
static unRegisterModule($moduleName)
static registerModule($moduleName)
static isModuleInstalled($moduleName)
static getVersion($moduleName)