RemoveOldShares.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  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 OCP\IDBConnection;
  24. use OCP\Migration\IOutput;
  25. use OCP\Migration\IRepairStep;
  26. /**
  27. * Class RemoveOldShares
  28. *
  29. * @package OC\Repair
  30. */
  31. class RemoveOldShares implements IRepairStep {
  32. /** @var IDBConnection */
  33. protected $connection;
  34. /**
  35. * RemoveOldCalendarShares constructor.
  36. *
  37. * @param IDBConnection $db
  38. */
  39. public function __construct(IDBConnection $connection) {
  40. $this->connection = $connection;
  41. }
  42. /**
  43. * @return string
  44. */
  45. public function getName() {
  46. return 'Remove old (< 9.0) calendar/contact shares';
  47. }
  48. /**
  49. * @param IOutput $output
  50. */
  51. public function run(IOutput $output) {
  52. $output->startProgress(4);
  53. $this->removeCalendarShares($output);
  54. $this->removeContactShares($output);
  55. $output->finishProgress();
  56. }
  57. /**
  58. * @param IOutput $output
  59. */
  60. private function removeCalendarShares(IOutput $output) {
  61. $qb = $this->connection->getQueryBuilder();
  62. $qb->delete('share')
  63. ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('calendar')));
  64. $qb->execute();
  65. $output->advance();
  66. $qb = $this->connection->getQueryBuilder();
  67. $qb->delete('share')
  68. ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('event')));
  69. $qb->execute();
  70. $output->advance();
  71. }
  72. /**
  73. * @param IOutput $output
  74. */
  75. private function removeContactShares(IOutput $output) {
  76. $qb = $this->connection->getQueryBuilder();
  77. $qb->delete('share')
  78. ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('contact')));
  79. $qb->execute();
  80. $output->advance();
  81. $qb = $this->connection->getQueryBuilder();
  82. $qb->delete('share')
  83. ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('addressbook')));
  84. $qb->execute();
  85. $output->advance();
  86. }
  87. }