innodb.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Repair;
  9. use Doctrine\DBAL\Platforms\MySqlPlatform;
  10. use OC\Hooks\BasicEmitter;
  11. class InnoDB extends BasicEmitter implements \OC\RepairStep {
  12. public function getName() {
  13. return 'Repair MySQL database engine';
  14. }
  15. /**
  16. * Fix mime types
  17. */
  18. public function run() {
  19. $connection = \OC_DB::getConnection();
  20. if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) {
  21. $this->emit('\OC\Repair', 'info', array('Not a mysql database -> nothing to do'));
  22. return;
  23. }
  24. $tables = $this->getAllMyIsamTables($connection);
  25. if (is_array($tables)) {
  26. foreach ($tables as $table) {
  27. $connection->exec("ALTER TABLE $table ENGINE=InnoDB;");
  28. $this->emit('\OC\Repair', 'info', array("Fixed $table"));
  29. }
  30. }
  31. }
  32. /**
  33. * @param \Doctrine\DBAL\Connection $connection
  34. * @return string[]
  35. */
  36. private function getAllMyIsamTables($connection) {
  37. $dbName = \OC::$server->getConfig()->getSystemValue("dbname");
  38. $result = $connection->fetchArray(
  39. "SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND engine = 'MyISAM' AND TABLE_NAME LIKE \"*PREFIX*%\"",
  40. array($dbName)
  41. );
  42. return $result;
  43. }
  44. }