RemoveObjectProperties.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /**
  16. * RemoveObjectProperties constructor.
  17. *
  18. * @param IDBConnection $connection
  19. */
  20. public function __construct(
  21. private IDBConnection $connection,
  22. ) {
  23. }
  24. /**
  25. * @inheritdoc
  26. */
  27. public function getName() {
  28. return 'Remove invalid object properties';
  29. }
  30. /**
  31. * @inheritdoc
  32. */
  33. public function run(IOutput $output) {
  34. $query = $this->connection->getQueryBuilder();
  35. $updated = $query->delete('properties')
  36. ->where($query->expr()->in('propertyname', $query->createNamedParameter([self::RESOURCE_TYPE_PROPERTY, self::ME_CARD_PROPERTY, self::CALENDAR_TRANSP_PROPERTY], IQueryBuilder::PARAM_STR_ARRAY)))
  37. ->andWhere($query->expr()->eq('propertyvalue', $query->createNamedParameter('Object'), IQueryBuilder::PARAM_STR))
  38. ->executeStatement();
  39. $output->info("$updated invalid object properties removed.");
  40. }
  41. }