19 declare(strict_types=1);
31 return hash(
"sha256", implode(
"-", [
33 $this->config->getHost(),
34 $this->config->getPort(),
35 $this->config->getDatabase()
41 return "The database is populated with ILIAS-tables.";
54 if ($environment->hasConfigFor(Setup\CLI\InstallCommand::IMPORT)) {
60 if ($environment->getResource(Setup\Environment::RESOURCE_DATABASE)) {
64 new \ilDatabaseExistsObjective($this->config)
68 public function achieve(Setup\
Environment $environment): Setup\Environment
74 $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
75 $io = $environment->getResource(Setup\Environment::RESOURCE_ADMIN_INTERACTION);
80 $io->text(
"Default DB engine is $default");
85 $io->text(
"reading dump file, this may take a while...");
90 throw new Setup\UnachievableException(
91 "Cannot determine database default engine, must be InnoDB, `$default` given." 103 if ($environment->hasConfigFor(Setup\CLI\InstallCommand::IMPORT)) {
107 $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
114 $probe_tables = [
'usr_data',
'object_data',
'object_reference'];
115 $number_of_probe_tables = count($probe_tables);
117 $number_of_tables = count($tables);
120 $number_of_tables > self::MIN_NUMBER_OF_ILIAS_TABLES
121 && count(array_intersect($tables, $probe_tables)) === $number_of_probe_tables;
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" 136 foreach ($this->
queryReader(realpath($path_to_db_dump)) as $query) {
141 throw new Setup\UnachievableException(
142 "Cannot populate database with dump file: $path_to_db_dump. Query failed: $query wih message " . $e->getMessage(
152 $handle = fopen($path_to_db_dump,
"r");
153 while (($line = fgets($handle)) !==
false) {
154 if (preg_match(
'/^--/', $line)) {
157 if (preg_match(
'/^\/\*/', $line)) {
162 if (!preg_match(
'/;$/', trim($line))) {
181 case 'pdo-mysql-innodb':
185 $db->
manipulate(
'SET default_storage_engine=InnoDB;');
193 $r = $db->
query(
'SHOW ENGINES ');
197 if (strtoupper(
$d->Support) ===
'DEFAULT') {
198 $default =
$d->Engine;
202 return strtolower($default);
getPreconditions(Setup\Environment $environment)
setDefaultEngine(ilDBInterface $db)
queryReader(string $path_to_db_dump)
readDumpFile(ilDBInterface $db)
getDefaultEngine(ilDBInterface $db)
A wrapper around an objective that adds some preconditions.
execute(ilDBStatement $stmt, array $data=[])
isDatabasePopulated(ilDBInterface $db)
fetchObject(ilDBStatement $query_result)
const MIN_NUMBER_OF_ILIAS_TABLES
query(string $query)
Run a (read-only) Query on the database.
isApplicable(Setup\Environment $environment)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
prepareManip(string $a_query, ?array $a_types=null)
An environment holds resources to be used in the setup process.
manipulate(string $query)
Run a (write) Query on the database.