2017-11-16 00:43:27 +01:00
|
|
|
from argparse import ArgumentParser
|
2022-07-11 08:47:11 +02:00
|
|
|
from typing import Any
|
2017-07-19 05:56:47 +02:00
|
|
|
|
2022-07-11 08:47:11 +02:00
|
|
|
from zerver.actions.streams import merge_streams
|
2017-08-07 21:42:21 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2022-07-11 08:47:11 +02:00
|
|
|
from zerver.models import get_stream
|
2017-07-19 05:56:47 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2017-08-07 21:42:21 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
2017-07-19 05:56:47 +02:00
|
|
|
help = """Merge two streams."""
|
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
parser.add_argument("stream_to_keep", help="name of stream to keep")
|
2021-02-12 08:19:30 +01:00
|
|
|
parser.add_argument(
|
2021-02-12 08:20:45 +01:00
|
|
|
"stream_to_destroy", help="name of stream to merge into the stream being kept"
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2021-05-10 21:29:25 +02:00
|
|
|
self.add_realm_args(parser, required=True)
|
2017-07-19 05:56:47 +02:00
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def handle(self, *args: Any, **options: str) -> None:
|
2017-08-07 21:42:21 +02:00
|
|
|
realm = self.get_realm(options)
|
2017-09-26 01:25:39 +02:00
|
|
|
assert realm is not None # Should be ensured by parser
|
2017-07-19 05:56:47 +02:00
|
|
|
stream_to_keep = get_stream(options["stream_to_keep"], realm)
|
|
|
|
stream_to_destroy = get_stream(options["stream_to_destroy"], realm)
|
2022-07-11 08:47:11 +02:00
|
|
|
stats = merge_streams(realm, stream_to_keep, stream_to_destroy)
|
|
|
|
print(f"Added { stats[0] } subscriptions")
|
|
|
|
print(f"Moved { stats[1] } messages")
|
|
|
|
print(f"Deactivated { stats[2] } subscriptions")
|