RemoveObjectProperties.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-only
  5. */
  6. namespace OCA\DAV\Migration;
  7. use OCP\DB\QueryBuilder\IQueryBuilder;
  8. use OCP\IDBConnection;
  9. use OCP\Migration\IOutput;
  10. use OCP\Migration\IRepairStep;
  11. class RemoveObjectProperties implements IRepairStep {
  12. private const RESOURCE_TYPE_PROPERTY = '{DAV:}resourcetype';
  13. private const ME_CARD_PROPERTY = '{http://calendarserver.org/ns/}me-card';
  14. private const CALENDAR_TRANSP_PROPERTY = '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp';
  15. /** @var IDBConnection */
  16. private $connection;
  17. /**
  18. * RemoveObjectProperties constructor.
  19. *
  20. * @param IDBConnection $connection
  21. */
  22. public function __construct(IDBConnection $connection) {
  23. $this->connection = $connection;
  24. }
  25. /**
  26. * @inheritdoc
  27. */
  28. public function getName() {
  29. return 'Remove invalid object properties';
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function run(IOutput $output) {
  35. $query = $this->connection->getQueryBuilder();
  36. $updated = $query->delete('properties')
  37. ->where($query->expr()->in('propertyname', $query->createNamedParameter([self::RESOURCE_TYPE_PROPERTY, self::ME_CARD_PROPERTY, self::CALENDAR_TRANSP_PROPERTY], IQueryBuilder::PARAM_STR_ARRAY)))
  38. ->andWhere($query->expr()->eq('propertyvalue', $query->createNamedParameter('Object'), IQueryBuilder::PARAM_STR))
  39. ->executeStatement();
  40. $output->info("$updated invalid object properties removed.");
  41. }
  42. }