innodb.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Robin Appelman <icewind@owncloud.com>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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 OC\Hooks\BasicEmitter;
  27. class InnoDB extends BasicEmitter implements \OC\RepairStep {
  28. public function getName() {
  29. return 'Repair MySQL database engine';
  30. }
  31. /**
  32. * Fix mime types
  33. */
  34. public function run() {
  35. $connection = \OC_DB::getConnection();
  36. if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) {
  37. $this->emit('\OC\Repair', 'info', array('Not a mysql database -> nothing to do'));
  38. return;
  39. }
  40. $tables = $this->getAllMyIsamTables($connection);
  41. if (is_array($tables)) {
  42. foreach ($tables as $table) {
  43. $connection->exec("ALTER TABLE $table ENGINE=InnoDB;");
  44. $this->emit('\OC\Repair', 'info', array("Fixed $table"));
  45. }
  46. }
  47. }
  48. /**
  49. * @param \Doctrine\DBAL\Connection $connection
  50. * @return string[]
  51. */
  52. private function getAllMyIsamTables($connection) {
  53. $dbName = \OC::$server->getConfig()->getSystemValue("dbname");
  54. $result = $connection->fetchArray(
  55. "SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND engine = 'MyISAM' AND TABLE_NAME LIKE \"*PREFIX*%\"",
  56. array($dbName)
  57. );
  58. return $result;
  59. }
  60. }