ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilComponentInstallPluginObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Setup;
22use 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 "Install 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 \ilIniFilesPopulatedObjective(),
70 new \ilDatabaseUpdatedObjective(),
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->isInstalled()) {
93 throw new \RuntimeException(
94 "Plugin $this->plugin_name is already installed."
95 );
96 }
97
98 $ORIG_DIC = $this->initEnvironment($environment, $component_repository, $component_factory);
99 $plugin = $component_factory->getPlugin($info->getId());
100 $plugin->install();
101 $plugin->update();
102 $GLOBALS["DIC"] = $ORIG_DIC;
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->isInstalled();
116 }
117
118 protected function initEnvironment(
119 Setup\Environment $environment,
120 \ilComponentRepository $component_repository,
121 \ilComponentFactory $component_factory
122 ) {
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 $DIC = $GLOBALS["DIC"];
133 $GLOBALS["DIC"] = new DI\Container();
134 $GLOBALS["DIC"]["ilDB"] = $db;
135 $GLOBALS["DIC"]["ilIliasIniFile"] = $ini;
136 $GLOBALS["DIC"]["ilClientIniFile"] = $client_ini;
137 $GLOBALS["DIC"]["ilLog"] = new NullLogger();
138 $GLOBALS["DIC"]["ilLoggerFactory"] = new class () extends ilLoggerFactory {
139 public function __construct()
140 {
141 }
142 public static function getRootLogger(): ilLogger
143 {
144 return $GLOBALS["DIC"]["ilLog"];
145 }
146 public static function getLogger(string $a_component_id): ilLogger
147 {
148 return $GLOBALS["DIC"]["ilLog"];
149 }
150 };
151 $GLOBALS["ilLog"] = $GLOBALS["DIC"]["ilLog"];
152 $GLOBALS["DIC"]["ilBench"] = null;
153 $GLOBALS["DIC"]["lng"] = new ilLanguage('en');
154 $GLOBALS["DIC"]["lng"]->lang_user = 'en';
155 $GLOBALS["DIC"]["ilPluginAdmin"] = $plugin_admin;
156 $GLOBALS["DIC"]["ilias"] = null;
157 $GLOBALS["DIC"]["ilErr"] = null;
158 $GLOBALS["DIC"]["tree"] = null;
159 $GLOBALS["DIC"]["ilAppEventHandler"] = null;
160 $GLOBALS["DIC"]["ilSetting"] = new ilSetting();
161 $GLOBALS["DIC"]["component.repository"] = $component_repository;
162 $GLOBALS["DIC"]["component.factory"] = $component_factory;
163 $GLOBALS["DIC"]["ilUser"] = new class () extends ilObjUser {
164 public array $prefs = [];
165
166 public function __construct()
167 {
168 $this->prefs["language"] = "en";
169 }
170 };
171 $GLOBALS["DIC"]["tree"] = new class () extends ilTree {
172 public function __construct()
173 {
174 }
175 };
176
177 if (!defined('DEBUG')) {
178 define('DEBUG', false);
179 }
180
181 if (!defined('SYSTEM_ROLE_ID')) {
182 define('SYSTEM_ROLE_ID', '2');
183 }
184
185 if (!defined("ILIAS_ABSOLUTE_PATH")) {
186 define("ILIAS_ABSOLUTE_PATH", dirname(__FILE__, 5));
187 }
188
189 if (!defined("CLIENT_ID")) {
190 define('CLIENT_ID', $client_ini->readVariable('client', 'name'));
191 }
192
193 if (!defined("ILIAS_WEB_DIR")) {
194 define('ILIAS_WEB_DIR', "public/data/");
195 }
196
197 // initialise this last to make sure the environment defined here
198 // will be available for plugins, ilObjectDefinition will create
199 // plugin instances, see https://mantis.ilias.de/view.php?id=40890
200 $GLOBALS["DIC"]["objDefinition"] = new ilObjectDefinition();
201
202 return $DIC;
203 }
204}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Read the client id of the installation from the data directory.
isApplicable(Setup\Environment $environment)
@inheritDoc
initEnvironment(Setup\Environment $environment, \ilComponentRepository $component_repository, \ilComponentFactory $component_factory)
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
ILIAS Setting Class.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$info
Definition: entry_point.php:21
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:20
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54