ILIAS  release_8 Revision v8.24
InstallCommand.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21namespace ILIAS\Setup\CLI;
22
30use Symfony\Component\Console\Command\Command;
31use Symfony\Component\Console\Input\InputInterface;
32use Symfony\Component\Console\Output\OutputInterface;
33use Symfony\Component\Console\Input\InputArgument;
34use Symfony\Component\Console\Input\InputOption;
35
39class InstallCommand extends Command
40{
41 use HasAgent;
43 use ObjectiveHelper;
44
45 protected static $defaultName = "install";
46
50 protected array $preconditions = [];
51
55 public function __construct(AgentFinder $agent_finder, ConfigReader $config_reader, array $preconditions)
56 {
58 $this->agent_finder = $agent_finder;
59 $this->config_reader = $config_reader;
60 $this->preconditions = $preconditions;
61 }
62
63 protected function configure(): void
64 {
65 $this->setDescription("Creates a fresh ILIAS installation based on the config");
66 $this->addArgument("config", InputArgument::OPTIONAL, "Configuration file for the installation");
67 $this->addOption("config", null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, "Define fields in the configuration file that should be overwritten, e.g. \"a.b.c=foo\"", []);
68 $this->addOption("yes", "y", InputOption::VALUE_NONE, "Confirm every message of the installation.");
70 }
71
72 protected function execute(InputInterface $input, OutputInterface $output): int
73 {
74 // ATTENTION: This is a hack to get around the usage of the echo/exit pattern in
75 // the setup for the command line version of the setup. Do not use this.
76 if (!defined("ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES")) {
77 define("ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES", true);
78 }
79
80 if ($input->hasOption('plugin') && $input->getOption('plugin') != "") {
81 list($objective, $environment, $io) = $this->preparePluginInstallation($input, $output);
82 } else {
83 list($objective, $environment, $io) = $this->prepareILIASInstallation($input, $output);
84 }
85
86 try {
87 $this->achieveObjective($objective, $environment, $io);
88 $io->success("Installation complete. Thanks and have fun!");
89 } catch (NoConfirmationException $e) {
90 $io->error("Aborting Installation, a necessary confirmation is missing:\n\n" . $e->getRequestedConfirmation());
91 }
92
93 return 0;
94 }
95
96 protected function prepareILIASInstallation(InputInterface $input, OutputInterface $output): array
97 {
98 $io = new IOWrapper($input, $output);
99 $io->printLicenseMessage();
100 $io->title("Install ILIAS");
101
102 $agent = $this->getRelevantAgent($input);
103
104 $config = $this->readAgentConfig($agent, $input);
105
106 $objective = new ObjectiveCollection(
107 "Install and Update ILIAS",
108 false,
109 $agent->getInstallObjective($config),
110 $agent->getUpdateObjective($config)
111 );
112 if ($this->preconditions !== []) {
113 $objective = new ObjectiveWithPreconditions(
114 $objective,
115 ...$this->preconditions
116 );
117 }
118
119 $environment = new ArrayEnvironment([
121 ]);
122 $environment = $this->addAgentConfigsToEnvironment($agent, $config, $environment);
123 // ATTENTION: This is bad because we strongly couple this generic command
124 // to something very specific here. This can go away once we have got rid of
125 // everything related to clients, since we do not need that client-id then.
126 // This will require some more work, though.
127 $common_config = $config->getConfig("common");
128 $environment = $environment->withResource(
130 $common_config->getClientId()
131 );
132
133 return [$objective, $environment, $io];
134 }
135
136 protected function preparePluginInstallation(InputInterface $input, OutputInterface $output): array
137 {
138 $io = new IOWrapper($input, $output);
139 $io->printLicenseMessage();
140 $io->title("Install ILIAS Plugin");
141
142 $agent = $this->getRelevantAgent($input);
143
144 $config = $this->readAgentConfig($agent, $input, $input->getOption("plugin"));
145
146 $objective = new ObjectiveCollection(
147 "Install and Update ILIAS Plugin",
148 false,
149 $agent->getInstallObjective($config),
150 $agent->getUpdateObjective($config)
151 );
152 if ($this->preconditions !== []) {
153 $objective = new ObjectiveWithPreconditions(
154 $objective,
155 ...$this->preconditions
156 );
157 }
158
159 $environment = new ArrayEnvironment([
161 ]);
162
163 if (!is_null($config)) {
164 $environment = $this->addAgentConfigsToEnvironment($agent, $config, $environment);
165 }
166
167 return [$objective, $environment, $io];
168 }
169}
Read a json-formatted config from a file and overwrite some fields.
Wrapper around symfonies input and output facilities to provide just the functionality required for t...
Definition: IOWrapper.php:33
__construct(AgentFinder $agent_finder, ConfigReader $config_reader, array $preconditions)
array $preconditions
var Objective[]
execute(InputInterface $input, OutputInterface $output)
preparePluginInstallation(InputInterface $input, OutputInterface $output)
prepareILIASInstallation(InputInterface $input, OutputInterface $output)
Signals that a necessary confirmation from the admin is missing.
A objective collection is a objective that is achieved once all subobjectives are achieved.
A wrapper around an objective that adds some preconditions.
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addAgentConfigsToEnvironment(Agent $agent, Config $config, Environment $environment)
trait HasAgent
Add this to an Command that has an agent.
Definition: HasAgent.php:30
getRelevantAgent(InputInterface $input)
Definition: HasAgent.php:40
trait HasConfigReader
Add this to an Command that has an config reader.
configureCommandForPlugins()
Definition: HasAgent.php:33
readAgentConfig(Agent $agent, InputInterface $input, string $use_config_field=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...