-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
fix(user_status): fix the status lifecycle #63151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
miaulalala
wants to merge
5
commits into
master
Choose a base branch
from
fix/noid/user-status-orphan-lifecycle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,015
−13
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aff361e
fix(user_status): clear unreachable automated status when there is no…
miaulalala 6a857b5
fix(user_status): refresh the status timestamp when restoring a backup
miaulalala a9a5eb3
fix(user_status): delete stranded backup statuses in the cleanup job
miaulalala 8204069
feat(user_status): add occ user-status:repair for statuses left behind
miaulalala c66fef6
fix(user_status): use IQueryBuilder::MAX_IN_PARAMETERS for IN-list ch…
miaulalala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\UserStatus\Command; | ||
|
|
||
| use OCA\UserStatus\Db\UserStatusMapper; | ||
| use OCA\UserStatus\Service\StatusService; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| class Repair extends Command { | ||
|
|
||
| public function __construct( | ||
| private UserStatusMapper $mapper, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| #[\Override] | ||
| protected function configure(): void { | ||
| $this | ||
| ->setName('user-status:repair') | ||
| ->setDescription('Repair user statuses left behind by an interrupted automated status') | ||
| ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Only report what would be repaired'); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function execute(InputInterface $input, OutputInterface $output): int { | ||
| $dryRun = (bool)$input->getOption('dry-run'); | ||
| if ($dryRun) { | ||
| $output->writeln('<comment>Dry run, no changes will be written.</comment>'); | ||
| $output->writeln(''); | ||
| } | ||
|
|
||
| $this->repairMissingBackupFlags($output, $dryRun); | ||
| $this->repairOrphanedStatuses($output, $dryRun); | ||
| $this->repairStrandedBackups($output, $dryRun); | ||
|
|
||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| /** | ||
| * Rows written before is_backup had a default are invisible to every query | ||
| * comparing it against false, so other users see them as offline and the | ||
| * cleanup job skips them. | ||
| */ | ||
| private function repairMissingBackupFlags(OutputInterface $output, bool $dryRun): void { | ||
| $ids = $this->mapper->findStatusesWithoutBackupFlagIds(); | ||
| if ($ids === []) { | ||
| $output->writeln('No statuses with a missing backup flag.'); | ||
| return; | ||
| } | ||
|
|
||
| $count = count($ids); | ||
| if ($dryRun) { | ||
| $output->writeln("Would set the backup flag on <info>$count</info> status(es)."); | ||
| $this->listIds($output, $ids); | ||
| return; | ||
| } | ||
|
|
||
| $fixed = $this->mapper->normalizeBackupFlagByIds($ids); | ||
| $output->writeln("Set the backup flag on <info>$fixed</info> status(es)."); | ||
| } | ||
|
|
||
| /** | ||
| * A live status on an automated message id with no backup row can never be | ||
| * reverted by the automation that set it, and the heartbeat refuses to | ||
| * overwrite it, so the user is stuck. Removing the row lets the next | ||
| * heartbeat recreate a normal status. | ||
| */ | ||
| private function repairOrphanedStatuses(OutputInterface $output, bool $dryRun): void { | ||
| $ids = $this->mapper->findOrphanedAutomatedStatusIds(StatusService::AUTOMATED_MESSAGE_IDS); | ||
| if ($ids === []) { | ||
| $output->writeln('No users stuck on an automated status.'); | ||
| return; | ||
| } | ||
|
|
||
| if ($dryRun) { | ||
| $output->writeln('Would clear <info>' . count($ids) . '</info> status(es) stuck on an automated status.'); | ||
| $this->listIds($output, $ids); | ||
| return; | ||
| } | ||
|
|
||
| $deleted = $this->mapper->deleteByIds($ids); | ||
| $output->writeln("Cleared <info>$deleted</info> status(es) stuck on an automated status."); | ||
| } | ||
|
|
||
| /** | ||
| * A backup that can no longer be matched blocks every future automated | ||
| * status change for that user, because createBackupStatus() keeps hitting | ||
| * the unique constraint on user_id. | ||
| */ | ||
| private function repairStrandedBackups(OutputInterface $output, bool $dryRun): void { | ||
| $ids = $this->mapper->findStrandedBackupIds(StatusService::AUTOMATED_MESSAGE_IDS); | ||
| if ($ids === []) { | ||
| $output->writeln('No stranded backup statuses.'); | ||
| return; | ||
| } | ||
|
|
||
| if ($dryRun) { | ||
| $output->writeln('Would remove <info>' . count($ids) . '</info> stranded backup status(es).'); | ||
| $this->listIds($output, $ids); | ||
| return; | ||
| } | ||
|
|
||
| $deleted = $this->mapper->deleteByIds($ids); | ||
| $output->writeln("Removed <info>$deleted</info> stranded backup status(es)."); | ||
| } | ||
|
|
||
| /** | ||
| * The ids are what an administrator needs to look the rows up themselves, | ||
| * but there can be a lot of them, so only spell them out when asked. | ||
| * | ||
| * @param list<int> $ids | ||
| */ | ||
| private function listIds(OutputInterface $output, array $ids): void { | ||
| if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { | ||
| $output->writeln(' ids: ' . implode(', ', $ids)); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.