ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 (protected 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 ()
 
 getPreconditions (Environment $environment)
 
 achieve (Environment $environment)
 
 isApplicable (Environment $environment)
 

Data Fields

const STEP_METHOD_PREFIX = "step_"
 

Protected Member Functions

 throwStepNotFinishedException (int $started, int $finished)
 

Protected Attributes

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 27 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

Constructor & Destructor Documentation

◆ __construct()

ilDatabaseUpdateStepsExecutedObjective::__construct ( protected ilDatabaseUpdateSteps  $steps)

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

33  {
34  $this->steps_class = $this->steps::class;
35  }

Member Function Documentation

◆ achieve()

ilDatabaseUpdateStepsExecutedObjective::achieve ( Environment  $environment)

Implements ILIAS\Setup\Objective.

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

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

78  : 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  }
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
+ 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 41 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

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

◆ getLabel()

ilDatabaseUpdateStepsExecutedObjective::getLabel ( )
final

Get a label that describes this objective.

Implements ILIAS\Setup\Objective.

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

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

◆ getPreconditions()

◆ isApplicable()

ilDatabaseUpdateStepsExecutedObjective::isApplicable ( Environment  $environment)

Implements ILIAS\Setup\Objective.

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

References ILIAS\Setup\Environment\getResource().

116  : 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  }
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
+ Here is the call graph for this function:

◆ isNotable()

ilDatabaseUpdateStepsExecutedObjective::isNotable ( )
final

Implements ILIAS\Setup\Objective.

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

57  : bool
58  {
59  return true;
60  }

◆ throwStepNotFinishedException()

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

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

Referenced by achieve().

127  : 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  }
+ Here is the caller graph for this function:

Field Documentation

◆ $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: