DropOldTables.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Florian Preinstorfer <nblock@archlinux.us>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Repair;
  26. use OCP\IDBConnection;
  27. use OCP\Migration\IOutput;
  28. use OCP\Migration\IRepairStep;
  29. class DropOldTables implements IRepairStep {
  30. /** @var IDBConnection */
  31. protected $connection;
  32. /**
  33. * @param IDBConnection $connection
  34. */
  35. public function __construct(IDBConnection $connection) {
  36. $this->connection = $connection;
  37. }
  38. /**
  39. * Returns the step's name
  40. *
  41. * @return string
  42. */
  43. public function getName() {
  44. return 'Drop old database tables';
  45. }
  46. /**
  47. * Run repair step.
  48. * Must throw exception on error.
  49. *
  50. * @throws \Exception in case of failure
  51. */
  52. public function run(IOutput $output) {
  53. $tables = $this->oldDatabaseTables();
  54. $output->startProgress(count($tables));
  55. foreach ($this->oldDatabaseTables() as $tableName) {
  56. if ($this->connection->tableExists($tableName)){
  57. $this->connection->dropTable($tableName);
  58. }
  59. $output->advance(1, "Drop old database table: $tableName");
  60. }
  61. $output->finishProgress();
  62. }
  63. /**
  64. * Returns a list of outdated tables which are not used anymore
  65. * @return array
  66. */
  67. protected function oldDatabaseTables() {
  68. return [
  69. 'calendar_calendars',
  70. 'calendar_objects',
  71. 'calendar_share_calendar',
  72. 'calendar_share_event',
  73. 'file_map',
  74. 'foldersize',
  75. 'fscache',
  76. 'gallery_sharing',
  77. 'locks',
  78. 'log',
  79. 'media_albums',
  80. 'media_artists',
  81. 'media_sessions',
  82. 'media_songs',
  83. 'media_users',
  84. 'permissions',
  85. 'pictures_images_cache',
  86. 'principalgroups',
  87. 'principals',
  88. 'queuedtasks',
  89. 'sharing',
  90. 'clndr_calendars',
  91. 'clndr_objects',
  92. 'clndr_share_event',
  93. 'clndr_share_calendar',
  94. 'clndr_repeat',
  95. 'contacts_addressbooks',
  96. 'contacts_cards',
  97. 'contacts_cards_properties',
  98. 'gallery_albums',
  99. 'gallery_photos'
  100. ];
  101. }
  102. }