ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilComponentInstallPluginObjective.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;
9
11{
15 protected $plugin_name;
16
17 public function __construct(string $plugin_name)
18 {
19 $this->plugin_name = $plugin_name;
20 }
21
25 public function getHash() : string
26 {
27 return hash("sha256", self::class . $this->plugin_name);
28 }
29
33 public function getLabel() : string
34 {
35 return "Install plugin $this->plugin_name.";
36 }
37
41 public function isNotable() : bool
42 {
43 return true;
44 }
45
49 public function getPreconditions(Setup\Environment $environment) : array
50 {
51 return [
53 new \ilIniFilesPopulatedObjective(),
54 new \ilDatabaseUpdatedObjective(),
55 new \ilComponentPluginAdminInitObjective()
56 ];
57 }
58
62 public function achieve(Setup\Environment $environment) : Setup\Environment
63 {
64 $ORIG_DIC = $this->initEnvironment($environment);
65
66 $plugin = $GLOBALS["DIC"]["ilPluginAdmin"]->getRawPluginDataFor($this->plugin_name);
67
68 if (!is_null($plugin) && $plugin['must_install'] && $plugin['supports_cli_setup']) {
70 $plugin['component_type'],
71 $plugin['component_name'],
72 $plugin['slot_id'],
73 $plugin['name']
74 );
75
76 $pl->install();
77 }
78
79 $GLOBALS["DIC"] = $ORIG_DIC;
80
81 return $environment;
82 }
83
87 public function isApplicable(Setup\Environment $environment) : bool
88 {
89 $ORIG_DIC = $this->initEnvironment($environment);
90
91 $plugin = $GLOBALS["DIC"]["ilPluginAdmin"]->getRawPluginDataFor($this->plugin_name);
92
93 if (is_null($plugin) || !$plugin['supports_cli_setup']) {
94 return false;
95 }
96
97 $GLOBALS["DIC"] = $ORIG_DIC;
98
99 return $plugin['must_install'];
100 }
101
102 protected function initEnvironment(Setup\Environment $environment) : ILIAS\DI\Container
103 {
104 $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
105 $plugin_admin = $environment->getResource(Setup\Environment::RESOURCE_PLUGIN_ADMIN);
106 $ini = $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI);
107 $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
108
109
110 // ATTENTION: This is a total abomination. It only exists to allow various
111 // sub components of the various readers to run. This is a memento to the
112 // fact, that dependency injection is something we want. Currently, every
113 // component could just service locate the whole world via the global $DIC.
114 $DIC = $GLOBALS["DIC"];
115 $GLOBALS["DIC"] = new DI\Container();
116 $GLOBALS["DIC"]["ilDB"] = $db;
117 $GLOBALS["DIC"]["ilIliasIniFile"] = $ini;
118 $GLOBALS["DIC"]["ilClientIniFile"] = $client_ini;
119 $GLOBALS["DIC"]["ilLog"] = new class() extends ilLogger {
120 public function __construct()
121 {
122 }
123 public function write($m, $l = ilLogLevel::INFO)
124 {
125 }
126 public function info($msg)
127 {
128 }
129 public function warning($msg)
130 {
131 }
132 public function error($msg)
133 {
134 }
135 public function debug($msg, $a = [])
136 {
137 }
138 public function dump($msg, $a = ilLogLevel::INFO)
139 {
140 }
141 };
142 $GLOBALS["DIC"]["ilLoggerFactory"] = new class() extends ilLoggerFactory {
143 public function __construct()
144 {
145 }
146 public static function getRootLogger()
147 {
148 return $GLOBALS["DIC"]["ilLog"];
149 }
150 public static function getLogger($a)
151 {
152 return $GLOBALS["DIC"]["ilLog"];
153 }
154 };
155 $GLOBALS["ilLog"] = $GLOBALS["DIC"]["ilLog"];
156 $GLOBALS["DIC"]["ilBench"] = null;
157 $GLOBALS["DIC"]["lng"] = new ilLanguage('en');
158 $GLOBALS["DIC"]["ilPluginAdmin"] = $plugin_admin;
159 $GLOBALS["DIC"]["ilCtrl"] = new ilCtrl();
160 $GLOBALS["DIC"]["ilias"] = null;
161 $GLOBALS["DIC"]["ilErr"] = null;
162 $GLOBALS["DIC"]["tree"] = null;
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
Read the client id of the installation from the data directory.
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.
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