ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilComponentActivatePluginsObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Setup;
22use 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 NullLogger();
134 $GLOBALS["DIC"]["ilLoggerFactory"] = new class () extends ilLoggerFactory {
135 public function __construct()
136 {
137 }
138 public static function getRootLogger(): ilLogger
139 {
140 return $GLOBALS["DIC"]["ilLog"];
141 }
142 public static function getLogger(string $a_component_id): ilLogger
143 {
144 return $GLOBALS["DIC"]["ilLog"];
145 }
146 };
147 $GLOBALS["DIC"]["ilBench"] = null;
148 $GLOBALS["DIC"]["lng"] = new ilLanguage('en');
149 $GLOBALS["DIC"]["ilPluginAdmin"] = $plugin_admin;
150 $GLOBALS["DIC"]["ilias"] = null;
151 $GLOBALS["ilLog"] = $GLOBALS["DIC"]["ilLog"];
152 $GLOBALS["DIC"]["ilErr"] = null;
153 $GLOBALS["DIC"]["tree"] = new class () extends ilTree {
154 public function __construct()
155 {
156 }
157 };
158 $GLOBALS["DIC"]["ilAppEventHandler"] = null;
159 $GLOBALS["DIC"]["ilSetting"] = new ilSetting();
160 $GLOBALS["DIC"]["ilUser"] = new class () extends ilObjUser {
161 public array $prefs = [];
162
163 public function __construct()
164 {
165 $this->prefs["language"] = "en";
166 }
167 };
168
169 if (!defined('SYSTEM_ROLE_ID')) {
170 define('SYSTEM_ROLE_ID', '2');
171 }
172
173 if (!defined("ILIAS_ABSOLUTE_PATH")) {
174 define("ILIAS_ABSOLUTE_PATH", dirname(__FILE__, 5));
175 }
176
177 if (!defined("CLIENT_ID")) {
178 define('CLIENT_ID', $client_ini->readVariable('client', 'name'));
179 }
180
181 if (!defined("ILIAS_WEB_DIR")) {
182 define('ILIAS_WEB_DIR', "public/data/");
183 }
184
185 // initialise this last to make sure the environment defined here
186 // will be available for plugins, ilObjectDefinition will create
187 // plugin instances, see https://mantis.ilias.de/view.php?id=40890
188 $GLOBALS["DIC"]["objDefinition"] = new ilObjectDefinition();
189
190 return $DIC;
191 }
192}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
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
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