Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| PluginManagerService | |
0.00% |
0 / 22 |
|
0.00% |
0 / 4 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| disablePlugin | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| enablePlugin | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
| getConfig | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2024 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoQtiTest\model\Service; |
| 24 | |
| 25 | use common_ext_Extension; |
| 26 | use common_ext_ExtensionsManager as ExtensionsManager; |
| 27 | use oat\generis\model\data\Ontology; |
| 28 | use oat\oatbox\reporting\Report; |
| 29 | |
| 30 | class PluginManagerService |
| 31 | { |
| 32 | private const PLUGIN_MAP = [ |
| 33 | 'allowSkipping' => 'enable-allow-skipping', |
| 34 | 'validateResponses' => 'enable-validate-responses', |
| 35 | ]; |
| 36 | private Ontology $ontology; |
| 37 | private ExtensionsManager $extensionsManager; |
| 38 | private common_ext_Extension $extension; |
| 39 | private array $config; |
| 40 | |
| 41 | public function __construct(Ontology $ontology, ExtensionsManager $extensionsManager) |
| 42 | { |
| 43 | $this->ontology = $ontology; |
| 44 | $this->extensionsManager = $extensionsManager; |
| 45 | $this->extension = $this->extensionsManager->getExtensionById('taoQtiTest'); |
| 46 | $this->config = $this->extension->getConfig('testRunner') ?? []; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @param string[] $disablePlugins |
| 51 | * @param Report $report |
| 52 | * @throws \common_exception_Error |
| 53 | */ |
| 54 | public function disablePlugin(array $disablePlugins, Report $report): void |
| 55 | { |
| 56 | foreach ($disablePlugins as $plugin) { |
| 57 | if (array_key_exists($plugin, self::PLUGIN_MAP)) { |
| 58 | $report->add(new Report(Report::TYPE_INFO, 'Plugin ' . $plugin . ' has been disabled')); |
| 59 | $this->config[self::PLUGIN_MAP[$plugin]] = false; |
| 60 | } |
| 61 | |
| 62 | if (array_key_exists($plugin, $this->config)) { |
| 63 | $report->add(new Report(Report::TYPE_INFO, 'Plugin ' . $plugin . ' has been disabled')); |
| 64 | $this->config[$plugin] = false; |
| 65 | } |
| 66 | } |
| 67 | $this->extension->setConfig('testRunner', $this->config); |
| 68 | } |
| 69 | |
| 70 | public function enablePlugin(array $enablePlugins, Report $report): void |
| 71 | { |
| 72 | $config = $this->getConfig(); |
| 73 | |
| 74 | foreach ($enablePlugins as $plugin) { |
| 75 | if (array_key_exists($plugin, self::PLUGIN_MAP)) { |
| 76 | $report->add(new Report(Report::TYPE_INFO, 'Plugin ' . $plugin . ' has been enabled')); |
| 77 | $config[self::PLUGIN_MAP[$plugin]] = true; |
| 78 | } |
| 79 | |
| 80 | if (array_key_exists($plugin, $config)) { |
| 81 | $report->add(new Report(Report::TYPE_INFO, 'Plugin ' . $plugin . ' has been disabled')); |
| 82 | $config[$plugin] = true; |
| 83 | } |
| 84 | } |
| 85 | $this->extension->setConfig('testRunner', $config); |
| 86 | } |
| 87 | |
| 88 | private function getConfig(): array |
| 89 | { |
| 90 | return $this->extensionsManager->getExtensionById('taoQtiTest')->getConfig('testRunner'); |
| 91 | } |
| 92 | } |