1
0

dropoldtables.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OC\Repair;
  22. use OC\DB\Connection;
  23. use OC\Hooks\BasicEmitter;
  24. use OC\RepairStep;
  25. class DropOldTables extends BasicEmitter implements RepairStep {
  26. /** @var Connection */
  27. protected $connection;
  28. /**
  29. * @param Connection $connection
  30. */
  31. public function __construct(Connection $connection) {
  32. $this->connection = $connection;
  33. }
  34. /**
  35. * Returns the step's name
  36. *
  37. * @return string
  38. */
  39. public function getName() {
  40. return 'Drop old database tables';
  41. }
  42. /**
  43. * Run repair step.
  44. * Must throw exception on error.
  45. *
  46. * @throws \Exception in case of failure
  47. */
  48. public function run() {
  49. foreach ($this->oldDatabaseTables() as $tableName) {
  50. if ($this->connection->tableExists($tableName)){
  51. $this->emit('\OC\Repair', 'info', [
  52. sprintf('Table %s has been deleted', $tableName)
  53. ]);
  54. $this->connection->dropTable($tableName);
  55. }
  56. }
  57. }
  58. /**
  59. * Returns a list of outdated tables which are not used anymore
  60. * @return array
  61. */
  62. protected function oldDatabaseTables() {
  63. return [
  64. 'calendar_calendars',
  65. 'calendar_objects',
  66. 'calendar_share_calendar',
  67. 'calendar_share_event',
  68. 'foldersize',
  69. 'fscache',
  70. 'locks',
  71. 'log',
  72. 'media_albums',
  73. 'media_artists',
  74. 'media_sessions',
  75. 'media_songs',
  76. 'media_users',
  77. 'permissions',
  78. 'pictures_images_cache',
  79. 'queuedtasks',
  80. 'sharing',
  81. ];
  82. }
  83. }