ILIAS  release_7 Revision v7.30-3-g800a261c036
UpdateCommand.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3/* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5namespace ILIAS\Setup\CLI;
6
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 UpdateCommand extends Command
23{
24 use HasAgent;
26 use ObjectiveHelper;
27
28 protected static $defaultName = "update";
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("Updates an existing ILIAS installation");
49 $this->addArgument("config", InputArgument::OPTIONAL, "Configuration file for the update");
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("ignore-db-update-messages", null, InputOption::VALUE_NONE, "Ignore messages from the database update steps.");
52 $this->addOption("yes", "y", InputOption::VALUE_NONE, "Confirm every message of the update.");
54 }
55
56 public function execute(InputInterface $input, OutputInterface $output)
57 {
58 // ATTENTION: This is a hack to get around the usage of the echo/exit pattern in
59 // the setup for the command line version of the setup. Do not use this.
60 if ($input->hasOption("ignore-db-update-messages") && $input->getOption("ignore-db-update-messages")) {
61 define("ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES", true);
62 }
63
64 $io = new IOWrapper($input, $output);
65 $io->printLicenseMessage();
66 $io->title("Update ILIAS");
67
68 $agent = $this->getRelevantAgent($input);
69
70 if ($input->getArgument("config")) {
71 $config = $this->readAgentConfig($agent, $input);
72 } else {
73 $config = null;
74 }
75
76 $objective = $agent->getUpdateObjective($config);
77 if (count($this->preconditions) > 0) {
78 $objective = new ObjectiveWithPreconditions(
79 $objective,
80 ...$this->preconditions
81 );
82 }
83
84 $environment = new ArrayEnvironment([
86 ]);
87 if ($config) {
88 $environment = $this->addAgentConfigsToEnvironment($agent, $config, $environment);
89 }
90
91 try {
92 $this->achieveObjective($objective, $environment, $io);
93 $io->success("Update complete. Thanks and have fun!");
94 } catch (NoConfirmationException $e) {
95 $io->error("Aborting Update, a necessary confirmation is missing:\n\n" . $e->getRequestedConfirmation());
96 }
97 }
98}
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
execute(InputInterface $input, OutputInterface $output)
__construct(AgentFinder $agent_finder, ConfigReader $config_reader, array $preconditions)
Signals that a necessary confirmation from the admin is missing.
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