ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMysqlMyIsamToInnoDbMigration.php
Go to the documentation of this file.
1 <?php
2 
19 namespace ILIAS\Setup;
20 
23 use ilDBConstants;
24 use ilException;
25 use ILIAS\Setup;
27 
29 {
30  protected ?string $db_name = null;
31  protected ?\ilDBInterface $database = null;
32 
36  public function getLabel(): string
37  {
38  return "Migration to convert tables from MyISAM to Innodb service";
39  }
40 
45  {
46  return 20;
47  }
48 
52  public function getPreconditions(Environment $environment): array
53  {
54  return [
58  ];
59  }
60 
64  public function prepare(Environment $environment): void
65  {
69  $this->database = $environment->getResource(Environment::RESOURCE_DATABASE);
70  $client_ini = $environment->getResource(Environment::RESOURCE_CLIENT_INI);
71  $this->db_name = $client_ini->readVariable('db', 'name');
72  }
73 
78  public function step(Environment $environment): void
79  {
80  $rows = $this->getNonInnoDBTables();
81  $table_name = array_pop($rows);
82 
83  if (is_string($table_name) && $table_name !== '') {
84  try {
85  $this->database->migrateTableToEngine($table_name);
86  } catch (\ilDatabaseException $e) {
87  throw new UnachievableException(
88  "The migration of the following tables did throw errors, " .
89  "please resolve the problem before you continue: \n" . $table_name . " -> " . $e->getMessage()
90  );
91  }
92  }
93  }
94 
98  public function getRemainingAmountOfSteps(): int
99  {
100  if ($this->db_name !== null) {
101  $rows = $this->getNonInnoDBTables();
102  return count($rows);
103  }
104  return 0;
105  }
106 
107  protected function getNonInnoDBTables(): array
108  {
109  $tables = [];
110  $set = $this->database->queryF("SELECT table_name
111  FROM INFORMATION_SCHEMA.TABLES
112  WHERE ENGINE != %s AND table_schema = %s;", ['text', 'text'], [
114  $this->db_name
115  ]);
116  while ($row = $this->database->fetchAssoc($set)) {
117  $tables[] = $row['table_name'];
118  }
119  return $tables;
120  }
121 }
A migration is a potentially long lasting operation that can be broken into discrete steps...
Definition: Migration.php:28
prepare(Environment $environment)
Prepare the migration by means of some environment.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
Signals that some goal won&#39;t be achievable by actions of the system ever.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
$rows
Definition: xhr_table.php:10
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27