ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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
 $config
 

Detailed Description

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

Member Function Documentation

◆ getDefaultEngine()

ilDatabasePopulatedObjective::getDefaultEngine ( ilDBInterface  $db)
private
Parameters
ilDBInterface$db
Returns
string

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

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

Referenced by getPreconditions().

167  : string
168  {
169  try {
170  $r = $db->query('SHOW ENGINES ');
171 
172  $default = '';
173  while ($d = $db->fetchObject($r)) {
174  if ($d->Support === 'DEFAULT') {
175  $default = $d->Engine;
176  }
177  }
178  return strtolower($default);
179  } catch (Throwable $e) {
180  return 'unknown';
181  }
182  }
fetchObject($query_result)
query($query)
Run a (read-only) Query on the database.
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHash()

ilDatabasePopulatedObjective::getHash ( )

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

11  : string
12  {
13  return hash("sha256", implode("-", [
14  self::class,
15  $this->config->getHost(),
16  $this->config->getPort(),
17  $this->config->getDatabase()
18  ]));
19  }

◆ getLabel()

ilDatabasePopulatedObjective::getLabel ( )

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

21  : string
22  {
23  return "The database is populated with ILIAS-tables.";
24  }

◆ getPreconditions()

ilDatabasePopulatedObjective::getPreconditions ( Setup\Environment  $environment)

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

References getDefaultEngine(), and readDumpFile().

31  : array
32  {
33  if ($environment->getResource(Setup\Environment::RESOURCE_DATABASE)) {
34  return [];
35  }
36  return [
37  new \ilDatabaseExistsObjective($this->config)
38  ];
39  }
+ Here is the call graph for this function:

◆ isApplicable()

ilDatabasePopulatedObjective::isApplicable ( Setup\Environment  $environment)

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

References isDatabasePopulated().

74  : bool
75  {
76  $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
77 
78  return !$this->isDatabasePopulated($db);
79  }
+ Here is the call graph for this function:

◆ isDatabasePopulated()

ilDatabasePopulatedObjective::isDatabasePopulated ( ilDBInterface  $db)
protected

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

References ilDBInterface\listTables().

Referenced by isApplicable().

81  : bool
82  {
83  $probe_tables = ['usr_data', 'object_data', 'object_reference'];
84  $number_of_probe_tables = count($probe_tables);
85  $tables = $db->listTables();
86  $number_of_tables = count($tables);
87 
88  return
89  $number_of_tables > self::MIN_NUMBER_OF_ILIAS_TABLES
90  && count(array_intersect($tables, $probe_tables)) == $number_of_probe_tables;
91  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isNotable()

ilDatabasePopulatedObjective::isNotable ( )

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

26  : bool
27  {
28  return true;
29  }

◆ queryReader()

ilDatabasePopulatedObjective::queryReader ( string  $path_to_db_dump)
private

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

Referenced by readDumpFile().

119  : Generator
120  {
121  $stack = '';
122  $handle = fopen($path_to_db_dump, "r");
123  while (($line = fgets($handle)) !== false) {
124  if (preg_match('/^--/', $line)) { // Skip comments
125  continue;
126  }
127  if (preg_match('/^\/\*/', $line)) { // Run Variables Assignments as single query
128  yield $line;
129  $stack = '';
130  continue;
131  }
132  if (!preg_match('/;$/', trim($line))) { // Break after ; character which indicates end of query
133  $stack .= $line;
134  } else {
135  $stack .= $line;
136  yield $stack;
137  $stack = '';
138  }
139  }
140 
141  fclose($handle);
142  }
+ Here is the caller graph for this function:

◆ readDumpFile()

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

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

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

Referenced by getPreconditions().

97  : void
98  {
99  $path_to_db_dump = $this->config->getPathToDBDump();
100  if (!is_file(realpath($path_to_db_dump)) ||
101  !is_readable(realpath($path_to_db_dump))) {
102  throw new Setup\UnachievableException(
103  "Cannot read database dump file: $path_to_db_dump"
104  );
105  }
106  foreach ($this->queryReader(realpath($path_to_db_dump)) as $query) {
107  try {
108  $statement = $db->prepareManip($query);
109  $db->execute($statement);
110  } catch (Throwable $e) {
111  throw new Setup\UnachievableException(
112  "Cannot populate database with dump file: $path_to_db_dump. Query failed: $query wih message " . $e->getMessage(
113  )
114  );
115  }
116  }
117  }
prepareManip($a_query, $a_types=null)
execute($stmt, $data=array())
$query
+ 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 147 of file class.ilDatabasePopulatedObjective.php.

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

147  : void
148  {
149  switch ($db->getDBType()) {
153  $db->manipulate('SET default_storage_engine=InnoDB;');
154  break;
157  $db->manipulate('SET default_storage_engine=MyISAM;');
158  break;
159 
160  }
161  }
getDBType()
Get DSN.
manipulate($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 9 of file class.ilDatabasePopulatedObjective.php.


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