1
0

SetAcceptedStatus.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. /** @var IDBConnection */
  16. private $connection;
  17. /** @var IConfig */
  18. private $config;
  19. public function __construct(IDBConnection $connection, IConfig $config) {
  20. $this->connection = $connection;
  21. $this->config = $config;
  22. }
  23. /**
  24. * Returns the step's name
  25. *
  26. * @return string
  27. * @since 9.1.0
  28. */
  29. public function getName(): string {
  30. return 'Set existing shares as accepted';
  31. }
  32. /**
  33. * @param IOutput $output
  34. */
  35. public function run(IOutput $output): void {
  36. if (!$this->shouldRun()) {
  37. return;
  38. }
  39. $query = $this->connection->getQueryBuilder();
  40. $query
  41. ->update('share')
  42. ->set('accepted', $query->createNamedParameter(IShare::STATUS_ACCEPTED))
  43. ->where($query->expr()->in('share_type', $query->createNamedParameter([IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_USERGROUP], IQueryBuilder::PARAM_INT_ARRAY)));
  44. $query->execute();
  45. }
  46. protected function shouldRun() {
  47. $appVersion = $this->config->getAppValue('files_sharing', 'installed_version', '0.0.0');
  48. return version_compare($appVersion, '1.10.1', '<');
  49. }
  50. }