ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
cli.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
6 chdir(__DIR__ . "/..");
7 
8 require_once(__DIR__ . "/../libs/composer/vendor/autoload.php");
9 
10 require_once(__DIR__ . "/../include/inc.ilias_version.php");
11 
12 // according to ./Services/Feeds/classes/class.ilExternalFeed.php:
13 if (!defined("MAGPIE_DIR")) {
14  define("MAGPIE_DIR", "./Services/Feeds/magpierss/");
15 }
16 
17 require_once(__DIR__ . "/classes/class.ilSetupObjective.php");
18 require_once(__DIR__ . "/classes/class.ilSetupAgent.php");
19 require_once(__DIR__ . "/classes/class.ilSetupConfig.php");
20 require_once(__DIR__ . "/classes/class.ilMakeInstallationAccessibleObjective.php");
21 require_once(__DIR__ . "/classes/class.ilUseRootConfirmed.php");
22 require_once(__DIR__ . "/classes/class.ilOwnRiskConfirmedObjective.php");
23 require_once(__DIR__ . "/classes/class.ilOverwritesExistingInstallationConfirmed.php");
24 require_once(__DIR__ . "/classes/class.ilIniFilesPopulatedObjective.php");
25 require_once(__DIR__ . "/classes/class.ilIniFilesLoadedObjective.php");
26 require_once(__DIR__ . "/classes/class.ilNICKeyRegisteredObjective.php");
27 require_once(__DIR__ . "/classes/class.ilNICKeyStoredObjective.php");
28 require_once(__DIR__ . "/classes/class.ilSetupConfigStoredObjective.php");
29 require_once(__DIR__ . "/classes/class.ilSetupPasswordManager.php");
30 require_once(__DIR__ . "/classes/class.ilSetupPasswordEncoderFactory.php");
31 
32 use ILIAS\UI\Component\Input\Field\Factory as FieldFactory;
36 
38 $app = $c["app"];
39 $app->run();
40 
41 function get_agent_name_by_class(string $class_name) : string
42 {
43  // We assume that the name of an agent in the class ilXYZSetupAgent really
44  // is XYZ. If that does not fit we just use the class name.
45  $match = [];
46  if (preg_match("/il(\w+)SetupAgent/", $class_name, $match)) {
47  return $match[1];
48  }
49  return $class_name;
50 }
51 
52 // ATTENTION: This is a hack to get around the usage of the echo/exit pattern in
53 // the setup for the command line version of the setup. Do not use this.
55 {
56  if (!defined("ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES") || !ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES) {
57  throw new \ILIAS\Setup\UnachievableException($message);
58  }
59 }
60 
62 {
63  $c = new \Pimple\Container;
64 
65  $c["app"] = function ($c) {
66  return new \ILIAS\Setup\CLI\App(
67  $c["command.install"],
68  $c["command.update"],
69  $c["command.build-artifacts"],
70  $c["command.reload-control-structure"]
71  );
72  };
73  $c["command.install"] = function ($c) {
74  return new \ILIAS\Setup\CLI\InstallCommand(
75  $c["agent"],
76  $c["config_reader"],
77  $c["common_preconditions"]
78  );
79  };
80  $c["command.update"] = function ($c) {
81  return new \ILIAS\Setup\CLI\UpdateCommand(
82  $c["agent"],
83  $c["config_reader"],
84  $c["common_preconditions"]
85  );
86  };
87  $c["command.build-artifacts"] = function ($c) {
88  return new \ILIAS\Setup\CLI\BuildArtifactsCommand(
89  $c["agent"],
90  $c["config_reader"],
91  []// TODO: $c["common_preconditions"]
92  );
93  };
94  $c["command.reload-control-structure"] = function ($c) {
95  return new \ILIAS\Setup\CLI\ReloadControlStructureCommand(
96  $c["agent"],
97  $c["config_reader"],
98  $c["common_preconditions"]
99  );
100  };
101 
102  $c["common_preconditions"] = function ($c) {
103  return [
104  new \ilOwnRiskConfirmedObjective(),
105  new \ilUseRootConfirmed()
106  ];
107  };
108 
109  $c["agent"] = function ($c) {
110  return function () use ($c) {
111  return new ILIAS\Setup\AgentCollection(
112  $c["ui.field_factory"],
113  $c["refinery"],
114  $c["agents"]
115  );
116  };
117  };
118 
119  $c["agent_finder"] = function ($c) {
121  ILIAS\Setup\Agent::class
122  );
123  };
124 
125  $c["common_agent"] = function ($c) {
126  return new \ilSetupAgent(
127  $c["refinery"],
128  $c["data_factory"],
129  $c["password_manager"]
130  );
131  };
132 
133  $c["agents"] = function ($c) {
134  $agents["common"] = $c["common_agent"];
135  foreach ($c["agent_finder"]->getMatchingClassNames() as $cls) {
136  if (preg_match("/ILIAS\\\\Setup\\\\.*/", $cls)) {
137  continue;
138  }
140  if (isset($agents[$name])) {
141  throw new \RuntimeException(
142  "Encountered duplicate agent $name in $cls"
143  );
144  }
145  $agents[strtolower($name)] = new $cls(
146  $c["refinery"],
147  $c["data_factory"],
148  $c["lng"]
149  );
150  };
151  return $agents;
152  };
153 
154  $c["ui.field_factory"] = function ($c) {
155  return new class implements FieldFactory {
156  public function text($label, $byline = null)
157  {
158  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
159  }
160  public function numeric($label, $byline = null)
161  {
162  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
163  }
164  public function group(array $inputs, string $label = '')
165  {
166  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
167  }
168  public function section(array $inputs, $label, $byline = null)
169  {
170  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
171  }
172  public function dependantGroup(array $inputs)
173  {
174  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
175  }
176  public function optionalGroup(array $inputs, string $label, string $byline = null) : \ILIAS\UI\Component\Input\Field\OptionalGroup
177  {
178  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
179  }
180  public function switchableGroup(array $inputs, string $label, string $byline = null) : \ILIAS\UI\Component\Input\Field\SwitchableGroup
181  {
182  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
183  }
184  public function checkbox($label, $byline = null)
185  {
186  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
187  }
188  public function tag(string $label, array $tags, $byline = null) : Tag
189  {
190  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
191  }
192  public function password($label, $byline = null)
193  {
194  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
195  }
196  public function select($label, array $options, $byline = null)
197  {
198  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
199  }
200  public function textarea($label, $byline = null)
201  {
202  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
203  }
204  public function radio($label, $byline = null)
205  {
206  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
207  }
208  public function multiSelect($label, array $options, $byline = null)
209  {
210  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
211  }
212  public function dateTime($label, $byline = null)
213  {
214  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
215  }
216  public function duration($label, $byline = null)
217  {
218  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
219  }
220  public function file(UploadHandler $handler, string $label, string $byline = null) : File
221  {
222  throw new \LogicException("The CLI-setup does not support the UI-Framework.");
223  }
224  };
225  };
226 
227  $c["refinery"] = function ($c) {
228  return new ILIAS\Refinery\Factory(
229  $c["data_factory"],
230  $c["lng"]
231  );
232  };
233 
234  $c["data_factory"] = function ($c) {
235  return new ILIAS\Data\Factory();
236  };
237 
238  $c["lng"] = function ($c) {
239  return new \ilSetupLanguage("en");
240  };
241 
242  $c["config_reader"] = function ($c) use ($executed_in_directory) {
243  return new \ILIAS\Setup\CLI\ConfigReader(
244  $executed_in_directory
245  );
246  };
247 
248  $c["password_manager"] = function ($c) {
249  return new \ilSetupPasswordManager([
250  'password_encoder' => 'bcryptphp',
251  'encoder_factory' => new \ilSetupPasswordEncoderFactory([
252  'default_password_encoder' => 'bcryptphp'
253  ])
254  ]);
255  };
256 
257  return $c;
258 }
This is what a factory for input fields looks like.
Definition: Factory.php:10
$app
Definition: cli.php:38
$c
Definition: cli.php:37
Class ChatMainBarProvider .
This describes optional group inputs.
if($format !==null) $name
Definition: metadata.php:230
$executed_in_directory
Definition: cli.php:5
setup_exit($message)
Definition: cli.php:54
This describes switchable group inputs.
$message
Definition: xapiexit.php:14
get_agent_name_by_class(string $class_name)
Definition: cli.php:41
build_container_for_setup(string $executed_in_directory)
Definition: cli.php:61
This describes file field.
Definition: File.php:8