searchlucenetables.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Repair;
  23. use OC\Hooks\BasicEmitter;
  24. class SearchLuceneTables extends BasicEmitter implements \OC\RepairStep {
  25. public function getName() {
  26. return 'Repair duplicate entries in oc_lucene_status';
  27. }
  28. /**
  29. * Fix duplicate entries in oc_lucene_status
  30. *
  31. * search_lucene prior to v0.5.0 did not have a primary key on the lucene_status table. Newer versions do, which
  32. * causes the migration check to fail because it tries to insert duplicate rows into the new schema.
  33. *
  34. * FIXME Currently, apps don't have a way of repairing anything before the migration check:
  35. * @link https://github.com/owncloud/core/issues/10980
  36. *
  37. * As a result this repair step needs to live in the core repo, although it belongs into search_lucene:
  38. * @link https://github.com/owncloud/core/issues/10205#issuecomment-54957557
  39. *
  40. * It will completely remove any rows that make a file id have more than one status:
  41. * fileid | status fileid | status
  42. * --------+-------- will become --------+--------
  43. * 2 | E 3 | E
  44. * 2 | I
  45. * 3 | E
  46. *
  47. * search_lucene will then reindex the fileids without a status when the next indexing job is executed
  48. */
  49. public function run() {
  50. if (\OC_DB::tableExists('lucene_status')) {
  51. $this->emit('\OC\Repair', 'info', array('removing duplicate entries from lucene_status'));
  52. $connection = \OC_DB::getConnection();
  53. $query = $connection->prepare('
  54. DELETE FROM `*PREFIX*lucene_status`
  55. WHERE `fileid` IN (
  56. SELECT `fileid`
  57. FROM (
  58. SELECT `fileid`
  59. FROM `*PREFIX*lucene_status`
  60. GROUP BY `fileid`
  61. HAVING count(`fileid`) > 1
  62. ) AS `mysqlerr1093hack`
  63. )');
  64. $query->execute();
  65. } else {
  66. $this->emit('\OC\Repair', 'info', array('lucene_status table does not exist -> nothing to do'));
  67. }
  68. }
  69. }