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
6use ILIAS\Setup\Agent;
7use ILIAS\Setup\AgentCollection;
8use ILIAS\Setup\ArrayEnvironment;
9use ILIAS\Setup\Config;
10use ILIAS\Setup\Environment;
11use ILIAS\Setup\Objective;
12use ILIAS\Setup\ObjectiveCollection;
13use ILIAS\Setup\AchievementTracker;
14use Symfony\Component\Console\Input\InputInterface;
15
16/**
17 * Reload Control Structure command.
18 */
19class ReloadControlStructureCommand extends BaseCommand
20{
21    protected static $defaultName = "reload-control-structure";
22
23    public function configure()
24    {
25        parent::configure();
26        $this->setDescription("Reloads the control structure of the installation.");
27    }
28
29    protected function printIntroMessage(IOWrapper $io)
30    {
31        $io->title("Reloading control structure of ILIAS");
32    }
33
34    protected function printOutroMessage(IOWrapper $io)
35    {
36        $io->success("Control structure reloaded. Thanks and have fun!");
37    }
38
39    protected function buildEnvironment(Agent $agent, ?Config $config, IOWrapper $io) : Environment
40    {
41        $environment = new ArrayEnvironment([
42            Environment::RESOURCE_ADMIN_INTERACTION => $io,
43            // TODO: This needs to be implemented correctly...
44            Environment::RESOURCE_ACHIEVEMENT_TRACKER => new class implements AchievementTracker {
45                public function trackAchievementOf(Objective $objective) : void
46                {
47                }
48                public function isAchieved(Objective $objective) : bool
49                {
50                    return false;
51                }
52            }
53        ]);
54
55        if ($agent instanceof AgentCollection && $config) {
56            foreach ($config->getKeys() as $k) {
57                $environment = $environment->withConfigFor($k, $config->getConfig($k));
58            }
59        }
60
61        return $environment;
62    }
63
64    protected function getObjective(Agent $agent, ?Config $config) : Objective
65    {
66        // ATTENTION: This is not how we want to do this in general during the
67        // setup, stuff should use Dependency Injection. However, since we
68        // currently won't get there with the control structure but still need
69        // a quick way to reload it, we do it anyway.
70        return new ObjectiveCollection(
71            "Install and update ILIAS",
72            false,
73            new \ilCtrlStructureStoredObjective(
74                new \ilCtrlStructureReader()
75            ),
76            new \ilComponentDefinitionsStoredObjective(false)
77        );
78    }
79}
80