drupal-civicrm/sites/all/modules/civicrm/Civi/Test/CiviEnvBuilder/ExtensionsStep.php

52 lines
1.2 KiB
PHP
Raw Normal View History

2018-01-14 15:10:16 +02:00
<?php
namespace Civi\Test\CiviEnvBuilder;
class ExtensionsStep implements StepInterface {
private $action;
private $names;
/**
* ExtensionStep constructor.
* @param string $action
* Ex: 'install', 'uninstall'.
* @param string|array $names
*/
public function __construct($action, $names) {
$this->action = $action;
$this->names = (array) $names;
}
public function getSig() {
return 'ext:' . implode(',', $this->names);
}
public function isValid() {
if (!in_array($this->action, array('install', 'uninstall'))) {
return FALSE;
}
foreach ($this->names as $name) {
if (!is_string($name)) {
return FALSE;
}
}
return TRUE;
}
public function run($ctx) {
$allKeys = \CRM_Extension_System::singleton()->getFullContainer()->getKeys();
$names = \CRM_Utils_String::filterByWildcards($this->names, $allKeys, TRUE);
$manager = \CRM_Extension_System::singleton()->getManager();
switch ($this->action) {
case 'install':
$manager->install($names);
break;
case 'uninstall':
$manager->disable($names);
$manager->uninstall($names);
break;
}
}
}