SetAcceptedStatus.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files_Sharing\Migration;
  8. use OCP\DB\QueryBuilder\IQueryBuilder;
  9. use OCP\IConfig;
  10. use OCP\IDBConnection;
  11. use OCP\Migration\IOutput;
  12. use OCP\Migration\IRepairStep;
  13. use OCP\Share\IShare;
  14. class SetAcceptedStatus implements IRepairStep {
  15. public function __construct(
  16. private IDBConnection $connection,
  17. private IConfig $config,
  18. ) {
  19. }
  20. /**
  21. * Returns the step's name
  22. *
  23. * @return string
  24. * @since 9.1.0
  25. */
  26. public function getName(): string {
  27. return 'Set existing shares as accepted';
  28. }
  29. /**
  30. * @param IOutput $output
  31. */
  32. public function run(IOutput $output): void {
  33. if (!$this->shouldRun()) {
  34. return;
  35. }
  36. $query = $this->connection->getQueryBuilder();
  37. $query
  38. ->update('share')
  39. ->set('accepted', $query->createNamedParameter(IShare::STATUS_ACCEPTED))
  40. ->where($query->expr()->in('share_type', $query->createNamedParameter([IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_USERGROUP], IQueryBuilder::PARAM_INT_ARRAY)));
  41. $query->executeStatement();
  42. }
  43. protected function shouldRun() {
  44. $appVersion = $this->config->getAppValue('files_sharing', 'installed_version', '0.0.0');
  45. return version_compare($appVersion, '1.10.1', '<');
  46. }
  47. }