InnoDB.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OC\Repair;
  25. use Doctrine\DBAL\Platforms\MySqlPlatform;
  26. use OCP\Migration\IOutput;
  27. use OCP\Migration\IRepairStep;
  28. class InnoDB implements IRepairStep {
  29. public function getName() {
  30. return 'Repair MySQL database engine';
  31. }
  32. /**
  33. * Fix mime types
  34. */
  35. public function run(IOutput $output) {
  36. $connection = \OC::$server->getDatabaseConnection();
  37. if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) {
  38. $output->info('Not a mysql database -> nothing to do');
  39. return;
  40. }
  41. $tables = $this->getAllMyIsamTables($connection);
  42. if (is_array($tables)) {
  43. foreach ($tables as $table) {
  44. $connection->exec("ALTER TABLE $table ENGINE=InnoDB;");
  45. $output->info("Fixed $table");
  46. }
  47. }
  48. }
  49. /**
  50. * @param \Doctrine\DBAL\Connection $connection
  51. * @return string[]
  52. */
  53. private function getAllMyIsamTables($connection) {
  54. $dbName = \OC::$server->getConfig()->getSystemValue("dbname");
  55. $result = $connection->fetchArray(
  56. "SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND engine = 'MyISAM' AND TABLE_NAME LIKE \"*PREFIX*%\"",
  57. array($dbName)
  58. );
  59. return $result;
  60. }
  61. }