ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilDatabaseEnvironmentValidObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Setup;
22
24{
25 private const ROW_FORMAT_DYNAMIC = "DYNAMIC";
26 private const INNO_DB = "InnoDB";
27
28 public function getHash(): string
29 {
30 return hash("sha256", self::class);
31 }
32
33 public function getLabel(): string
34 {
35 return "The database server has valid settings.";
36 }
37
38 public function isNotable(): bool
39 {
40 return true;
41 }
42
46 public function getPreconditions(Setup\Environment $environment): array
47 {
48 return [ ];
49 }
50
51 public function achieve(Setup\Environment $environment): Setup\Environment
52 {
57 $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
58 $io = $environment->getResource(Setup\Environment::RESOURCE_ADMIN_INTERACTION);
59 $this->checkDBAvailable($db);
60 $this->checkRowFormat($db);
61 $io->inform("Default Row Format is " . self::ROW_FORMAT_DYNAMIC . ".");
62 $this->checkDefaultEngine($db);
63 $io->inform("Default Engine is InnoDB.");
64
65 return $environment;
66 }
67
68 protected function checkDefaultEngine(ilDBInterface $db)
69 {
70 $default_engine = 'unknown';
71 try {
72 $r = $db->query('SHOW ENGINES ');
73 while ($d = $db->fetchObject($r)) {
74 if (strtoupper($d->Support) === 'DEFAULT') {
75 $default_engine = strtolower($d->Engine);
76 break;
77 }
78 }
79 } catch (Throwable $e) {
80 }
81 $default_engine = strtolower($default_engine);
82
83 if ($default_engine !== strtolower(self::INNO_DB)) {
85 "The default database engine is not set to '" . self::INNO_DB
86 . ", `$default_engine` given'. Please set the default database engine to '"
87 . self::INNO_DB . " to proceed'."
88 );
89 }
90 }
91
92 protected function checkRowFormat(ilDBInterface $db): void
93 {
94 $setting = $db->fetchObject($db->query('SELECT @@GLOBAL.innodb_default_row_format AS row_format;'));
95 $row_format = $setting->row_format ?? null;
96 if ($row_format === null || strtoupper($row_format) !== self::ROW_FORMAT_DYNAMIC) {
98 "The default row format of the database is not set to '" . self::ROW_FORMAT_DYNAMIC . "'. Please set the default row format to " . self::ROW_FORMAT_DYNAMIC . " and run an 'OPTIMIZE TABLE' for each of your database tables before you continue."
99 );
100 }
101 }
102
107 protected function checkDBAvailable(?ilDBInterface $db): void
108 {
109 if ($db === null) {
111 "Database cannot be connected. Please check the credentials."
112 );
113 }
114 }
115
119 public function isApplicable(Setup\Environment $environment): bool
120 {
121 return true;
122 }
123}
Signals that some goal won't be achievable by actions of the system ever.
isApplicable(Setup\Environment $environment)
@inheritDoc
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
Interface ilDBInterface.
fetchObject(ilDBStatement $query_result)
query(string $query)
Run a (read-only) Query on the database.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...