ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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;
26 
28 {
29  protected ?string $db_name = null;
31 
35  public function getLabel(): string
36  {
37  return "Migration to convert tables from MyISAM to Innodb service";
38  }
39 
44  {
45  return 20;
46  }
47 
51  public function getPreconditions(Environment $environment): array
52  {
53  return [
57  ];
58  }
59 
63  public function prepare(Environment $environment): void
64  {
68  $this->database = $environment->getResource(Environment::RESOURCE_DATABASE);
69  $client_ini = $environment->getResource(Environment::RESOURCE_CLIENT_INI);
70  $this->db_name = $client_ini->readVariable('db', 'name');
71  }
72 
77  public function step(Environment $environment): void
78  {
79  $rows = $this->getNonInnoDBTables();
80  $table_name = array_pop($rows);
81 
82  if (is_string($table_name) && $table_name !== '') {
83  try {
84  $this->database->migrateTableToEngine($table_name);
85  } catch (\ilDatabaseException $e) {
86  throw new UnachievableException(
87  "The migration of the following tables did throw errors, " .
88  "please resolve the problem before you continue: \n" . $table_name . " -> " . $e->getMessage()
89  );
90  }
91  }
92  }
93 
97  public function getRemainingAmountOfSteps(): int
98  {
99  if ($this->db_name !== null) {
100  $rows = $this->getNonInnoDBTables();
101  return count($rows);
102  }
103  return 0;
104  }
105 
106  protected function getNonInnoDBTables(): array
107  {
108  $tables = [];
109  $set = $this->database->queryF("SELECT table_name
110  FROM INFORMATION_SCHEMA.TABLES
111  WHERE ENGINE != %s AND table_schema = %s;", ['text', 'text'], [
113  $this->db_name
114  ]);
115  while ($row = $this->database->fetchAssoc($set)) {
116  $tables[] = $row['table_name'];
117  }
118  return $tables;
119  }
120 }
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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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.
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