From c79d7f1070378840a50abca93f6d1f768d725a30 Mon Sep 17 00:00:00 2001 From: Rhea Parekh Date: Thu, 24 May 2018 17:26:15 +0530 Subject: [PATCH] Import: Move zerver_reaction from 'messages-000001.json' to 'realm.json'. Also change the existing slack conversion script structure, to include 'zerver_realm' in 'realm.json'. --- zerver/lib/import_realm.py | 27 +++++++++++++------------- zerver/lib/slack_data_to_zulip_data.py | 4 ++++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py index 4ffdce8bd0..c6b6e158c0 100644 --- a/zerver/lib/import_realm.py +++ b/zerver/lib/import_realm.py @@ -539,6 +539,19 @@ def do_import_realm(import_dir: Path, subdomain: str) -> Realm: # Import zerver_message and zerver_usermessage import_message_data(import_dir) + # As the export of Reactions is not supported, Zulip exported + # data would not contain this field. + # However this is supported in slack importer script + if 'zerver_reaction' in data: + re_map_foreign_keys(data, 'zerver_reaction', 'message', related_table="message") + re_map_foreign_keys(data, 'zerver_reaction', 'user_profile', related_table="user_profile") + for reaction in data['zerver_reaction']: + if reaction['reaction_type'] == Reaction.REALM_EMOJI: + re_map_foreign_keys(data, 'zerver_reaction', 'emoji_code', + related_table="realmemoji", id_field=True) + update_model_ids(Reaction, data, 'zerver_reaction', 'reaction') + bulk_import_model(data, Reaction, 'zerver_reaction') + # Do attachments AFTER message data is loaded. # TODO: de-dup how we read these json files. fn = os.path.join(import_dir, "attachment.json") @@ -614,20 +627,6 @@ def import_message_data(import_dir: Path) -> None: fix_bitfield_keys(data, 'zerver_usermessage', 'flags') update_model_ids(UserMessage, data, 'zerver_usermessage', 'usermessage') bulk_import_model(data, UserMessage, 'zerver_usermessage') - - # As the export of Reactions is not supported, Zulip exported - # data would not contain this field. - # However this is supported in slack importer script - if 'zerver_reaction' in data: - re_map_foreign_keys(data, 'zerver_reaction', 'message', related_table="message") - re_map_foreign_keys(data, 'zerver_reaction', 'user_profile', related_table="user_profile") - for reaction in data['zerver_reaction']: - if reaction['reaction_type'] == Reaction.REALM_EMOJI: - re_map_foreign_keys(data, 'zerver_reaction', 'emoji_code', - related_table="realmemoji", id_field=True) - update_model_ids(Reaction, data, 'zerver_reaction', 'reaction') - bulk_import_model(data, Reaction, 'zerver_reaction') - dump_file_id += 1 def import_attachments(data: TableData) -> None: diff --git a/zerver/lib/slack_data_to_zulip_data.py b/zerver/lib/slack_data_to_zulip_data.py index fcc712ab98..5834112024 100755 --- a/zerver/lib/slack_data_to_zulip_data.py +++ b/zerver/lib/slack_data_to_zulip_data.py @@ -829,6 +829,10 @@ def do_convert_data(slack_zip_file: str, output_dir: str, token: str, threads: i slack_data_dir, user_list, realm_id, added_users, added_recipient, added_channels, realm, realm['zerver_realmemoji'], domain_name) + # Move zerver_reactions to realm.json file + realm['zerver_reaction'] = message_json['zerver_reaction'] + del message_json['zerver_reaction'] + emoji_folder = os.path.join(output_dir, 'emoji') os.makedirs(emoji_folder, exist_ok=True) emoji_records = process_emojis(realm['zerver_realmemoji'], emoji_folder, emoji_url_map, threads)