ILIAS  release_8 Revision v8.24
ilDatabaseUpdateStepsExecutedObjective Class Reference

This class attempt to achieve a set of database update steps. More...

+ Inheritance diagram for ilDatabaseUpdateStepsExecutedObjective:
+ Collaboration diagram for ilDatabaseUpdateStepsExecutedObjective:

Public Member Functions

 __construct (ilDatabaseUpdateSteps $steps)
 
 getHash ()
 The hash for the objective is calculated over the classname and the steps that are contained. More...
 
 getLabel ()
 Get a label that describes this objective. More...
 
 isNotable ()
 @inheritdocs More...
 
 getPreconditions (Environment $environment)
 @inheritdocs More...
 
 achieve (Environment $environment)
 @inheritdocs More...
 
 isApplicable (Environment $environment)
 @inheritDoc More...
 
 getHash ()
 Get a hash for this objective. More...
 
 getLabel ()
 Get a label that describes this objective. More...
 
 isNotable ()
 Get to know if this is an interesting objective for a human. More...
 
 getPreconditions (Environment $environment)
 Objectives might depend on other objectives. More...
 
 achieve (Environment $environment)
 Objectives can be achieved. More...
 
 isApplicable (Environment $environment)
 Get to know whether the objective is applicable. More...
 

Data Fields

const STEP_METHOD_PREFIX = "step_"
 

Protected Member Functions

 throwStepNotFinishedException (int $started, int $finished)
 

Protected Attributes

ilDatabaseUpdateSteps $steps
 
string $steps_class
 

Detailed Description

This class attempt to achieve a set of database update steps.

Look into the interface ilDatabaseUpdateSteps for further instructions.

Definition at line 26 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

Constructor & Destructor Documentation

◆ __construct()

ilDatabaseUpdateStepsExecutedObjective::__construct ( ilDatabaseUpdateSteps  $steps)

Reimplemented in ilDataCollectionObjective.

Definition at line 33 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

34 {
35 $this->steps = $steps;
36 $this->steps_class = get_class($this->steps);
37 }

References $steps.

Member Function Documentation

◆ achieve()

ilDatabaseUpdateStepsExecutedObjective::achieve ( Environment  $environment)

@inheritdocs

Implements ILIAS\Setup\Objective.

Reimplemented in ilDataCollectionObjective.

Definition at line 79 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

80 {
81 $execution_log = $environment->getResource(ilDBStepExecutionDB::class);
82 $step_reader = $environment->getResource(ilDBStepReader::class);
83
84 $last_started_step = $execution_log->getLastStartedStep($this->steps_class);
85 $last_finished_step = $execution_log->getLastFinishedStep($this->steps_class);
86 if ($last_started_step !== $last_finished_step) {
87 $this->throwStepNotFinishedException($last_started_step, $last_finished_step);
88 throw new LogicException(
89 "ilDatabaseUpdateStepExecutionLog::throwStepNotFinishedException should throw an exception."
90 );
91 }
92
93 if ($last_finished_step === $step_reader->getLatestStepNumber($this->steps_class, self::STEP_METHOD_PREFIX)) {
94 return $environment;
95 }
96
97 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
98 $this->steps->prepare($db);
99
100 $steps = $step_reader->readStepNumbers($this->steps_class, self::STEP_METHOD_PREFIX);
101 foreach ($steps as $step) {
102 if ($step <= $last_finished_step) {
103 continue;
104 }
105 $execution_log->started($this->steps_class, $step);
106 $method = self::STEP_METHOD_PREFIX . $step;
107 $this->steps->$method();
108 $execution_log->finished($this->steps_class, $step);
109 }
110
111 return $environment;
112 }
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.

References $steps, ILIAS\Setup\Environment\getResource(), and throwStepNotFinishedException().

+ Here is the call graph for this function:

◆ getHash()

ilDatabaseUpdateStepsExecutedObjective::getHash ( )
final

The hash for the objective is calculated over the classname and the steps that are contained.

Implements ILIAS\Setup\Objective.

Definition at line 43 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

43 : string
44 {
45 return hash(
46 "sha256",
47 self::class . $this->steps_class
48 );
49 }

◆ getLabel()

ilDatabaseUpdateStepsExecutedObjective::getLabel ( )
final

Get a label that describes this objective.

Implements ILIAS\Setup\Objective.

Definition at line 51 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

51 : string
52 {
53 return "Database update steps in $this->steps_class.";
54 }

◆ getPreconditions()

◆ isApplicable()

ilDatabaseUpdateStepsExecutedObjective::isApplicable ( Environment  $environment)

@inheritDoc

Implements ILIAS\Setup\Objective.

Definition at line 117 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

117 : bool
118 {
119 $execution_log = $environment->getResource(ilDBStepExecutionDB::class);
120 $step_reader = $environment->getResource(ilDBStepReader::class);
121
122 return $execution_log->getLastFinishedStep($this->steps_class) !== $step_reader->getLatestStepNumber(
123 $this->steps_class,
124 self::STEP_METHOD_PREFIX
125 );
126 }

References ILIAS\Setup\Environment\getResource().

+ Here is the call graph for this function:

◆ isNotable()

ilDatabaseUpdateStepsExecutedObjective::isNotable ( )
final

@inheritdocs

Implements ILIAS\Setup\Objective.

Definition at line 59 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

59 : bool
60 {
61 return true;
62 }

◆ throwStepNotFinishedException()

ilDatabaseUpdateStepsExecutedObjective::throwStepNotFinishedException ( int  $started,
int  $finished 
)
protected

Definition at line 128 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

128 : void
129 {
130 throw new RuntimeException(
131 "For update steps in $this->steps_class: step $started was started " .
132 "last, but step $finished was finished last. Aborting because of that " .
133 "mismatch."
134 );
135 }

Referenced by achieve().

+ Here is the caller graph for this function:

Field Documentation

◆ $steps

ilDatabaseUpdateSteps ilDatabaseUpdateStepsExecutedObjective::$steps
protected

Definition at line 30 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

Referenced by __construct(), and achieve().

◆ $steps_class

string ilDatabaseUpdateStepsExecutedObjective::$steps_class
protected

◆ STEP_METHOD_PREFIX

const ilDatabaseUpdateStepsExecutedObjective::STEP_METHOD_PREFIX = "step_"

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