ILIAS  release_7 Revision v7.30-3-g800a261c036
InstallCommand.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
4namespace ILIAS\Setup\CLI;
5
13use Symfony\Component\Console\Command\Command;
14use Symfony\Component\Console\Input\InputInterface;
15use Symfony\Component\Console\Output\OutputInterface;
16use Symfony\Component\Console\Input\InputArgument;
17use Symfony\Component\Console\Input\InputOption;
18
22class InstallCommand extends Command
23{
24 use HasAgent;
26 use ObjectiveHelper;
27
28 protected static $defaultName = "install";
29
33 protected $preconditions;
34
38 public function __construct(AgentFinder $agent_finder, ConfigReader $config_reader, array $preconditions)
39 {
41 $this->agent_finder = $agent_finder;
42 $this->config_reader = $config_reader;
43 $this->preconditions = $preconditions;
44 }
45
46 public function configure()
47 {
48 $this->setDescription("Creates a fresh ILIAS installation based on the config");
49 $this->addArgument("config", InputArgument::OPTIONAL, "Configuration file for the installation");
50 $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\"", []);
51 $this->addOption("yes", "y", InputOption::VALUE_NONE, "Confirm every message of the installation.");
53 }
54
55 public function execute(InputInterface $input, OutputInterface $output)
56 {
57 // ATTENTION: This is a hack to get around the usage of the echo/exit pattern in
58 // the setup for the command line version of the setup. Do not use this.
59 if(!defined('ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES')) {
60 define("ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES", true);
61 }
62
63 if ($input->hasOption('plugin') && $input->getOption('plugin') != "") {
64 list($objective, $environment, $io) = $this->preparePluginInstallation($input, $output);
65 } else {
66 list($objective, $environment, $io) = $this->prepareILIASInstallation($input, $output);
67 }
68
69 try {
70 $this->achieveObjective($objective, $environment, $io);
71 $io->success("Installation complete. Thanks and have fun!");
72 } catch (NoConfirmationException $e) {
73 $io->error("Aborting Installation, a necessary confirmation is missing:\n\n" . $e->getRequestedConfirmation());
74 }
75
76 }
77
78 protected function prepareILIASInstallation(InputInterface $input, OutputInterface $output) : array
79 {
80 $io = new IOWrapper($input, $output);
81 $io->printLicenseMessage();
82 $io->title("Install ILIAS");
83
84 $agent = $this->getRelevantAgent($input);
85
86 $config = $this->readAgentConfig($agent, $input);
87
88 $objective = new ObjectiveCollection(
89 "Install and Update ILIAS",
90 false,
91 $agent->getInstallObjective($config),
92 $agent->getUpdateObjective($config)
93 );
94 if (count($this->preconditions) > 0) {
95 $objective = new ObjectiveWithPreconditions(
96 $objective,
97 ...$this->preconditions
98 );
99 }
100
101 $environment = new ArrayEnvironment([
103 ]);
104 $environment = $this->addAgentConfigsToEnvironment($agent, $config, $environment);
105 // ATTENTION: This is bad because we strongly couple this generic command
106 // to something very specific here. This can go away once we have got rid of
107 // everything related to clients, since we do not need that client-id then.
108 // This will require some more work, though.
109 $common_config = $config->getConfig("common");
110 $environment = $environment->withResource(
112 $common_config->getClientId()
113 );
114
115 return [$objective, $environment, $io];
116 }
117
118 protected function preparePluginInstallation(InputInterface $input, OutputInterface $output) : array
119 {
120 $io = new IOWrapper($input, $output);
121 $io->printLicenseMessage();
122 $io->title("Install ILIAS Plugin");
123
124 $agent = $this->getRelevantAgent($input);
125
126 $config = $this->readAgentConfig($agent, $input);
127
128 $objective = new ObjectiveCollection(
129 "Install and Update ILIAS Plugin",
130 false,
131 $agent->getInstallObjective($config),
132 $agent->getUpdateObjective($config)
133 );
134 if (count($this->preconditions) > 0) {
135 $objective = new ObjectiveWithPreconditions(
136 $objective,
137 ...$this->preconditions
138 );
139 }
140
141 $environment = new ArrayEnvironment([
143 ]);
144
145 if (!is_null($config)) {
146 $environment = $this->addAgentConfigsToEnvironment($agent, $config, $environment);
147 }
148
149 return [$objective, $environment, $io];
150 }
151}
An exception for terminatinating execution or to throw for unit testing.
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:17
__construct(AgentFinder $agent_finder, ConfigReader $config_reader, array $preconditions)
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:12
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
__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:15
getRelevantAgent(InputInterface $input)
Definition: HasAgent.php:28
readAgentConfig(Agent $agent, InputInterface $input)
trait HasConfigReader
Add this to an Command that has an config reader.
configureCommandForPlugins()
Definition: HasAgent.php:21