ILIAS  release_8 Revision v8.24
class.ilComponentUpdatePluginObjective.php
Go to the documentation of this file.
1<?php
2
20declare(strict_types=1);
21
22use ILIAS\Setup;
23use ILIAS\DI;
25
27{
31 protected $plugin_name;
32
33 public function __construct(string $plugin_name)
34 {
35 $this->plugin_name = $plugin_name;
36 }
37
41 public function getHash(): string
42 {
43 return hash("sha256", self::class . $this->plugin_name);
44 }
45
49 public function getLabel(): string
50 {
51 return "Update plugin $this->plugin_name.";
52 }
53
57 public function isNotable(): bool
58 {
59 return true;
60 }
61
65 public function getPreconditions(Setup\Environment $environment): array
66 {
67 return [
69 new \ilIniFilesLoadedObjective(),
70 new \ilDatabaseInitializedObjective(),
71 new \ilComponentPluginAdminInitObjective(),
72 new \ilComponentRepositoryExistsObjective(),
73 new \ilComponentFactoryExistsObjective()
74 ];
75 }
76
80 public function achieve(Setup\Environment $environment): Setup\Environment
81 {
82 $component_repository = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_REPOSITORY);
83 $component_factory = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_FACTORY);
84 $info = $component_repository->getPluginByName($this->plugin_name);
85
86 if (!$info->supportsCLISetup()) {
87 throw new \RuntimeException(
88 "Plugin $this->plugin_name does not support command line setup."
89 );
90 }
91
92 if (!$info->isUpdateRequired()) {
93 throw new \RuntimeException(
94 "Plugin $this->plugin_name is already updated."
95 );
96 }
97
98 [$ORIG_DIC, $ORIG_ilDB] = $this->initEnvironment($environment, $component_repository, $component_factory);
99 $plugin = $component_factory->getPlugin($info->getId());
100 $plugin->update();
101 $GLOBALS["DIC"] = $ORIG_DIC;
102 $GLOBALS["ilDB"] = $ORIG_ilDB;
103
104 return $environment;
105 }
106
110 public function isApplicable(Setup\Environment $environment): bool
111 {
112 $component_repository = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_REPOSITORY);
113 $plugin = $component_repository->getPluginByName($this->plugin_name);
114
115 return $plugin->isUpdateRequired();
116 }
117
118 protected function initEnvironment(
119 Setup\Environment $environment,
120 \ilComponentRepository $component_repository,
121 \ilComponentFactory $component_factory
122 ): array {
123 $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
124 $plugin_admin = $environment->getResource(Setup\Environment::RESOURCE_PLUGIN_ADMIN);
125 $ini = $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI);
126 $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
127
128 // ATTENTION: This is a total abomination. It only exists to allow various
129 // sub components of the various readers to run. This is a memento to the
130 // fact, that dependency injection is something we want. Currently, every
131 // component could just service locate the whole world via the global $DIC.
132 $ORIG_DIC = $GLOBALS["DIC"];
133 $ORIG_ilDB = $GLOBALS["ilDB"];
134
135 $GLOBALS["DIC"] = new DI\Container();
136 $GLOBALS["DIC"]["component.repository"] = $component_repository;
137 $GLOBALS["DIC"]["component.factory"] = $component_factory;
138 $GLOBALS["DIC"]["ilDB"] = $db;
139 $GLOBALS["ilDB"] = $db;
140 $GLOBALS["DIC"]["ilIliasIniFile"] = $ini;
141 $GLOBALS["DIC"]["ilClientIniFile"] = $client_ini;
142 $GLOBALS["DIC"]["ilLogger"] = new class () extends ilLogger {
143 public function __construct()
144 {
145 }
146 public function isHandling(int $a_level): bool
147 {
148 return true;
149 }
150 public function log(string $a_message, int $a_level = ilLogLevel::INFO): void
151 {
152 }
153 public function dump($a_variable, int $a_level = ilLogLevel::INFO): void
154 {
155 }
156 public function debug(string $a_message, array $a_context = array()): void
157 {
158 }
159 public function info(string $a_message): void
160 {
161 }
162 public function notice(string $a_message): void
163 {
164 }
165 public function warning(string $a_message): void
166 {
167 }
168 public function error(string $a_message): void
169 {
170 }
171 public function critical(string $a_message): void
172 {
173 }
174 public function alert(string $a_message): void
175 {
176 }
177 public function emergency(string $a_message): void
178 {
179 }
180 public function write(string $a_message, $a_level = ilLogLevel::INFO): void
181 {
182 }
183 public function writeLanguageLog(string $a_topic, string $a_lang_key): void
184 {
185 }
186 public function logStack(?int $a_level = null, string $a_message = ''): void
187 {
188 }
189 public function writeMemoryPeakUsage(int $a_level): void
190 {
191 }
192 };
193 $GLOBALS["DIC"]["ilLog"] = new class () extends ilLogger {
194 public function __construct()
195 {
196 }
197 public function write(string $a_msg, $a_log_level = ilLogLevel::INFO): void
198 {
199 }
200 public function info($msg): void
201 {
202 }
203 public function warning($msg): void
204 {
205 }
206 public function error($msg): void
207 {
208 }
209 public function debug($msg, $a = []): void
210 {
211 }
212 public function dump($a_var, ?int $a_log_level = ilLogLevel::INFO): void
213 {
214 }
215 };
216 $GLOBALS["DIC"]["ilLoggerFactory"] = new class () extends ilLoggerFactory {
217 public function __construct()
218 {
219 }
220 public static function getRootLogger(): ilLogger
221 {
222 return $GLOBALS["DIC"]["ilLog"];
223 }
224 public static function getLogger(string $a_component_id): ilLogger
225 {
226 return $GLOBALS["DIC"]["ilLog"];
227 }
228 };
229 $GLOBALS["ilLog"] = $GLOBALS["DIC"]["ilLog"];
230 $GLOBALS["DIC"]["ilBench"] = null;
231 $GLOBALS["DIC"]["lng"] = new ilLanguage('en');
232 $GLOBALS["DIC"]["ilPluginAdmin"] = $plugin_admin;
233 $GLOBALS["DIC"]["ilias"] = null;
234 $GLOBALS["DIC"]["ilErr"] = null;
235 $GLOBALS["DIC"]["tree"] = new class () extends ilTree {
236 public function __construct()
237 {
238 }
239 };
240 $GLOBALS["DIC"]["ilAppEventHandler"] = new class () extends ilAppEventHandler {
241 public function __construct()
242 {
243 }
244 public function raise($a_component, $a_event, $a_parameter = ""): void
245 {
246 }
247 };
248 $GLOBALS["DIC"]["ilObjDataCache"] = new ilObjectDataCache();
249 $GLOBALS["DIC"]["ilSetting"] = new ilSetting();
250 $GLOBALS["DIC"]["rbacadmin"] = new class () extends ilRbacAdmin {
251 public function __construct()
252 {
253 }
254 };
255 $GLOBALS["DIC"]["rbacreview"] = new class () extends ilRbacReview {
256 public function __construct()
257 {
258 }
259 };
260 $GLOBALS["DIC"]["ilUser"] = new class () extends ilObjUser {
261 public array $prefs = [];
262
263 public function __construct()
264 {
265 $this->prefs["language"] = "en";
266 }
267 };
268
269 if (!defined('DEBUG')) {
270 define('DEBUG', false);
271 }
272
273 if (!defined('SYSTEM_ROLE_ID')) {
274 define('SYSTEM_ROLE_ID', '2');
275 }
276
277 if (!defined("ILIAS_ABSOLUTE_PATH")) {
278 define("ILIAS_ABSOLUTE_PATH", dirname(__FILE__, 5));
279 }
280
281 if (!defined("CLIENT_ID")) {
282 define('CLIENT_ID', $client_ini->readVariable('client', 'name'));
283 }
284
285 if (!defined("ILIAS_WEB_DIR")) {
286 define('ILIAS_WEB_DIR', dirname(__DIR__, 4) . "/data/");
287 }
288
289 // initialise this last to make sure the environment defined here
290 // will be available for plugins, ilObjectDefinition will create
291 // plugin instances, see https://mantis.ilias.de/view.php?id=40890
292 $GLOBALS["DIC"]["objDefinition"] = new ilObjectDefinition();
293
294 return [$ORIG_DIC, $ORIG_ilDB];
295 }
296}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
Read the client id of the installation from the data directory.
error(string $a_errmsg)
Global event handler.
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
parses the objects.xml it handles the xml-description of all ilias objects
Class ilRbacAdmin Core functions for role based access control.
class ilRbacReview Contains Review functions of core Rbac.
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...
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...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$ini
Definition: raiseError.php:4