ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilDBStepExecutionDB Class Reference

This logs the execution of database update steps. More...

+ Inheritance diagram for ilDBStepExecutionDB:
+ Collaboration diagram for ilDBStepExecutionDB:

Public Member Functions

 __construct (protected ilDBInterface $db, callable $get_now)
 
 started (string $class, int $step)
 
 finished (string $class, int $step)
 
 getLastStartedStep (string $class)
 Returns 0 as "first" step. More...
 
 getLastFinishedStep (string $class)
 Returns 0 as "first" step. More...
 

Data Fields

const TABLE_NAME = "il_db_steps"
 
const FIELD_CLASS = "class"
 
const FIELD_STEP = "step"
 
const FIELD_STARTED = "started"
 
const FIELD_FINISHED = "finished"
 

Protected Member Functions

 throwIfClassNameTooLong (string $class)
 
 getFormattedNow ()
 

Protected Attributes

 $get_now
 

Detailed Description

This logs the execution of database update steps.

Author
: Richard Klees

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

Constructor & Destructor Documentation

◆ __construct()

ilDBStepExecutionDB::__construct ( protected ilDBInterface  $db,
callable  $get_now 
)
Parameters
callable$get_nowmust return a DateTime object indicating the very moment the callable was called.

Definition at line 40 of file class.ilDBStepExecutionDB.php.

References $get_now.

41  {
42  $this->get_now = $get_now;
43  }

Member Function Documentation

◆ finished()

ilDBStepExecutionDB::finished ( string  $class,
int  $step 
)
Exceptions

Implements ilDatabaseUpdateStepExecutionLog.

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

References getFormattedNow(), getLastStartedStep(), and throwIfClassNameTooLong().

Referenced by ilDBStepExecutionDBTest\testFinishedThrowsWhenOtherStepThenLastIsFinished(), and ilDBStepExecutionDBTest\testFinishedWritesToDB().

81  : void
82  {
83  $this->throwIfClassNameTooLong($class);
84 
85  $last_started_step = $this->getLastStartedStep($class);
86  if ($last_started_step !== $step) {
87  throw new \RuntimeException(
88  "The step $step for $class is supposed to be finished, but" .
89  " $last_started_step was $step started last."
90  );
91  }
92 
93  $this->db->update(
94  self::TABLE_NAME,
95  [
96  self::FIELD_FINISHED => ["text", $this->getFormattedNow()]
97  ],
98  [
99  self::FIELD_CLASS => ["text", $class],
100  self::FIELD_STEP => ["integer", $step]
101  ]
102  );
103  }
getLastStartedStep(string $class)
Returns 0 as "first" step.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFormattedNow()

ilDBStepExecutionDB::getFormattedNow ( )
protected

Definition at line 143 of file class.ilDBStepExecutionDB.php.

References $get_now.

Referenced by finished(), and started().

143  : string
144  {
145  $now = ($this->get_now)();
146  if (!($now instanceof \DateTime)) {
147  throw new \LogicException(
148  "Expected \$get_now to return a DateTime."
149  );
150  }
151  return $now->format("Y-m-d H:i:s.u");
152  }
+ Here is the caller graph for this function:

◆ getLastFinishedStep()

ilDBStepExecutionDB::getLastFinishedStep ( string  $class)

Returns 0 as "first" step.

Implements ilDatabaseUpdateStepExecutionLog.

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

References $res, and throwIfClassNameTooLong().

Referenced by started().

119  : int
120  {
121  $this->throwIfClassNameTooLong($class);
122 
123  $res = $this->db->query(
124  "SELECT MAX(" . self::FIELD_STEP . ") AS " . self::FIELD_STEP .
125  " FROM " . self::TABLE_NAME .
126  " WHERE " . self::FIELD_CLASS . " = " . $this->db->quote($class, "text") .
127  " AND " . self::FIELD_FINISHED . " IS NOT NULL"
128  );
129 
130  $row = $this->db->fetchAssoc($res);
131  return (int) ($row[self::FIELD_STEP] ?? 0);
132  }
$res
Definition: ltiservices.php:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastStartedStep()

ilDBStepExecutionDB::getLastStartedStep ( string  $class)

Returns 0 as "first" step.

Implements ilDatabaseUpdateStepExecutionLog.

Definition at line 105 of file class.ilDBStepExecutionDB.php.

References $res, and throwIfClassNameTooLong().

Referenced by finished(), and started().

105  : int
106  {
107  $this->throwIfClassNameTooLong($class);
108 
109  $res = $this->db->query(
110  "SELECT MAX(" . self::FIELD_STEP . ") AS " . self::FIELD_STEP .
111  " FROM " . self::TABLE_NAME .
112  " WHERE " . self::FIELD_CLASS . " = " . $this->db->quote($class, "text")
113  );
114 
115  $row = $this->db->fetchAssoc($res);
116  return (int) ($row[self::FIELD_STEP] ?? 0);
117  }
$res
Definition: ltiservices.php:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ started()

ilDBStepExecutionDB::started ( string  $class,
int  $step 
)
Exceptions

Implements ilDatabaseUpdateStepExecutionLog.

Definition at line 48 of file class.ilDBStepExecutionDB.php.

References getFormattedNow(), getLastFinishedStep(), getLastStartedStep(), and throwIfClassNameTooLong().

Referenced by ilDBStepExecutionDBTest\testStartedThrowsOnStartStepNotLargerThenLastFinishedStep(), ilDBStepExecutionDBTest\testStartedThrowsWhenLastStepNotFinished(), and ilDBStepExecutionDBTest\testStartedWritesToDB().

48  : void
49  {
50  $this->throwIfClassNameTooLong($class);
51 
52  $last_started_step = $this->getLastStartedStep($class);
53  if ($last_started_step >= $step) {
54  throw new \RuntimeException(
55  "The last started step for $class was $last_started_step, which" .
56  " is higher then the step $step started now."
57  );
58  }
59 
60  $last_finished_step = $this->getLastFinishedStep($class);
61  if ($last_started_step !== $last_finished_step) {
62  throw new \RuntimeException(
63  "Step $step should be started for $class, but last step $last_started_step " .
64  "has not finished by now."
65  );
66  }
67 
68  $this->db->insert(
69  self::TABLE_NAME,
70  [
71  self::FIELD_CLASS => ["text", $class],
72  self::FIELD_STEP => ["integer", $step],
73  self::FIELD_STARTED => ["text", $this->getFormattedNow()]
74  ]
75  );
76  }
getLastFinishedStep(string $class)
Returns 0 as "first" step.
getLastStartedStep(string $class)
Returns 0 as "first" step.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ throwIfClassNameTooLong()

ilDBStepExecutionDB::throwIfClassNameTooLong ( string  $class)
protected

Definition at line 134 of file class.ilDBStepExecutionDB.php.

Referenced by finished(), getLastFinishedStep(), getLastStartedStep(), and started().

134  : void
135  {
136  if (strlen($class) > 200) {
137  throw new \InvalidArgumentException(
138  "This ilDatabaseUpdateStepExecutionLog only supports class names up to 200 chars."
139  );
140  }
141  }
+ Here is the caller graph for this function:

Field Documentation

◆ $get_now

ilDBStepExecutionDB::$get_now
protected

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

Referenced by __construct(), and getFormattedNow().

◆ FIELD_CLASS

◆ FIELD_FINISHED

const ilDBStepExecutionDB::FIELD_FINISHED = "finished"

◆ FIELD_STARTED

const ilDBStepExecutionDB::FIELD_STARTED = "started"

◆ FIELD_STEP

◆ TABLE_NAME


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