ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 ()
 
 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

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

Constructor & Destructor Documentation

◆ __construct()

ilDatabaseUpdateStepsExecutedObjective::__construct ( ilDatabaseUpdateSteps  $steps)

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

References $steps.

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

Member Function Documentation

◆ achieve()

ilDatabaseUpdateStepsExecutedObjective::achieve ( Environment  $environment)

Implements ILIAS\Setup\Objective.

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

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

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

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

◆ getLabel()

ilDatabaseUpdateStepsExecutedObjective::getLabel ( )
final

Get a label that describes this objective.

Implements ILIAS\Setup\Objective.

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

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

◆ getPreconditions()

◆ isApplicable()

ilDatabaseUpdateStepsExecutedObjective::isApplicable ( Environment  $environment)

Implements ILIAS\Setup\Objective.

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

References ILIAS\Setup\Environment\getResource().

119  : bool
120  {
121  $execution_log = $environment->getResource(ilDatabaseUpdateStepExecutionLog::class);
122  $step_reader = $environment->getResource(ilDBStepReader::class);
123 
124  return $execution_log->getLastFinishedStep($this->steps_class) !== $step_reader->getLatestStepNumber(
125  $this->steps_class,
126  self::STEP_METHOD_PREFIX
127  );
128  }
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 60 of file class.ilDatabaseUpdateStepsExecutedObjective.php.

60  : bool
61  {
62  return true;
63  }

◆ throwStepNotFinishedException()

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

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

Referenced by achieve().

130  : void
131  {
132  throw new RuntimeException(
133  "For update steps in $this->steps_class: step $started was started " .
134  "last, but step $finished was finished last. Aborting because of that " .
135  "mismatch."
136  );
137  }
+ Here is the caller graph for this function:

Field Documentation

◆ $steps

ilDatabaseUpdateSteps ilDatabaseUpdateStepsExecutedObjective::$steps
protected

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

Referenced by __construct().

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