Merge pull request #22548 from eileenmcnaughton/raw
[civicrm-core.git] / CRM / Extension / Manager / Module.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 * This class stores logic for managing CiviCRM extensions.
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
17 */
18class CRM_Extension_Manager_Module extends CRM_Extension_Manager_Base {
19
e0ef6999
EM
20 /**
21 * @param CRM_Extension_Mapper $mapper
22 */
6a488035
TO
23 public function __construct(CRM_Extension_Mapper $mapper) {
24 parent::__construct(FALSE);
25 $this->mapper = $mapper;
26 }
27
e0ef6999
EM
28 /**
29 * @param CRM_Extension_Info $info
30 */
6a488035 31 public function onPreInstall(CRM_Extension_Info $info) {
c09b5c5b 32 $this->registerClassloader($info);
6a488035
TO
33 $this->callHook($info, 'install');
34 $this->callHook($info, 'enable');
35 }
36
e0ef6999
EM
37 /**
38 * @param CRM_Extension_Info $info
39 */
3d0e24ec 40 public function onPostPostInstall(CRM_Extension_Info $info) {
41 $this->callHook($info, 'postInstall');
42 }
43
e0ef6999
EM
44 /**
45 * @param CRM_Extension_Info $info
100fef9d 46 * @param string $hookName
e0ef6999 47 */
6a488035
TO
48 private function callHook(CRM_Extension_Info $info, $hookName) {
49 try {
50 $file = $this->mapper->keyToPath($info->key);
0db6c3e1
TO
51 }
52 catch (CRM_Extension_Exception $e) {
6a488035
TO
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 }
ce9781c5
TO
63 if ($info->upgrader) {
64 $this->mapper->getUpgrader($info->key)->notify($hookName);
65 }
6a488035
TO
66 }
67
e0ef6999
EM
68 /**
69 * @param CRM_Extension_Info $info
70 *
71 * @return bool
72 */
6a488035 73 public function onPreUninstall(CRM_Extension_Info $info) {
c09b5c5b 74 $this->registerClassloader($info);
6a488035
TO
75 $this->callHook($info, 'uninstall');
76 return TRUE;
77 }
78
e0ef6999
EM
79 /**
80 * @param CRM_Extension_Info $info
81 */
6a488035 82 public function onPostUninstall(CRM_Extension_Info $info) {
6a488035
TO
83 }
84
e0ef6999
EM
85 /**
86 * @param CRM_Extension_Info $info
87 */
6a488035
TO
88 public function onPreDisable(CRM_Extension_Info $info) {
89 $this->callHook($info, 'disable');
90 }
91
e0ef6999
EM
92 /**
93 * @param CRM_Extension_Info $info
94 */
6a488035 95 public function onPreEnable(CRM_Extension_Info $info) {
c09b5c5b 96 $this->registerClassloader($info);
6a488035
TO
97 $this->callHook($info, 'enable');
98 }
96025800 99
c09b5c5b
TO
100 /**
101 * @param CRM_Extension_Info $info
102 */
103 private function registerClassloader($info) {
dde93836
TO
104 try {
105 $extPath = dirname($this->mapper->keyToPath($info->key));
106 }
107 catch (CRM_Extension_Exception_MissingException $e) {
108 // This could happen if there was a dirty removal (i.e. deleting ext-code before uninstalling).
109 return;
110 }
111
112 $classloader = CRM_Extension_System::singleton()->getClassLoader();
113 $classloader->installExtension($info, $extPath);
c09b5c5b
TO
114 }
115
6a488035 116}