ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilComponentActivatePluginsObjective.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2020 Daniel Weise <daniel.weise@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
4declare(strict_types=1);
5
7use ILIAS\DI;
8
10{
14 protected $plugin_name;
15
16 public function __construct(string $plugin_name)
17 {
18 $this->plugin_name = $plugin_name;
19 }
20
24 public function getHash() : string
25 {
26 return hash("sha256", self::class . $this->plugin_name);
27 }
28
32 public function getLabel() : string
33 {
34 return "Activate plugin $this->plugin_name.";
35 }
36
40 public function isNotable() : bool
41 {
42 return true;
43 }
44
48 public function getPreconditions(Setup\Environment $environment) : array
49 {
50 return [
51 new \ilComponentUpdatePluginObjective($this->plugin_name)
52 ];
53 }
54
58 public function achieve(Setup\Environment $environment) : Setup\Environment
59 {
60 $ORIG_DIC = $this->initEnvironment($environment);
61
62 $plugin = $GLOBALS["DIC"]["ilPluginAdmin"]->getRawPluginDataFor($this->plugin_name);
63
64 if (!is_null($plugin) && $plugin['activation_possible'] && $plugin['supports_cli_setup']) {
66 $plugin['component_type'],
67 $plugin['component_name'],
68 $plugin['slot_id'],
69 $plugin['name']
70 );
71
72 $pl->activate();
73 }
74
75 $GLOBALS["DIC"] = $ORIG_DIC;
76
77 return $environment;
78 }
79
83 public function isApplicable(Setup\Environment $environment) : bool
84 {
85 $ORIG_DIC = $this->initEnvironment($environment);
86
87 $plugin = $GLOBALS["DIC"]["ilPluginAdmin"]->getRawPluginDataFor($this->plugin_name);
88
89 if (is_null($plugin) || !$plugin['supports_cli_setup']) {
90 return false;
91 }
92
93 $GLOBALS["DIC"] = $ORIG_DIC;
94
95 return $plugin['activation_possible'];
96 }
97
98 protected function initEnvironment(Setup\Environment $environment) : ?ILIAS\DI\Container
99 {
100 $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
101 $plugin_admin = $environment->getResource(Setup\Environment::RESOURCE_PLUGIN_ADMIN);
102 $ini = $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI);
103 $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
104
105
106 // ATTENTION: This is a total abomination. It only exists to allow various
107 // sub components of the various readers to run. This is a memento to the
108 // fact, that dependency injection is something we want. Currently, every
109 // component could just service locate the whole world via the global $DIC.
110 $DIC = $GLOBALS["DIC"];
111 $GLOBALS["DIC"] = new DI\Container();
112 $GLOBALS["DIC"]["ilDB"] = $db;
113 $GLOBALS["DIC"]["ilIliasIniFile"] = $ini;
114 $GLOBALS["DIC"]["ilClientIniFile"] = $client_ini;
115 $GLOBALS["DIC"]["ilLog"] = new class() extends ilLogger {
116 public function __construct()
117 {
118 }
119 public function write($m, $l = ilLogLevel::INFO)
120 {
121 }
122 public function info($msg)
123 {
124 }
125 public function warning($msg)
126 {
127 }
128 public function error($msg)
129 {
130 }
131 public function debug($msg, $a = [])
132 {
133 }
134 public function dump($msg, $a = ilLogLevel::INFO)
135 {
136 }
137 };
138 $GLOBALS["DIC"]["ilLoggerFactory"] = new class() extends ilLoggerFactory {
139 public function __construct()
140 {
141 }
142 public static function getRootLogger()
143 {
144 return $GLOBALS["DIC"]["ilLog"];
145 }
146 public static function getLogger($a)
147 {
148 return $GLOBALS["DIC"]["ilLog"];
149 }
150 };
151 $GLOBALS["DIC"]["ilBench"] = null;
152 $GLOBALS["DIC"]["lng"] = new ilLanguage('en');
153 $GLOBALS["DIC"]["ilPluginAdmin"] = $plugin_admin;
154 $GLOBALS["DIC"]["ilCtrl"] = new ilCtrl();
155 $GLOBALS["DIC"]["ilias"] = null;
156 $GLOBALS["ilLog"] = $GLOBALS["DIC"]["ilLog"];
157 $GLOBALS["DIC"]["ilErr"] = null;
158 $GLOBALS["DIC"]["tree"] = new class() extends ilTree {
159 public function __construct()
160 {
161 }
162 };
163 $GLOBALS["DIC"]["ilAppEventHandler"] = null;
164 $GLOBALS["DIC"]["ilSetting"] = new ilSetting();
165 $GLOBALS["DIC"]["objDefinition"] = new ilObjectDefinition();
166 $GLOBALS["DIC"]["ilUser"] = new class() extends ilObjUser {
167 public $prefs = [];
168
169 public function __construct()
170 {
171 $this->prefs["language"] = "en";
172 }
173 };
174
175 if (!defined('DEBUG')) {
176 define('DEBUG', false);
177 }
178
179 if (!defined('SYSTEM_ROLE_ID')) {
180 define('SYSTEM_ROLE_ID', '2');
181 }
182
183 if (!defined("CLIENT_ID")) {
184 define('CLIENT_ID', $client_ini->readVariable('client', 'name'));
185 }
186
187 if (!defined("ILIAS_WEB_DIR")) {
188 define('ILIAS_WEB_DIR', dirname(__DIR__, 4) . "/data/");
189 }
190
191 return $DIC;
192 }
193}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:19
error($a_errmsg)
set error message @access public
isApplicable(Setup\Environment $environment)
@inheritDoc
This class provides processing control methods.
language handling
Component logger with individual log levels by component id.
parses the objects.xml it handles the xml-description of all ilias objects
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
ILIAS Setting Class.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
global $DIC
Definition: goto.php:24
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:15
Class HTTPServicesTest.
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...
Class ChatMainBarProvider \MainMenu\Provider.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$ini
Definition: raiseError.php:4
info()
Definition: info.php:2