ILIAS  release_8 Revision v8.24
class.ilComponentActivatePluginsObjective.php
Go to the documentation of this file.
1<?php
2
20declare(strict_types=1);
21
22use ILIAS\Setup;
23use ILIAS\DI;
24
26{
27 protected string $plugin_name;
28
29 public function __construct(string $plugin_name)
30 {
31 $this->plugin_name = $plugin_name;
32 }
33
37 public function getHash(): string
38 {
39 return hash("sha256", self::class . $this->plugin_name);
40 }
41
45 public function getLabel(): string
46 {
47 return "Activate plugin $this->plugin_name.";
48 }
49
53 public function isNotable(): bool
54 {
55 return true;
56 }
57
61 public function getPreconditions(Setup\Environment $environment): array
62 {
63 return [
64 new \ilIniFilesLoadedObjective(),
65 new \ilDatabaseInitializedObjective(),
66 new \ilComponentPluginAdminInitObjective(),
67 new \ilComponentRepositoryExistsObjective(),
68 new \ilComponentFactoryExistsObjective()
69 ];
70 }
71
75 public function achieve(Setup\Environment $environment): Setup\Environment
76 {
77 $component_repository = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_REPOSITORY);
78 $component_factory = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_FACTORY);
79 $info = $component_repository->getPluginByName($this->plugin_name);
80
81 if (!$info->supportsCLISetup()) {
82 throw new \RuntimeException(
83 "Plugin $this->plugin_name does not support command line setup."
84 );
85 }
86
87 if (!$info->isActivationPossible()) {
88 throw new \RuntimeException(
89 "Plugin $this->plugin_name can not be activated."
90 );
91 }
92
93 $ORIG_DIC = $this->initEnvironment($environment, $component_repository, $component_factory);
94 $plugin = $component_factory->getPlugin($info->getId());
95 $plugin->activate();
96 $GLOBALS["DIC"] = $ORIG_DIC;
97
98 return $environment;
99 }
100
104 public function isApplicable(Setup\Environment $environment): bool
105 {
106 $component_repository = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_REPOSITORY);
107 $plugin = $component_repository->getPluginByName($this->plugin_name);
108
109 return $plugin->isActivationPossible($environment);
110 }
111
112 protected function initEnvironment(
113 Setup\Environment $environment,
114 \ilComponentRepository $component_repository,
115 \ilComponentFactory $component_factory
116 ) {
117 $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
118 $plugin_admin = $environment->getResource(Setup\Environment::RESOURCE_PLUGIN_ADMIN);
119 $ini = $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI);
120 $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
121
122 // ATTENTION: This is a total abomination. It only exists to allow various
123 // sub components of the various readers to run. This is a memento to the
124 // fact, that dependency injection is something we want. Currently, every
125 // component could just service locate the whole world via the global $DIC.
126 $DIC = $GLOBALS["DIC"];
127 $GLOBALS["DIC"] = new DI\Container();
128 $GLOBALS["DIC"]["component.repository"] = $component_repository;
129 $GLOBALS["DIC"]["component.factory"] = $component_factory;
130 $GLOBALS["DIC"]["ilDB"] = $db;
131 $GLOBALS["DIC"]["ilIliasIniFile"] = $ini;
132 $GLOBALS["DIC"]["ilClientIniFile"] = $client_ini;
133 $GLOBALS["DIC"]["ilLog"] = new class () extends ilLogger {
134 public function __construct()
135 {
136 }
137 public function write(string $a_message, $a_level = ilLogLevel::INFO): void
138 {
139 }
140 public function info(string $a_message): void
141 {
142 }
143 public function warning(string $a_message): void
144 {
145 }
146 public function error(string $a_message): void
147 {
148 }
149 public function debug(string $a_message, array $a_context = []): void
150 {
151 }
152 public function dump($a_variable, int $a_level = ilLogLevel::INFO): void
153 {
154 }
155 };
156 $GLOBALS["DIC"]["ilLoggerFactory"] = new class () extends ilLoggerFactory {
157 public function __construct()
158 {
159 }
160 public static function getRootLogger(): ilLogger
161 {
162 return $GLOBALS["DIC"]["ilLog"];
163 }
164 public static function getLogger(string $a_component_id): ilLogger
165 {
166 return $GLOBALS["DIC"]["ilLog"];
167 }
168 };
169 $GLOBALS["DIC"]["ilBench"] = null;
170 $GLOBALS["DIC"]["lng"] = new ilLanguage('en');
171 $GLOBALS["DIC"]["ilPluginAdmin"] = $plugin_admin;
172 $GLOBALS["DIC"]["ilias"] = null;
173 $GLOBALS["ilLog"] = $GLOBALS["DIC"]["ilLog"];
174 $GLOBALS["DIC"]["ilErr"] = null;
175 $GLOBALS["DIC"]["tree"] = new class () extends ilTree {
176 public function __construct()
177 {
178 }
179 };
180 $GLOBALS["DIC"]["ilAppEventHandler"] = null;
181 $GLOBALS["DIC"]["ilSetting"] = new ilSetting();
182 $GLOBALS["DIC"]["ilUser"] = new class () extends ilObjUser {
183 public array $prefs = [];
184
185 public function __construct()
186 {
187 $this->prefs["language"] = "en";
188 }
189 };
190
191 if (!defined('DEBUG')) {
192 define('DEBUG', false);
193 }
194
195 if (!defined('SYSTEM_ROLE_ID')) {
196 define('SYSTEM_ROLE_ID', '2');
197 }
198
199 if (!defined("ILIAS_ABSOLUTE_PATH")) {
200 define("ILIAS_ABSOLUTE_PATH", dirname(__FILE__, 5));
201 }
202
203 if (!defined("CLIENT_ID")) {
204 define('CLIENT_ID', $client_ini->readVariable('client', 'name'));
205 }
206
207 if (!defined("ILIAS_WEB_DIR")) {
208 define('ILIAS_WEB_DIR', dirname(__DIR__, 4) . "/data/");
209 }
210
211 // initialise this last to make sure the environment defined here
212 // will be available for plugins, ilObjectDefinition will create
213 // plugin instances, see https://mantis.ilias.de/view.php?id=40890
214 $GLOBALS["DIC"]["objDefinition"] = new ilObjectDefinition();
215
216 return $DIC;
217 }
218}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
error(string $a_errmsg)
initEnvironment(Setup\Environment $environment, \ilComponentRepository $component_repository, \ilComponentFactory $component_factory)
isApplicable(Setup\Environment $environment)
@inheritDoc
language handling
Component logger with individual log levels by component id.
User class.
parses the objects.xml it handles the xml-description of all ilias objects
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
Readable part of repository interface to ilComponentDataDB.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Container.php:19
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ini
Definition: raiseError.php:4