mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
import: Fix reaction import bug.
In 'zerver_reaction', the emoji_code should be updated with the RealmEmoji allocated id when the 'reaction_type' is 'realm_emoji'. Hence we add an extra field 'reaction_field' in 're_map_foreign_keys', to process the above mentioned condition.
This commit is contained in:
@@ -141,7 +141,8 @@ def re_map_foreign_keys(data: TableData,
|
||||
related_table: TableName,
|
||||
verbose: bool=False,
|
||||
id_field: bool=False,
|
||||
recipient_field: bool=False) -> None:
|
||||
recipient_field: bool=False,
|
||||
reaction_field: bool=False) -> None:
|
||||
"""
|
||||
This is a wrapper function for all the realm data tables
|
||||
and only avatar and attachment records need to be passed through the internal function
|
||||
@@ -149,7 +150,7 @@ def re_map_foreign_keys(data: TableData,
|
||||
and List[Record] corresponding to the avatar and attachment records)
|
||||
"""
|
||||
re_map_foreign_keys_internal(data[table], table, field_name, related_table, verbose, id_field,
|
||||
recipient_field)
|
||||
recipient_field, reaction_field)
|
||||
|
||||
def re_map_foreign_keys_internal(data_table: List[Record],
|
||||
table: TableName,
|
||||
@@ -157,7 +158,8 @@ def re_map_foreign_keys_internal(data_table: List[Record],
|
||||
related_table: TableName,
|
||||
verbose: bool=False,
|
||||
id_field: bool=False,
|
||||
recipient_field: bool=False) -> None:
|
||||
recipient_field: bool=False,
|
||||
reaction_field: bool=False) -> None:
|
||||
'''
|
||||
We occasionally need to assign new ids to rows during the
|
||||
import/export process, to accommodate things like existing rows
|
||||
@@ -177,6 +179,11 @@ def re_map_foreign_keys_internal(data_table: List[Record],
|
||||
else:
|
||||
continue
|
||||
old_id = item[field_name]
|
||||
if reaction_field:
|
||||
if item['reaction_type'] == Reaction.REALM_EMOJI:
|
||||
old_id = int(old_id)
|
||||
else:
|
||||
continue
|
||||
if old_id in lookup_table:
|
||||
new_id = lookup_table[old_id]
|
||||
if verbose:
|
||||
@@ -190,7 +197,10 @@ def re_map_foreign_keys_internal(data_table: List[Record],
|
||||
item[field_name + "_id"] = new_id
|
||||
del item[field_name]
|
||||
else:
|
||||
item[field_name] = new_id
|
||||
if reaction_field:
|
||||
item[field_name] = str(new_id)
|
||||
else:
|
||||
item[field_name] = new_id
|
||||
|
||||
def fix_bitfield_keys(data: TableData, table: TableName, field_name: Field) -> None:
|
||||
for item in data[table]:
|
||||
@@ -539,18 +549,12 @@ 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')
|
||||
re_map_foreign_keys(data, 'zerver_reaction', 'message', related_table="message")
|
||||
re_map_foreign_keys(data, 'zerver_reaction', 'user_profile', related_table="user_profile")
|
||||
re_map_foreign_keys(data, 'zerver_reaction', 'emoji_code', related_table="realmemoji", id_field=True,
|
||||
reaction_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.
|
||||
|
||||
Reference in New Issue
Block a user