searchlucenetables.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. }