ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilDatabasePopulatedObjective Class Reference
+ Inheritance diagram for ilDatabasePopulatedObjective:
+ Collaboration diagram for ilDatabasePopulatedObjective:

Public Member Functions

 getHash ()
 
 getLabel ()
 
 isNotable ()
 
 getPreconditions (Setup\Environment $environment)
 
 isApplicable (Setup\Environment $environment)
 
- Public Member Functions inherited from ilDatabaseObjective
 __construct (\ilDatabaseSetupConfig $config)
 

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)
 

Additional Inherited Members

- Protected Attributes inherited from ilDatabaseObjective
ilDatabaseSetupConfig $config
 

Detailed Description

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

Member Function Documentation

◆ getDefaultEngine()

ilDatabasePopulatedObjective::getDefaultEngine ( ilDBInterface  $db)
private

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

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

Referenced by getPreconditions().

190  : string
191  {
192  try {
193  $r = $db->query('SHOW ENGINES ');
194 
195  $default = '';
196  while ($d = $db->fetchObject($r)) {
197  if (strtoupper($d->Support) === 'DEFAULT') {
198  $default = $d->Engine;
199  break;
200  }
201  }
202  return strtolower($default);
203  } catch (Throwable $e) {
204  return 'unknown';
205  }
206  }
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 ( )

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

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

◆ getLabel()

ilDatabasePopulatedObjective::getLabel ( )

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

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

◆ getPreconditions()

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

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

References getDefaultEngine(), and readDumpFile().

52  : array
53  {
54  if ($environment->hasConfigFor(Setup\CLI\InstallCommand::IMPORT)) {
55  return [new ObjectiveWithPreconditions(
56  new \ilDatabaseExistsObjective($this->config),
57  new ImportFileUnzippedFileObjective($environment->getConfigFor(Setup\CLI\InstallCommand::IMPORT))
58  )];
59  }
60  if ($environment->getResource(Setup\Environment::RESOURCE_DATABASE)) {
61  return [];
62  }
63  return [
64  new \ilDatabaseExistsObjective($this->config)
65  ];
66  }
A wrapper around an objective that adds some preconditions.
+ Here is the call graph for this function:

◆ isApplicable()

ilDatabasePopulatedObjective::isApplicable ( Setup\Environment  $environment)

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

References isDatabasePopulated().

101  : bool
102  {
103  if ($environment->hasConfigFor(Setup\CLI\InstallCommand::IMPORT)) {
104  return true;
105  }
106 
107  $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
108 
109  return !$this->isDatabasePopulated($db);
110  }
+ Here is the call graph for this function:

◆ isDatabasePopulated()

ilDatabasePopulatedObjective::isDatabasePopulated ( ilDBInterface  $db)
protected

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

References ilDBInterface\listTables().

Referenced by isApplicable().

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

◆ isNotable()

ilDatabasePopulatedObjective::isNotable ( )

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

44  : bool
45  {
46  return true;
47  }

◆ queryReader()

ilDatabasePopulatedObjective::queryReader ( string  $path_to_db_dump)
private

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

Referenced by readDumpFile().

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

◆ readDumpFile()

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

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

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

Referenced by getPreconditions().

127  : void
128  {
129  $path_to_db_dump = $this->config->getPathToDBDump();
130  if (!is_file(realpath($path_to_db_dump) ?: '') ||
131  !is_readable(realpath($path_to_db_dump) ?: '')) {
132  throw new Setup\UnachievableException(
133  "Cannot read database dump file: $path_to_db_dump"
134  );
135  }
136  foreach ($this->queryReader(realpath($path_to_db_dump)) as $query) {
137  try {
138  $statement = $db->prepareManip($query);
139  $db->execute($statement);
140  } catch (Throwable $e) {
141  throw new Setup\UnachievableException(
142  "Cannot populate database with dump file: $path_to_db_dump. Query failed: $query wih message " . $e->getMessage(
143  )
144  );
145  }
146  }
147  }
execute(ilDBStatement $stmt, array $data=[])
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 178 of file class.ilDatabasePopulatedObjective.php.

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

178  : void
179  {
180  switch ($db->getDBType()) {
181  case 'pdo-mysql-innodb':
185  $db->manipulate('SET default_storage_engine=InnoDB;');
186  break;
187  }
188  }
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 27 of file class.ilDatabasePopulatedObjective.php.


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