ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilDBStepExecutionDB Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 __construct (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

ilDBInterface $db
 
 $get_now
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 ( ilDBInterface  $db,
callable  $get_now 
)
Parameters
callable$get_nowmust return a DateTime object indicating the very moment the callable was called.

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

References $db, and $get_now.

43  {
44  $this->db = $db;
45  $this->get_now = $get_now;
46  }

Member Function Documentation

◆ finished()

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

Implements ilDatabaseUpdateStepExecutionLog.

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

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

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

◆ getFormattedNow()

ilDBStepExecutionDB::getFormattedNow ( )
protected

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

References $get_now.

Referenced by finished(), and started().

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

◆ getLastFinishedStep()

ilDBStepExecutionDB::getLastFinishedStep ( string  $class)

Returns 0 as "first" step.

Implements ilDatabaseUpdateStepExecutionLog.

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

References $res, and throwIfClassNameTooLong().

Referenced by started().

122  : int
123  {
124  $this->throwIfClassNameTooLong($class);
125 
126  $res = $this->db->query(
127  "SELECT MAX(" . self::FIELD_STEP . ") AS " . self::FIELD_STEP .
128  " FROM " . self::TABLE_NAME .
129  " WHERE " . self::FIELD_CLASS . " = " . $this->db->quote($class, "text") .
130  " AND " . self::FIELD_FINISHED . " IS NOT NULL"
131  );
132 
133  $row = $this->db->fetchAssoc($res);
134  return (int) ($row[self::FIELD_STEP] ?? 0);
135  }
$res
Definition: ltiservices.php:69
+ 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 108 of file class.ilDBStepExecutionDB.php.

References $res, and throwIfClassNameTooLong().

Referenced by finished(), and started().

108  : int
109  {
110  $this->throwIfClassNameTooLong($class);
111 
112  $res = $this->db->query(
113  "SELECT MAX(" . self::FIELD_STEP . ") AS " . self::FIELD_STEP .
114  " FROM " . self::TABLE_NAME .
115  " WHERE " . self::FIELD_CLASS . " = " . $this->db->quote($class, "text")
116  );
117 
118  $row = $this->db->fetchAssoc($res);
119  return (int) ($row[self::FIELD_STEP] ?? 0);
120  }
$res
Definition: ltiservices.php:69
+ 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 51 of file class.ilDBStepExecutionDB.php.

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

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

◆ throwIfClassNameTooLong()

ilDBStepExecutionDB::throwIfClassNameTooLong ( string  $class)
protected

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

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

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

Field Documentation

◆ $db

ilDBInterface ilDBStepExecutionDB::$db
protected

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

Referenced by __construct().

◆ $get_now

ilDBStepExecutionDB::$get_now
protected

Definition at line 36 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: