ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilDatabasePopulatedObjective Class Reference
+ Inheritance diagram for ilDatabasePopulatedObjective:
+ Collaboration diagram for ilDatabasePopulatedObjective:

Public Member Functions

 getHash ()
 Get a hash for this objective. More...
 
 getLabel ()
 Get a label that describes this objective. More...
 
 isNotable ()
 Get to know if this is an interesting objective for a human. More...
 
 getPreconditions (Environment $environment)
 
 isApplicable (Environment $environment)
 
- Public Member Functions inherited from ilDatabaseObjective
 __construct (protected \ilDatabaseSetupConfig $config)
 
- Public Member Functions inherited from ILIAS\Setup\Objective
 achieve (Environment $environment)
 Objectives can be achieved. More...
 

Data Fields

const MIN_NUMBER_OF_ILIAS_TABLES = 200
 

Protected Member Functions

 isDatabasePopulated (ilDBInterface $db)
 

Private Member Functions

 readDumpFile (ilDBInterface $db)
 
 queryReader (string $path_to_db_dump)
 
 setDefaultEngine (ilDBInterface $db)
 
 getDefaultEngine (ilDBInterface $db)
 

Detailed Description

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

Member Function Documentation

◆ getDefaultEngine()

ilDatabasePopulatedObjective::getDefaultEngine ( ilDBInterface  $db)
private

Definition at line 192 of file class.ilDatabasePopulatedObjective.php.

References Vendor\Package\$d, $r, ilDBInterface\fetchObject(), and ilDBInterface\query().

Referenced by getPreconditions().

192  : string
193  {
194  try {
195  $r = $db->query('SHOW ENGINES ');
196 
197  $default = '';
198  while ($d = $db->fetchObject($r)) {
199  if (strtoupper((string) $d->Support) === 'DEFAULT') {
200  $default = $d->Engine;
201  break;
202  }
203  }
204  return strtolower((string) $default);
205  } catch (Throwable) {
206  return 'unknown';
207  }
208  }
fetchObject(ilDBStatement $query_result)
query(string $query)
Run a (read-only) Query on the database.
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHash()

ilDatabasePopulatedObjective::getHash ( )

Get a hash for this objective.

The hash of two objectives must be the same, if they are the same objective, with the same config on the same environment, i.e. if the one is achieved the other is achieved as well because they are the same.

Implements ILIAS\Setup\Objective.

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

31  : string
32  {
33  return hash("sha256", implode("-", [
34  self::class,
35  $this->config->getHost(),
36  $this->config->getPort(),
37  $this->config->getDatabase()
38  ]));
39  }

◆ getLabel()

ilDatabasePopulatedObjective::getLabel ( )

Get a label that describes this objective.

Implements ILIAS\Setup\Objective.

Definition at line 41 of file class.ilDatabasePopulatedObjective.php.

41  : string
42  {
43  return "The database is populated with ILIAS-tables.";
44  }

◆ getPreconditions()

ilDatabasePopulatedObjective::getPreconditions ( Environment  $environment)
Returns
[]

Implements ILIAS\Setup\Objective.

Definition at line 54 of file class.ilDatabasePopulatedObjective.php.

References ILIAS\Setup\Objective\achieve(), ILIAS\Setup\Environment\getConfigFor(), getDefaultEngine(), ILIAS\Setup\Environment\getResource(), ILIAS\Setup\Environment\hasConfigFor(), and readDumpFile().

54  : array
55  {
56  if ($environment->hasConfigFor(InstallCommand::IMPORT)) {
57  return [new ObjectiveWithPreconditions(
58  new \ilDatabaseExistsObjective($this->config),
59  new ImportFileUnzippedFileObjective($environment->getConfigFor(InstallCommand::IMPORT))
60  )];
61  }
62  if ($environment->getResource(Environment::RESOURCE_DATABASE)) {
63  return [];
64  }
65  return [
66  new \ilDatabaseExistsObjective($this->config)
67  ];
68  }
A wrapper around an objective that adds some preconditions.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
hasConfigFor(string $component)
getConfigFor(string $component)
+ Here is the call graph for this function:

◆ isApplicable()

ilDatabasePopulatedObjective::isApplicable ( Environment  $environment)

Implements ILIAS\Setup\Objective.

Definition at line 103 of file class.ilDatabasePopulatedObjective.php.

References ILIAS\Setup\Environment\getResource(), ILIAS\Setup\Environment\hasConfigFor(), and isDatabasePopulated().

103  : bool
104  {
105  if ($environment->hasConfigFor(InstallCommand::IMPORT)) {
106  return true;
107  }
108 
109  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
110 
111  return !$this->isDatabasePopulated($db);
112  }
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
hasConfigFor(string $component)
+ Here is the call graph for this function:

◆ isDatabasePopulated()

ilDatabasePopulatedObjective::isDatabasePopulated ( ilDBInterface  $db)
protected

Definition at line 114 of file class.ilDatabasePopulatedObjective.php.

References ilDBInterface\listTables().

Referenced by isApplicable().

114  : bool
115  {
116  $probe_tables = ['usr_data', 'object_data', 'object_reference'];
117  $number_of_probe_tables = count($probe_tables);
118  $tables = $db->listTables();
119  $number_of_tables = count($tables);
120 
121  return
122  $number_of_tables > self::MIN_NUMBER_OF_ILIAS_TABLES
123  && count(array_intersect($tables, $probe_tables)) === $number_of_probe_tables;
124  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isNotable()

ilDatabasePopulatedObjective::isNotable ( )

Get to know if this is an interesting objective for a human.

Implements ILIAS\Setup\Objective.

Definition at line 46 of file class.ilDatabasePopulatedObjective.php.

46  : bool
47  {
48  return true;
49  }

◆ queryReader()

ilDatabasePopulatedObjective::queryReader ( string  $path_to_db_dump)
private

Definition at line 151 of file class.ilDatabasePopulatedObjective.php.

Referenced by readDumpFile().

151  : Generator
152  {
153  $stack = '';
154  $handle = fopen($path_to_db_dump, "r");
155  while (($line = fgets($handle)) !== false) {
156  if (preg_match('/^--/', $line)) { // Skip comments
157  continue;
158  }
159  if (preg_match('/^\/\*/', $line)) { // Run Variables Assignments as single query
160  yield $line;
161  $stack = '';
162  continue;
163  }
164  if (!preg_match('/;$/', trim($line))) { // Break after ; character which indicates end of query
165  $stack .= $line;
166  } else {
167  $stack .= $line;
168  yield $stack;
169  $stack = '';
170  }
171  }
172 
173  fclose($handle);
174  }
+ Here is the caller graph for this function:

◆ readDumpFile()

ilDatabasePopulatedObjective::readDumpFile ( ilDBInterface  $db)
private
Exceptions
ilDatabaseException

Definition at line 129 of file class.ilDatabasePopulatedObjective.php.

References Vendor\Package\$e, ilDBInterface\execute(), ilDBInterface\prepareManip(), and queryReader().

Referenced by getPreconditions().

129  : void
130  {
131  $path_to_db_dump = $this->config->getPathToDBDump();
132  if (!is_file(realpath($path_to_db_dump) ?: '') ||
133  !is_readable(realpath($path_to_db_dump) ?: '')) {
134  throw new UnachievableException(
135  "Cannot read database dump file: $path_to_db_dump"
136  );
137  }
138  foreach ($this->queryReader(realpath($path_to_db_dump)) as $query) {
139  try {
140  $statement = $db->prepareManip($query);
141  $db->execute($statement);
142  } catch (Throwable $e) {
143  throw new UnachievableException(
144  "Cannot populate database with dump file: $path_to_db_dump. Query failed: $query wih message " . $e->getMessage(
145  )
146  );
147  }
148  }
149  }
execute(ilDBStatement $stmt, array $data=[])
Signals that some goal won't be achievable by actions of the system ever.
prepareManip(string $a_query, ?array $a_types=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDefaultEngine()

ilDatabasePopulatedObjective::setDefaultEngine ( ilDBInterface  $db)
private
Parameters
ilDBInterface | null$db

Definition at line 180 of file class.ilDatabasePopulatedObjective.php.

References ilDBInterface\getDBType(), ilDBInterface\manipulate(), ilDBConstants\TYPE_GALERA, ilDBConstants\TYPE_INNODB, and ilDBConstants\TYPE_MYSQL.

180  : void
181  {
182  switch ($db->getDBType()) {
183  case 'pdo-mysql-innodb':
187  $db->manipulate('SET default_storage_engine=InnoDB;');
188  break;
189  }
190  }
getDBType()
Get DSN.
manipulate(string $query)
Run a (write) Query on the database.
+ Here is the call graph for this function:

Field Documentation

◆ MIN_NUMBER_OF_ILIAS_TABLES

const ilDatabasePopulatedObjective::MIN_NUMBER_OF_ILIAS_TABLES = 200

Definition at line 29 of file class.ilDatabasePopulatedObjective.php.


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