Bitrix-D7  20.0.0
modulemanager.php
См. документацию.
1 <?php
2 namespace Bitrix\Main;
3 
5 {
6  protected static $installedModules = array();
7 
8  public static function getInstalledModules()
9  {
10  if (empty(self::$installedModules))
11  {
12  $cacheManager = Application::getInstance()->getManagedCache();
13  if ($cacheManager->read(3600, "b_module"))
14  self::$installedModules = $cacheManager->get("b_module");
15 
16  if (empty(self::$installedModules))
17  {
18  self::$installedModules = array();
20  $rs = $con->query("SELECT ID FROM b_module ORDER BY ID");
21  while ($ar = $rs->fetch())
22  self::$installedModules[$ar['ID']] = $ar;
23  $cacheManager->set("b_module", self::$installedModules);
24  }
25  }
26 
28  }
29 
30  public static function getVersion($moduleName)
31  {
32  $moduleName = preg_replace("/[^a-zA-Z0-9_.]+/i", "", trim($moduleName));
33  if ($moduleName == '')
34  return false;
35 
36  if (!self::isModuleInstalled($moduleName))
37  return false;
38 
39  if ($moduleName == 'main')
40  {
41  if (!defined("SM_VERSION"))
42  {
43  include_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/classes/general/version.php");
44  }
45  $version = SM_VERSION;
46  }
47  else
48  {
49  $modulePath = getLocalPath("modules/".$moduleName."/install/version.php");
50  if ($modulePath === false)
51  return false;
52 
53  $arModuleVersion = array();
54  include($_SERVER["DOCUMENT_ROOT"].$modulePath);
55  $version = (array_key_exists("VERSION", $arModuleVersion)? $arModuleVersion["VERSION"] : false);
56  }
57 
58  return $version;
59  }
60 
61  public static function isModuleInstalled($moduleName)
62  {
63  $arInstalledModules = self::getInstalledModules();
64  return isset($arInstalledModules[$moduleName]);
65  }
66 
67  public static function delete($moduleName)
68  {
70  $con->queryExecute("DELETE FROM b_module WHERE ID = '".$con->getSqlHelper()->forSql($moduleName)."'");
71 
72  self::$installedModules = array();
73  Loader::clearModuleCache($moduleName);
74 
75  $cacheManager = Application::getInstance()->getManagedCache();
76  $cacheManager->clean("b_module");
77  $cacheManager->clean("b_module_to_module");
78  }
79 
80  public static function add($moduleName)
81  {
83  $con->queryExecute("INSERT INTO b_module(ID) VALUES('".$con->getSqlHelper()->forSql($moduleName)."')");
84 
85  self::$installedModules = array();
86  Loader::clearModuleCache($moduleName);
87 
88  $cacheManager = Application::getInstance()->getManagedCache();
89  $cacheManager->clean("b_module");
90  $cacheManager->clean("b_module_to_module");
91  }
92 
93  public static function registerModule($moduleName)
94  {
95  static::add($moduleName);
96 
97  $event = new Event("main", "OnAfterRegisterModule", array($moduleName));
98  $event->send();
99  }
100 
101  public static function unRegisterModule($moduleName)
102  {
103  $con = Application::getInstance()->getConnection();
104 
105  $con->queryExecute("DELETE FROM b_agent WHERE MODULE_ID='".$con->getSqlHelper()->forSql($moduleName)."'");
106  \CMain::DelGroupRight($moduleName);
107 
108  static::delete($moduleName);
109 
110  $event = new Event("main", "OnAfterUnRegisterModule", array($moduleName));
111  $event->send();
112  }
113 }
Bitrix\Main\ModuleManager\registerModule
static registerModule($moduleName)
Definition: modulemanager.php:93
Bitrix\Main\Loader\clearModuleCache
static clearModuleCache($moduleName)
Definition: main/lib/loader.php:178
Bitrix\Main\ModuleManager
Definition: modulemanager.php:4
Bitrix\Main
Bitrix\Main\ModuleManager\getInstalledModules
static getInstalledModules()
Definition: modulemanager.php:8
Bitrix\Main\ModuleManager\isModuleInstalled
static isModuleInstalled($moduleName)
Definition: modulemanager.php:61
Bitrix\Main\Event
Definition: main/lib/event.php:4
Bitrix\Main\ModuleManager\unRegisterModule
static unRegisterModule($moduleName)
Definition: modulemanager.php:101
Bitrix\Main\Application\getConnection
static getConnection($name="")
Static method returns database connection for the specified name.
Definition: main/lib/application.php:381
Bitrix\Main\Application\getInstance
static getInstance()
Returns current instance of the Application.
Definition: main/lib/application.php:86
Bitrix\Main\ModuleManager\getVersion
static getVersion($moduleName)
Definition: modulemanager.php:30
Bitrix\Main\ModuleManager\$installedModules
static $installedModules
Definition: modulemanager.php:6
Bitrix\Main\ModuleManager\add
static add($moduleName)
Definition: modulemanager.php:80