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