From 1d12fcd168847377de61393d9b5a5b88fdd0f766 Mon Sep 17 00:00:00 2001 From: Gaurav Pandey Date: Fri, 25 Jun 2021 12:49:35 +0530 Subject: [PATCH] management: Delete fix_unreads command. This command was part of the complex migration to introduce the `unread_msgs` data structure as the source of truth for unreads. Effectively, it's a migration to remove anomalies that we ran several times before turning it into the final 0104_fix_unreads.py migration. Fixes part of #18898. --- zerver/management/commands/fix_unreads.py | 57 ----------------------- 1 file changed, 57 deletions(-) delete mode 100644 zerver/management/commands/fix_unreads.py diff --git a/zerver/management/commands/fix_unreads.py b/zerver/management/commands/fix_unreads.py deleted file mode 100644 index e969f85e97..0000000000 --- a/zerver/management/commands/fix_unreads.py +++ /dev/null @@ -1,57 +0,0 @@ -import logging -from argparse import ArgumentParser -from typing import Any, List, Optional - -from django.db import connection - -from zerver.lib.fix_unreads import fix -from zerver.lib.management import CommandError, ZulipBaseCommand -from zerver.models import Realm, UserProfile - -logging.getLogger("zulip.fix_unreads").setLevel(logging.INFO) - - -class Command(ZulipBaseCommand): - help = """Fix problems related to unread counts.""" - - def add_arguments(self, parser: ArgumentParser) -> None: - parser.add_argument( - "emails", metavar="", nargs="*", help="email address to spelunk" - ) - parser.add_argument("--all", action="store_true", help="fix all users in specified realm") - self.add_realm_args(parser) - - def fix_all_users(self, realm: Realm) -> None: - user_profiles = list( - UserProfile.objects.filter( - realm=realm, - is_bot=False, - ) - ) - for user_profile in user_profiles: - fix(user_profile) - connection.commit() - - def fix_emails(self, realm: Optional[Realm], emails: List[str]) -> None: - - for email in emails: - try: - user_profile = self.get_user(email, realm) - except CommandError: - print(f"e-mail {email} doesn't exist in the realm {realm}, skipping") - return - - fix(user_profile) - connection.commit() - - def handle(self, *args: Any, **options: Any) -> None: - realm = self.get_realm(options) - - if options["all"]: - if realm is None: - raise CommandError("You must specify a realm if you choose the --all option.") - - self.fix_all_users(realm) - return - - self.fix_emails(realm, options["emails"])