ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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)
 
 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 27 of file class.ilDatabaseUpdateSteps.php.

Constructor & Destructor Documentation

◆ __construct()

ilDatabaseUpdateSteps::__construct ( Objective  $base)
Parameters
\ilObjective$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 47 of file class.ilDatabaseUpdateSteps.php.

References $base, and base().

49  {
50  $this->base = $base;
51  }
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 110 of file class.ilDatabaseUpdateSteps.php.

110  : Environment
111  {
112  return $environment;
113  }
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 61 of file class.ilDatabaseUpdateSteps.php.

Referenced by getStep().

61  : array
62  {
63  return [];
64  }
+ 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 70 of file class.ilDatabaseUpdateSteps.php.

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

◆ getLabel()

ilDatabaseUpdateSteps::getLabel ( )
final

Get a label that describes this objective.

Implements ILIAS\Setup\Objective.

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

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

◆ getLatestStepNum()

ilDatabaseUpdateSteps::getLatestStepNum ( )
final

Get the number of latest database step in this class.

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

References getSteps().

Referenced by getPreconditions().

140  : int
141  {
142  $this->getSteps();
143  return end($this->steps);
144  }
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 94 of file class.ilDatabaseUpdateSteps.php.

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

94  : array
95  {
96  $log = $environment->getResource(\ilDatabaseUpdateStepExecutionLog::class);
97 
98  if ($log) {
99  $finished = $log->getLastFinishedStep(get_class($this));
100  } else {
101  $finished = 0;
102  }
103 
104  return [$this->getStep($this->getLatestStepNum(), $finished)];
105  }
$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 121 of file class.ilDatabaseUpdateSteps.php.

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

Referenced by getPreconditions().

122  {
123  $cur = $this->base;
124  foreach ($this->getSteps() as $s) {
125  if ($s <= $finished) {
126  continue;
127  } elseif ($s <= $num) {
128  $cur = new ilDatabaseUpdateStep($this, $s, $cur, ...$this->getAdditionalPreconditionsForStep($s));
129  } else {
130  break;
131  }
132  }
133 
134  return $cur;
135  }
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 151 of file class.ilDatabaseUpdateSteps.php.

References $steps.

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

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

◆ isNotable()

ilDatabaseUpdateSteps::isNotable ( )
final

Implements ILIAS\Setup\Objective.

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

86  : bool
87  {
88  return true;
89  }

Field Documentation

◆ $base

ilDatabaseUpdateSteps::$base
protected

Definition at line 39 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 29 of file class.ilDatabaseUpdateSteps.php.

Referenced by ilDatabaseUpdateStep\__construct().


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