RemoveObjectProperties.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021, Thomas Citharel <nextcloud@tcit.fr>.
  4. *
  5. * @author Thomas Citharel <nextcloud@tcit.fr>
  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 OCA\DAV\Migration;
  23. use OCP\DB\QueryBuilder\IQueryBuilder;
  24. use OCP\IDBConnection;
  25. use OCP\Migration\IOutput;
  26. use OCP\Migration\IRepairStep;
  27. class RemoveObjectProperties implements IRepairStep {
  28. private const RESOURCE_TYPE_PROPERTY = '{DAV:}resourcetype';
  29. private const ME_CARD_PROPERTY = '{http://calendarserver.org/ns/}me-card';
  30. private const CALENDAR_TRANSP_PROPERTY = '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp';
  31. /** @var IDBConnection */
  32. private $connection;
  33. /**
  34. * RemoveObjectProperties constructor.
  35. *
  36. * @param IDBConnection $connection
  37. */
  38. public function __construct(IDBConnection $connection) {
  39. $this->connection = $connection;
  40. }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function getName() {
  45. return 'Remove invalid object properties';
  46. }
  47. /**
  48. * @inheritdoc
  49. */
  50. public function run(IOutput $output) {
  51. $query = $this->connection->getQueryBuilder();
  52. $updated = $query->delete('properties')
  53. ->where($query->expr()->in('propertyname', $query->createNamedParameter([self::RESOURCE_TYPE_PROPERTY, self::ME_CARD_PROPERTY, self::CALENDAR_TRANSP_PROPERTY], IQueryBuilder::PARAM_STR_ARRAY)))
  54. ->andWhere($query->expr()->eq('propertyvalue', $query->createNamedParameter('Object'), IQueryBuilder::PARAM_STR))
  55. ->executeStatement();
  56. $output->info("$updated invalid object properties removed.");
  57. }
  58. }