ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDatabaseUpdateStepsExecutedObjective.php
Go to the documentation of this file.
1<?php
2
22
28{
29 public const STEP_METHOD_PREFIX = "step_";
30 protected string $steps_class;
31
32 public function __construct(protected ilDatabaseUpdateSteps $steps)
33 {
34 $this->steps_class = $this->steps::class;
35 }
36
41 final public function getHash(): string
42 {
43 return hash(
44 "sha256",
45 self::class . $this->steps_class
46 );
47 }
48
49 final public function getLabel(): string
50 {
51 return "Database update steps in $this->steps_class.";
52 }
53
57 final public function isNotable(): bool
58 {
59 return true;
60 }
61
65 public function getPreconditions(Environment $environment): array
66 {
67 return [
72 ];
73 }
74
78 public function achieve(Environment $environment): Environment
79 {
80 $execution_log = $environment->getResource(ilDatabaseUpdateStepExecutionLog::class);
81 $step_reader = $environment->getResource(ilDBStepReader::class);
82
83 $last_started_step = $execution_log->getLastStartedStep($this->steps_class);
84 $last_finished_step = $execution_log->getLastFinishedStep($this->steps_class);
85 if ($last_started_step !== $last_finished_step) {
86 $this->throwStepNotFinishedException($last_started_step, $last_finished_step);
87 throw new LogicException(
88 "ilDatabaseUpdateStepExecutionLog::throwStepNotFinishedException should throw an exception."
89 );
90 }
91
92 if ($last_finished_step === $step_reader->getLatestStepNumber($this->steps_class, self::STEP_METHOD_PREFIX)) {
93 return $environment;
94 }
95
96 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
97 $this->steps->prepare($db);
98
99 $steps = $step_reader->readStepNumbers($this->steps_class, self::STEP_METHOD_PREFIX);
100 foreach ($steps as $step) {
101 if ($step <= $last_finished_step) {
102 continue;
103 }
104 $execution_log->started($this->steps_class, $step);
105 $method = self::STEP_METHOD_PREFIX . $step;
106 $this->steps->$method();
107 $execution_log->finished($this->steps_class, $step);
108 }
109
110 return $environment;
111 }
112
116 public function isApplicable(Environment $environment): bool
117 {
118 $execution_log = $environment->getResource(ilDatabaseUpdateStepExecutionLog::class);
119 $step_reader = $environment->getResource(ilDBStepReader::class);
120
121 return $execution_log->getLastFinishedStep($this->steps_class) !== $step_reader->getLatestStepNumber(
122 $this->steps_class,
123 self::STEP_METHOD_PREFIX
124 );
125 }
126
127 protected function throwStepNotFinishedException(int $started, int $finished): void
128 {
129 throw new RuntimeException(
130 "For update steps in $this->steps_class: step $started was started " .
131 "last, but step $finished was finished last. Aborting because of that " .
132 "mismatch."
133 );
134 }
135}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
This class attempt to achieve a set of database update steps.
getHash()
The hash for the objective is calculated over the classname and the steps that are contained.
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...