ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ILIAS\Setup\CLI\AchieveCommand Class Reference

Achieves an objective. More...

+ Inheritance diagram for ILIAS\Setup\CLI\AchieveCommand:
+ Collaboration diagram for ILIAS\Setup\CLI\AchieveCommand:

Public Member Functions

 __construct (AgentFinder $agent_finder, ConfigReader $config_reader, array $preconditions, Refinery $refinery)
 

Protected Member Functions

 configure ()
 
 execute (InputInterface $input, OutputInterface $output)
 

Protected Attributes

array $preconditions = []
 
Refinery $refinery
 

Static Protected Attributes

static $defaultName = "achieve"
 

Private Member Functions

 shouldListNamedObjectives (InputInterface $input)
 
 executeListNamedObjectives (IOWrapper $io, OutputInterface $output)
 
 executeAchieveObjective (IOWrapper $io, InputInterface $input)
 

Detailed Description

Achieves an objective.

Definition at line 41 of file AchieveCommand.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Setup\CLI\AchieveCommand::__construct ( AgentFinder  $agent_finder,
ConfigReader  $config_reader,
array  $preconditions,
Refinery  $refinery 
)

Definition at line 56 of file AchieveCommand.php.

References ILIAS\Setup\CLI\AchieveCommand\$preconditions, ILIAS\Setup\CLI\AchieveCommand\$refinery, ILIAS\GlobalScreen\Provider\__construct(), and ILIAS\Repository\refinery().

61  {
63  $this->agent_finder = $agent_finder;
64  $this->config_reader = $config_reader;
65  $this->preconditions = $preconditions;
66  $this->refinery = $refinery;
67  }
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ configure()

ILIAS\Setup\CLI\AchieveCommand::configure ( )
protected

Definition at line 69 of file AchieveCommand.php.

69  : void
70  {
71  $this->setDescription("Achieve a named objective from an agent.");
72  $this->addArgument(
73  "objective",
74  InputArgument::OPTIONAL,
75  "Objective to be execute from an agent. Format: \$AGENT::\$OBJECTIVE"
76  );
77  $this->addArgument("config", InputArgument::OPTIONAL, "Configuration file for the installation");
78  $this->addOption(
79  "config",
80  null,
81  InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
82  "Define fields in the configuration file that should be overwritten, e.g. \"a.b.c=foo\"",
83  []
84  );
85  $this->addOption("yes", "y", InputOption::VALUE_NONE, "Confirm every message of the objective.");
86  $this->addOption("list", null, InputOption::VALUE_NONE, "Lists all achievable objectives");
87  }

◆ execute()

ILIAS\Setup\CLI\AchieveCommand::execute ( InputInterface  $input,
OutputInterface  $output 
)
protected

Definition at line 89 of file AchieveCommand.php.

References ILIAS\Setup\CLI\AchieveCommand\executeAchieveObjective(), ILIAS\Setup\CLI\AchieveCommand\executeListNamedObjectives(), and ILIAS\Setup\CLI\AchieveCommand\shouldListNamedObjectives().

89  : int
90  {
91  $io = new IOWrapper($input, $output);
92  $io->printLicenseMessage();
93 
94  if ($this->shouldListNamedObjectives($input)) {
95  $this->executeListNamedObjectives($io, $output);
96  return 0;
97  }
98 
99  $this->executeAchieveObjective($io, $input);
100 
101  return 0;
102  }
executeListNamedObjectives(IOWrapper $io, OutputInterface $output)
executeAchieveObjective(IOWrapper $io, InputInterface $input)
shouldListNamedObjectives(InputInterface $input)
+ Here is the call graph for this function:

◆ executeAchieveObjective()

ILIAS\Setup\CLI\AchieveCommand::executeAchieveObjective ( IOWrapper  $io,
InputInterface  $input 
)
private

Definition at line 131 of file AchieveCommand.php.

References $config, Vendor\Package\$e, ILIAS\Setup\CLI\addAgentConfigsToEnvironment(), ILIAS\Setup\CLI\IOWrapper\error(), ILIAS\Setup\CLI\getRelevantAgent(), ILIAS\Setup\NoConfirmationException\getRequestedConfirmation(), ILIAS\Setup\CLI\readAgentConfig(), ILIAS\Setup\Environment\RESOURCE_ADMIN_INTERACTION, ILIAS\Setup\CLI\IOWrapper\success(), and ILIAS\Setup\CLI\IOWrapper\title().

Referenced by ILIAS\Setup\CLI\AchieveCommand\execute().

131  : void
132  {
133  $agent = $this->getRelevantAgent($input);
134  $objective_name = $input->getArgument('objective');
135 
136  $io->title("Achieve objective: $objective_name");
137 
138  $config = null;
139 
140  if ($input->getArgument("config")) {
141  $config = $this->readAgentConfig($agent, $input);
142  }
143 
144  $namedObjectives = $agent->getNamedObjectives($config);
145 
146  if (isset($namedObjectives[$objective_name])) {
147  $objective = $namedObjectives[$objective_name];
148  } else {
149  throw new InvalidArgumentException(
150  "There is no named objective '$objective_name'"
151  );
152  }
153 
154  if ($this->preconditions !== []) {
155  $objective = new ObjectiveWithPreconditions(
156  $objective->create(),
157  ...$this->preconditions
158  );
159  } else {
160  $objective = $objective->create();
161  }
162 
163  $environment = new ArrayEnvironment([
165  ]);
166  if ($config !== null) {
167  $environment = $this->addAgentConfigsToEnvironment($agent, $config, $environment);
168  }
169 
170  try {
171  $this->achieveObjective($objective, $environment, $io);
172  $io->success("Achieved objective '$objective_name'. Thanks and have fun!");
173  } catch (NoConfirmationException $e) {
174  $io->error("Aborted the attempt to achieve '$objective_name', a necessary confirmation is missing:\n\n" . $e->getRequestedConfirmation());
175  }
176  }
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
addAgentConfigsToEnvironment(Agent $agent, Config $config, Environment $environment)
getRelevantAgent(InputInterface $input)
Definition: HasAgent.php:40
readAgentConfig(Agent $agent, InputInterface $input, string $use_config_field=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeListNamedObjectives()

ILIAS\Setup\CLI\AchieveCommand::executeListNamedObjectives ( IOWrapper  $io,
OutputInterface  $output 
)
private

Definition at line 119 of file AchieveCommand.php.

References ILIAS\Setup\CLI\IOWrapper\LABEL_WIDTH, and ILIAS\Setup\CLI\IOWrapper\title().

Referenced by ILIAS\Setup\CLI\AchieveCommand\execute().

119  : void
120  {
121  $io->title("Listing available objectives");
122 
123  $agentCollection = $this->agent_finder->getAgents();
124  foreach ($agentCollection->getNamedObjectives(null) as $cmd => $objectiveCollection) {
125  $output->write(str_pad($cmd, IOWrapper::LABEL_WIDTH));
126  $output->writeln($objectiveCollection->getDescription());
127  }
128  $output->writeln("");
129  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shouldListNamedObjectives()

ILIAS\Setup\CLI\AchieveCommand::shouldListNamedObjectives ( InputInterface  $input)
private

Definition at line 104 of file AchieveCommand.php.

Referenced by ILIAS\Setup\CLI\AchieveCommand\execute().

104  : bool
105  {
106  return
107  (
108  $input->getOption("list") !== null
109  && is_bool($input->getOption("list"))
110  && $input->getOption("list")
111  )
112  ||
113  (
114  $input->getArgument("objective") === ""
115  || $input->getArgument("objective") === null
116  );
117  }
+ Here is the caller graph for this function:

Field Documentation

◆ $defaultName

ILIAS\Setup\CLI\AchieveCommand::$defaultName = "achieve"
staticprotected

Definition at line 47 of file AchieveCommand.php.

◆ $preconditions

array ILIAS\Setup\CLI\AchieveCommand::$preconditions = []
protected

Definition at line 49 of file AchieveCommand.php.

Referenced by ILIAS\Setup\CLI\AchieveCommand\__construct().

◆ $refinery

Refinery ILIAS\Setup\CLI\AchieveCommand::$refinery
protected

Definition at line 51 of file AchieveCommand.php.

Referenced by ILIAS\Setup\CLI\AchieveCommand\__construct().


The documentation for this class was generated from the following file: