You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SearchLuceneTables.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  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 OCP\Migration\IOutput;
  26. use OCP\Migration\IRepairStep;
  27. class SearchLuceneTables implements IRepairStep {
  28. public function getName() {
  29. return 'Repair duplicate entries in oc_lucene_status';
  30. }
  31. /**
  32. * Fix duplicate entries in oc_lucene_status
  33. *
  34. * search_lucene prior to v0.5.0 did not have a primary key on the lucene_status table. Newer versions do, which
  35. * causes the migration check to fail because it tries to insert duplicate rows into the new schema.
  36. *
  37. * FIXME Currently, apps don't have a way of repairing anything before the migration check:
  38. * @link https://github.com/owncloud/core/issues/10980
  39. *
  40. * As a result this repair step needs to live in the core repo, although it belongs into search_lucene:
  41. * @link https://github.com/owncloud/core/issues/10205#issuecomment-54957557
  42. *
  43. * It will completely remove any rows that make a file id have more than one status:
  44. * fileid | status fileid | status
  45. * --------+-------- will become --------+--------
  46. * 2 | E 3 | E
  47. * 2 | I
  48. * 3 | E
  49. *
  50. * search_lucene will then reindex the fileids without a status when the next indexing job is executed
  51. */
  52. public function run(IOutput $out) {
  53. $connection = \OC::$server->getDatabaseConnection();
  54. if ($connection->tableExists('lucene_status')) {
  55. $out->info('removing duplicate entries from lucene_status');
  56. $query = $connection->prepare('
  57. DELETE FROM `*PREFIX*lucene_status`
  58. WHERE `fileid` IN (
  59. SELECT `fileid`
  60. FROM (
  61. SELECT `fileid`
  62. FROM `*PREFIX*lucene_status`
  63. GROUP BY `fileid`
  64. HAVING count(`fileid`) > 1
  65. ) AS `mysqlerr1093hack`
  66. )');
  67. $query->execute();
  68. } else {
  69. $out->info('lucene_status table does not exist -> nothing to do');
  70. }
  71. }
  72. }