Version011901Date20240305120000.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\UpdateNotification\Migration;
  8. use OCA\UpdateNotification\BackgroundJob\ResetToken;
  9. use OCP\BackgroundJob\IJobList;
  10. use OCP\Migration\IOutput;
  11. use OCP\Migration\SimpleMigrationStep;
  12. /**
  13. * Drop this with Nextcloud 30
  14. */
  15. class Version011901Date20240305120000 extends SimpleMigrationStep {
  16. public function __construct(
  17. private IJobList $joblist,
  18. ) {
  19. }
  20. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void {
  21. /**
  22. * Remove and replace the reset-updater-token background job
  23. * This class was renamed so it is now unknow but we still need to remove it
  24. * @psalm-suppress UndefinedClass, InvalidArgument
  25. */
  26. $hasOldResetToken = $this->joblist->has(\OCA\UpdateNotification\ResetTokenBackgroundJob::class, null);
  27. $hasNewResetToken = $this->joblist->has(ResetToken::class, null);
  28. if ($hasOldResetToken) {
  29. /**
  30. * @psalm-suppress UndefinedClass, InvalidArgument
  31. */
  32. $this->joblist->remove(\OCA\UpdateNotification\ResetTokenBackgroundJob::class);
  33. if (!$hasNewResetToken) {
  34. $this->joblist->add(ResetToken::class);
  35. }
  36. }
  37. /**
  38. * Remove the "has updates" background job, the new one is automatically started from the info.xml
  39. * @psalm-suppress UndefinedClass, InvalidArgument
  40. */
  41. if ($this->joblist->has(\OCA\UpdateNotification\Notification\BackgroundJob::class, null)) {
  42. /**
  43. * @psalm-suppress UndefinedClass, InvalidArgument
  44. */
  45. $this->joblist->remove(\OCA\UpdateNotification\Notification\BackgroundJob::class);
  46. }
  47. }
  48. }