ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilDatabaseUpdateSteps Class Reference

This base-class simplifies the creation of (consecutive) database updates. More...

+ Inheritance diagram for ilDatabaseUpdateSteps:
+ Collaboration diagram for ilDatabaseUpdateSteps:

Public Member Functions

 __construct (Objective $base)
 
 getAdditionalPreconditionsForStep (int $num)
 Get preconditions for steps. More...
 
 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)
 
 getStep (int $num, int $finished=0)
 Get a database update step. More...
 
 getLatestStepNum ()
 Get the number of latest database step in this class. More...
 

Data Fields

const STEP_METHOD_PREFIX = "step_"
 

Protected Member Functions

 getSteps ()
 Get the numbers of the steps in this class. More...
 

Protected Attributes

 $steps = null
 
 $base
 

Detailed Description

This base-class simplifies the creation of (consecutive) database updates.

Implement update steps on one or more tables by creating methods that follow this schema:

public function step_1( $db) { ... }

The class will figure out which of them haven't been performed yet and need to be executed.

If the class takes care of only one table or a set of related tables it will be easier to maintain.

If for some reason you rely on other objectives, e.g. steps from other db-update classes, implement getAdditionalPreconditionsForStep.

Definition at line 25 of file class.ilDatabaseUpdateSteps.php.

Constructor & Destructor Documentation

◆ __construct()

ilDatabaseUpdateSteps::__construct ( Objective  $base)
Parameters
Objective$basefor the update steps, i.e. the objective that should have been reached before the steps of this class can even begin. Most probably this should be .

Definition at line 45 of file class.ilDatabaseUpdateSteps.php.

References $base, and base().

47  {
48  $this->base = $base;
49  }
base()
Definition: base.php:4
+ Here is the call graph for this function:

Member Function Documentation

◆ achieve()

ilDatabaseUpdateSteps::achieve ( Environment  $environment)
final

Implements ILIAS\Setup\Objective.

Definition at line 108 of file class.ilDatabaseUpdateSteps.php.

108  : Environment
109  {
110  return $environment;
111  }
An environment holds resources to be used in the setup process.
Definition: Environment.php:11

◆ getAdditionalPreconditionsForStep()

ilDatabaseUpdateSteps::getAdditionalPreconditionsForStep ( int  $num)

Get preconditions for steps.

The previous step will automatically be a precondition of every step but will not be returned from this method.

Returns
Objective[]

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

Referenced by getStep().

59  : array
60  {
61  return [];
62  }
+ Here is the caller graph for this function:

◆ getHash()

ilDatabaseUpdateSteps::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 68 of file class.ilDatabaseUpdateSteps.php.

68  : string
69  {
70  return hash(
71  "sha256",
72  get_class($this)
73  );
74  }

◆ getLabel()

ilDatabaseUpdateSteps::getLabel ( )
final

Get a label that describes this objective.

Implements ILIAS\Setup\Objective.

Definition at line 76 of file class.ilDatabaseUpdateSteps.php.

76  : string
77  {
78  return "Database update steps in " . get_class($this);
79  }

◆ getLatestStepNum()

ilDatabaseUpdateSteps::getLatestStepNum ( )
final

Get the number of latest database step in this class.

Definition at line 146 of file class.ilDatabaseUpdateSteps.php.

References getSteps().

Referenced by getPreconditions().

146  : int
147  {
148  $this->getSteps();
149  return end($this->steps);
150  }
getSteps()
Get the numbers of the steps in this class.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPreconditions()

ilDatabaseUpdateSteps::getPreconditions ( Environment  $environment)
final

Implements ILIAS\Setup\Objective.

Definition at line 92 of file class.ilDatabaseUpdateSteps.php.

References $log, getLatestStepNum(), ILIAS\Setup\Environment\getResource(), and getStep().

92  : array
93  {
94  $log = $environment->getResource(\ilDatabaseUpdateStepExecutionLog::class);
95 
96  if ($log) {
97  $finished = $log->getLastFinishedStep(get_class($this));
98  } else {
99  $finished = 0;
100  }
101 
102  return [$this->getStep($this->getLatestStepNum(), $finished)];
103  }
$log
Definition: result.php:15
getLatestStepNum()
Get the number of latest database step in this class.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
getStep(int $num, int $finished=0)
Get a database update step.
+ Here is the call graph for this function:

◆ getStep()

ilDatabaseUpdateSteps::getStep ( int  $num,
int  $finished = 0 
)
final

Get a database update step.

Optionally tell which step is known to have been finished to exclude it from the preconditions of the newer steps.

Exceptions

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

References $base, getAdditionalPreconditionsForStep(), and getSteps().

Referenced by getPreconditions().

128  {
129  $cur = $this->base;
130  foreach ($this->getSteps() as $s) {
131  if ($s <= $finished) {
132  continue;
133  } elseif ($s <= $num) {
134  $cur = new ilDatabaseUpdateStep($this, $s, $cur, ...$this->getAdditionalPreconditionsForStep($s));
135  } else {
136  break;
137  }
138  }
139 
140  return $cur;
141  }
getAdditionalPreconditionsForStep(int $num)
Get preconditions for steps.
getSteps()
Get the numbers of the steps in this class.
This encapsulate one database update step which is a method on some ilDatabaseUpdateSteps-object.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSteps()

ilDatabaseUpdateSteps::getSteps ( )
finalprotected

Get the numbers of the steps in this class.

Returns
int[]

Definition at line 157 of file class.ilDatabaseUpdateSteps.php.

References $steps.

Referenced by Test_ilDatabaseUpdateSteps\_getSteps(), getLatestStepNum(), and getStep().

157  : array
158  {
159  if (!is_null($this->steps)) {
160  return $this->steps;
161  }
162 
163  $this->steps = [];
164 
165  foreach (get_class_methods(static::class) as $method) {
166  if (stripos($method, self::STEP_METHOD_PREFIX) !== 0) {
167  continue;
168  }
169 
170  $number = substr($method, strlen(self::STEP_METHOD_PREFIX));
171 
172  if (!preg_match("/^[1-9]\d*$/", $number)) {
173  throw new \LogicException("Method $method seems to be a step but has an odd looking number");
174  }
175 
176  $this->steps[(int) $number] = (int) $number;
177  }
178 
179  asort($this->steps);
180 
181  return $this->steps;
182  }
+ Here is the caller graph for this function:

◆ isApplicable()

ilDatabaseUpdateSteps::isApplicable ( Environment  $environment)
final

Implements ILIAS\Setup\Objective.

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

116  : bool
117  {
118  return true;
119  }

◆ isNotable()

ilDatabaseUpdateSteps::isNotable ( )
final

Implements ILIAS\Setup\Objective.

Definition at line 84 of file class.ilDatabaseUpdateSteps.php.

84  : bool
85  {
86  return true;
87  }

Field Documentation

◆ $base

ilDatabaseUpdateSteps::$base
protected

Definition at line 37 of file class.ilDatabaseUpdateSteps.php.

Referenced by __construct(), and getStep().

◆ $steps

ilDatabaseUpdateSteps::$steps = null
protected

◆ STEP_METHOD_PREFIX

const ilDatabaseUpdateSteps::STEP_METHOD_PREFIX = "step_"

Definition at line 27 of file class.ilDatabaseUpdateSteps.php.

Referenced by ilDatabaseUpdateStep\__construct().


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