ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UpdateCommand.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Setup\CLI;
22
30use Symfony\Component\Console\Input\InputInterface;
31use Symfony\Component\Console\Output\OutputInterface;
32use Symfony\Component\Console\Input\InputArgument;
33use Symfony\Component\Console\Input\InputOption;
34
39{
40 use HasAgent;
42 use ObjectiveHelper;
43
44 protected static $defaultName = "update";
45
49 protected array $preconditions;
50
54 public function __construct(AgentFinder $agent_finder, ConfigReader $config_reader, array $preconditions)
55 {
57 $this->agent_finder = $agent_finder;
58 $this->config_reader = $config_reader;
59 $this->preconditions = $preconditions;
60 }
61
62 protected function configure(): void
63 {
64 $this->setDescription("Updates an existing ILIAS installation");
65 $this->addArgument("config", InputArgument::OPTIONAL, "Configuration file for the update");
66 $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\"", []);
67 $this->addOption("ignore-db-update-messages", null, InputOption::VALUE_NONE, "Ignore messages from the database update steps.");
68 $this->addOption("yes", "y", InputOption::VALUE_NONE, "Confirm every message of the update.");
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 ($input->hasOption("ignore-db-update-messages") && $input->getOption("ignore-db-update-messages")) {
77 define("ILIAS_SETUP_IGNORE_DB_UPDATE_STEP_MESSAGES", true);
78 }
79
80 $io = new IOWrapper($input, $output);
81 $io->printLicenseMessage();
82 $io->title("Update ILIAS");
83
84 $agent = $this->getRelevantAgent($input);
85
86 if ($input->getArgument("config")) {
87 $config = $this->readAgentConfig($agent, $input);
88 } else {
89 $config = null;
90 }
91
92 $objective = $agent->getUpdateObjective($config);
93 if ($this->preconditions !== []) {
94 $objective = new ObjectiveWithPreconditions(
95 $objective,
96 ...$this->preconditions
97 );
98 }
99
100 $environment = new ArrayEnvironment([
102 ]);
103 if ($config !== null) {
104 $environment = $this->addAgentConfigsToEnvironment($agent, $config, $environment);
105 }
106
107 try {
108 $this->achieveObjective($objective, $environment, $io);
109 $io->success("Update complete. Thanks and have fun!");
110 } catch (NoConfirmationException $e) {
111 $io->error("Aborting Update, a necessary confirmation is missing:\n\n" . $e->getRequestedConfirmation());
112 }
113
114 return 0;
115 }
116}
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
execute(InputInterface $input, OutputInterface $output)
array $preconditions
var Objective[]
__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:28
__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
readAgentConfig(Agent $agent, InputInterface $input, ?string $use_config_field=null)
trait HasConfigReader
Add this to an Command that has an config reader.
configureCommandForPlugins()
Definition: HasAgent.php:33