ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ilMysqlMyIsamToInnoDbMigration.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\Setup;
20
24use ilException;
26
28{
29 protected ?string $db_name = null;
30 protected ?\ilDBInterface $database = 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 {
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}
Signals that some goal won't be achievable by actions of the system ever.
getPreconditions(Environment $environment)
@inheritDoc
Class ilDBConstants.
const MYSQL_ENGINE_INNODB
Class ilDatabaseException.
Base class for ILIAS Exception handling.
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.
A migration is a potentially long lasting operation that can be broken into discrete steps.
Definition: Migration.php:29
prepare(Environment $environment)
Prepare the migration by means of some environment.
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...