ResetGeneratedAvatarFlag.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 OC\Repair\NC18;
  8. use OCP\IConfig;
  9. use OCP\IDBConnection;
  10. use OCP\Migration\IOutput;
  11. use OCP\Migration\IRepairStep;
  12. class ResetGeneratedAvatarFlag implements IRepairStep {
  13. /** @var IConfig */
  14. private $config;
  15. /** @var IDBConnection */
  16. private $connection;
  17. public function __construct(IConfig $config,
  18. IDBConnection $connection) {
  19. $this->config = $config;
  20. $this->connection = $connection;
  21. }
  22. public function getName(): string {
  23. return 'Reset generated avatar flag';
  24. }
  25. private function shouldRun(): bool {
  26. $versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0.0');
  27. return version_compare($versionFromBeforeUpdate, '18.0.0.5', '<=');
  28. }
  29. public function run(IOutput $output): void {
  30. if ($this->shouldRun()) {
  31. $query = $this->connection->getQueryBuilder();
  32. $query->delete('preferences')
  33. ->where($query->expr()->eq('appid', $query->createNamedParameter('avatar')))
  34. ->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('generated')));
  35. }
  36. }
  37. }