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