2017-10-05 00:55:43 +02:00
|
|
|
from argparse import ArgumentParser
|
2017-11-16 00:55:49 +01:00
|
|
|
from typing import Any
|
2017-10-05 00:55:43 +02:00
|
|
|
|
2024-05-24 16:49:56 +02:00
|
|
|
from django.core.management.base import CommandError
|
2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
2017-10-05 00:55:43 +02:00
|
|
|
|
2023-11-09 19:24:49 +01:00
|
|
|
from analytics.lib.counts import ALL_COUNT_STATS, do_drop_single_stat
|
2024-05-24 16:49:56 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2017-10-05 00:55:43 +02:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2024-05-24 16:49:56 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
2017-10-05 00:55:43 +02:00
|
|
|
help = """Clear analytics tables."""
|
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2017-11-05 06:54:00 +01:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
parser.add_argument("--force", action="store_true", help="Actually do it.")
|
|
|
|
parser.add_argument("--property", help="The property of the stat to be cleared.")
|
2017-10-05 00:55:43 +02:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2017-11-05 06:54:00 +01:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
property = options["property"]
|
2023-11-09 19:24:49 +01:00
|
|
|
if property not in ALL_COUNT_STATS:
|
2020-06-10 06:41:04 +02:00
|
|
|
raise CommandError(f"Invalid property: {property}")
|
2021-02-12 08:20:45 +01:00
|
|
|
if not options["force"]:
|
2019-05-03 23:20:39 +02:00
|
|
|
raise CommandError("No action taken. Use --force.")
|
2017-10-05 00:55:43 +02:00
|
|
|
|
|
|
|
do_drop_single_stat(property)
|