ILIAS  release_8 Revision v8.24
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)
 @inheritDoc More...
 
- 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 23 of file class.ilDatabasePopulatedObjective.php.

Member Function Documentation

◆ getDefaultEngine()

ilDatabasePopulatedObjective::getDefaultEngine ( ilDBInterface  $db)
private

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

178 : string
179 {
180 try {
181 $r = $db->query('SHOW ENGINES ');
182
183 $default = '';
184 while ($d = $db->fetchObject($r)) {
185 if (strtoupper($d->Support) === 'DEFAULT') {
186 $default = $d->Engine;
187 break;
188 }
189 }
190 return strtolower($default);
191 } catch (Throwable $e) {
192 return 'unknown';
193 }
194 }
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
fetchObject(ilDBStatement $query_result)
query(string $query)
Run a (read-only) Query on the database.

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

+ Here is the call graph for this function:

◆ getHash()

ilDatabasePopulatedObjective::getHash ( )

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

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

◆ getLabel()

ilDatabasePopulatedObjective::getLabel ( )

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

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

◆ getPreconditions()

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

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

50 : array
51 {
52 if ($environment->getResource(Setup\Environment::RESOURCE_DATABASE)) {
53 return [];
54 }
55 return [
56 new \ilDatabaseExistsObjective($this->config)
57 ];
58 }

◆ isApplicable()

ilDatabasePopulatedObjective::isApplicable ( Setup\Environment  $environment)

@inheritDoc

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

93 : bool
94 {
95 $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
96
97 return !$this->isDatabasePopulated($db);
98 }

References isDatabasePopulated().

+ Here is the call graph for this function:

◆ isDatabasePopulated()

ilDatabasePopulatedObjective::isDatabasePopulated ( ilDBInterface  $db)
protected

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

100 : bool
101 {
102 $probe_tables = ['usr_data', 'object_data', 'object_reference'];
103 $number_of_probe_tables = count($probe_tables);
104 $tables = $db->listTables();
105 $number_of_tables = count($tables);
106
107 return
108 $number_of_tables > self::MIN_NUMBER_OF_ILIAS_TABLES
109 && count(array_intersect($tables, $probe_tables)) === $number_of_probe_tables;
110 }

References ilDBInterface\listTables().

Referenced by isApplicable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isNotable()

ilDatabasePopulatedObjective::isNotable ( )

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

42 : bool
43 {
44 return true;
45 }

◆ queryReader()

ilDatabasePopulatedObjective::queryReader ( string  $path_to_db_dump)
private

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

137 : Generator
138 {
139 $stack = '';
140 $handle = fopen($path_to_db_dump, "r");
141 while (($line = fgets($handle)) !== false) {
142 if (preg_match('/^--/', $line)) { // Skip comments
143 continue;
144 }
145 if (preg_match('/^\/\*/', $line)) { // Run Variables Assignments as single query
146 yield $line;
147 $stack = '';
148 continue;
149 }
150 if (!preg_match('/;$/', trim($line))) { // Break after ; character which indicates end of query
151 $stack .= $line;
152 } else {
153 $stack .= $line;
154 yield $stack;
155 $stack = '';
156 }
157 }
158
159 fclose($handle);
160 }

Referenced by readDumpFile().

+ Here is the caller graph for this function:

◆ readDumpFile()

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

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

115 : void
116 {
117 $path_to_db_dump = $this->config->getPathToDBDump();
118 if (!is_file(realpath($path_to_db_dump)) ||
119 !is_readable(realpath($path_to_db_dump))) {
120 throw new Setup\UnachievableException(
121 "Cannot read database dump file: $path_to_db_dump"
122 );
123 }
124 foreach ($this->queryReader(realpath($path_to_db_dump)) as $query) {
125 try {
126 $statement = $db->prepareManip($query);
127 $db->execute($statement);
128 } catch (Throwable $e) {
129 throw new Setup\UnachievableException(
130 "Cannot populate database with dump file: $path_to_db_dump. Query failed: $query wih message " . $e->getMessage(
131 )
132 );
133 }
134 }
135 }
prepareManip(string $a_query, ?array $a_types=null)
execute(ilDBStatement $stmt, array $data=[])
$query

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

+ Here is the call graph for this function:

◆ setDefaultEngine()

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

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

166 : void
167 {
168 switch ($db->getDBType()) {
169 case 'pdo-mysql-innodb':
173 $db->manipulate('SET default_storage_engine=InnoDB;');
174 break;
175 }
176 }
manipulate(string $query)
Run a (write) Query on the database.
getDBType()
Get DSN.

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

+ 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 25 of file class.ilDatabasePopulatedObjective.php.


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