Commit | Line | Data |
---|---|---|
ca7abfcc TO |
1 | <?php |
2 | namespace Civi\Test\CiviEnvBuilder; | |
3 | class ExtensionsStep implements StepInterface { | |
4 | private $action; | |
5 | private $names; | |
6 | ||
7 | /** | |
8 | * ExtensionStep constructor. | |
9 | * @param string $action | |
10 | * Ex: 'install', 'uninstall'. | |
11 | * @param string|array $names | |
12 | */ | |
13 | public function __construct($action, $names) { | |
14 | $this->action = $action; | |
15 | $this->names = (array) $names; | |
16 | } | |
17 | ||
18 | public function getSig() { | |
19 | return 'ext:' . implode(',', $this->names); | |
20 | } | |
21 | ||
22 | public function isValid() { | |
23 | if (!in_array($this->action, array('install', 'uninstall'))) { | |
24 | return FALSE; | |
25 | } | |
26 | foreach ($this->names as $name) { | |
27 | if (!is_string($name)) { | |
28 | return FALSE; | |
29 | } | |
30 | } | |
31 | return TRUE; | |
32 | } | |
33 | ||
34 | public function run($ctx) { | |
35 | $allKeys = \CRM_Extension_System::singleton()->getFullContainer()->getKeys(); | |
36 | $names = \CRM_Utils_String::filterByWildcards($this->names, $allKeys, TRUE); | |
37 | ||
38 | $manager = \CRM_Extension_System::singleton()->getManager(); | |
39 | switch ($this->action) { | |
40 | case 'install': | |
41 | $manager->install($names); | |
42 | break; | |
43 | ||
44 | case 'uninstall': | |
45 | $manager->disable($names); | |
46 | $manager->uninstall($names); | |
47 | break; | |
48 | } | |
49 | } | |
50 | ||
51 | } |