forked from civicrm/civicrm-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModule.php
107 lines (96 loc) · 2.73 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* This class stores logic for managing CiviCRM extensions.
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
class CRM_Extension_Manager_Module extends CRM_Extension_Manager_Base {
/**
* @param CRM_Extension_Mapper $mapper
*/
public function __construct(CRM_Extension_Mapper $mapper) {
parent::__construct(FALSE);
$this->mapper = $mapper;
}
/**
* @param CRM_Extension_Info $info
*/
public function onPreInstall(CRM_Extension_Info $info) {
$this->registerClassloader($info);
$this->callHook($info, 'install');
$this->callHook($info, 'enable');
}
/**
* @param CRM_Extension_Info $info
*/
public function onPostPostInstall(CRM_Extension_Info $info) {
$this->callHook($info, 'postInstall');
}
/**
* @param CRM_Extension_Info $info
* @param string $hookName
*/
private function callHook(CRM_Extension_Info $info, $hookName) {
try {
$file = $this->mapper->keyToPath($info->key);
}
catch (CRM_Extension_Exception $e) {
return;
}
if (!file_exists($file)) {
return;
}
include_once $file;
$fnName = "{$info->file}_civicrm_{$hookName}";
if (function_exists($fnName)) {
$fnName();
}
if ($info->upgrader) {
$this->mapper->getUpgrader($info->key)->notify($hookName);
}
}
/**
* @param CRM_Extension_Info $info
*
* @return bool
*/
public function onPreUninstall(CRM_Extension_Info $info) {
$this->registerClassloader($info);
$this->callHook($info, 'uninstall');
return TRUE;
}
/**
* @param CRM_Extension_Info $info
*/
public function onPostUninstall(CRM_Extension_Info $info) {
}
/**
* @param CRM_Extension_Info $info
*/
public function onPreDisable(CRM_Extension_Info $info) {
$this->callHook($info, 'disable');
}
/**
* @param CRM_Extension_Info $info
*/
public function onPreEnable(CRM_Extension_Info $info) {
$this->registerClassloader($info);
$this->callHook($info, 'enable');
}
/**
* @param CRM_Extension_Info $info
*/
private function registerClassloader($info) {
CRM_Extension_System::singleton()->getClassLoader()->installExtension($info, dirname($this->mapper->keyToPath($info->key)));
}
}