ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilDatabaseEnvironmentValidObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
26 {
30  private const ROW_FORMAT_DYNAMIC = "DYNAMIC";
34  private const INNO_DB = "InnoDB";
35 
36  public function getHash(): string
37  {
38  return hash("sha256", self::class);
39  }
40 
41  public function getLabel(): string
42  {
43  return "The database server has valid settings.";
44  }
45 
46  public function isNotable(): bool
47  {
48  return true;
49  }
50 
54  public function getPreconditions(Environment $environment): array
55  {
56  return [ ];
57  }
58 
59  public function achieve(Environment $environment): Environment
60  {
65  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
66  $io = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION);
67  $this->checkDBAvailable($db);
68  $this->checkRowFormat($db);
69  $io->inform("Default Row Format is " . self::ROW_FORMAT_DYNAMIC . ".");
70  $this->checkDefaultEngine($db);
71  $io->inform("Default Engine is InnoDB.");
72 
73  return $environment;
74  }
75 
76  protected function checkDefaultEngine(ilDBInterface $db)
77  {
78  $default_engine = 'unknown';
79  try {
80  $r = $db->query('SHOW ENGINES ');
81  while ($d = $db->fetchObject($r)) {
82  if (strtoupper((string) $d->Support) === 'DEFAULT') {
83  $default_engine = strtolower((string) $d->Engine);
84  break;
85  }
86  }
87  } catch (Throwable) {
88  }
89  $default_engine = strtolower($default_engine);
90 
91  if ($default_engine !== strtolower(self::INNO_DB)) {
92  throw new UnachievableException(
93  "The default database engine is not set to '" . self::INNO_DB
94  . ", `$default_engine` given'. Please set the default database engine to '"
95  . self::INNO_DB . " to proceed'."
96  );
97  }
98  }
99 
100  protected function checkRowFormat(ilDBInterface $db): void
101  {
102  $setting = $db->fetchObject($db->query('SELECT @@GLOBAL.innodb_default_row_format AS row_format;'));
103  $row_format = $setting->row_format ?? null;
104  if ($row_format === null || strtoupper((string) $row_format) !== self::ROW_FORMAT_DYNAMIC) {
105  throw new UnachievableException(
106  "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."
107  );
108  }
109  }
110 
115  protected function checkDBAvailable(?ilDBInterface $db): void
116  {
117  if ($db === null) {
118  throw new UnachievableException(
119  "Database cannot be connected. Please check the credentials."
120  );
121  }
122  }
123 
127  public function isApplicable(Environment $environment): bool
128  {
129  return true;
130  }
131 }
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:30
isNotable()
Get to know if this is an interesting objective for a human.
getLabel()
Get a label that describes this objective.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Signals that some goal won&#39;t be achievable by actions of the system ever.
fetchObject(ilDBStatement $query_result)
query(string $query)
Run a (read-only) Query on the database.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
achieve(Environment $environment)
Objectives can be achieved.
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
$r