mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 11:22:04 +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,
|
related_table: TableName,
|
||||||
verbose: bool=False,
|
verbose: bool=False,
|
||||||
id_field: 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
|
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
|
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)
|
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,
|
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],
|
def re_map_foreign_keys_internal(data_table: List[Record],
|
||||||
table: TableName,
|
table: TableName,
|
||||||
@@ -157,7 +158,8 @@ def re_map_foreign_keys_internal(data_table: List[Record],
|
|||||||
related_table: TableName,
|
related_table: TableName,
|
||||||
verbose: bool=False,
|
verbose: bool=False,
|
||||||
id_field: 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
|
We occasionally need to assign new ids to rows during the
|
||||||
import/export process, to accommodate things like existing rows
|
import/export process, to accommodate things like existing rows
|
||||||
@@ -177,6 +179,11 @@ def re_map_foreign_keys_internal(data_table: List[Record],
|
|||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
old_id = item[field_name]
|
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:
|
if old_id in lookup_table:
|
||||||
new_id = lookup_table[old_id]
|
new_id = lookup_table[old_id]
|
||||||
if verbose:
|
if verbose:
|
||||||
@@ -190,7 +197,10 @@ def re_map_foreign_keys_internal(data_table: List[Record],
|
|||||||
item[field_name + "_id"] = new_id
|
item[field_name + "_id"] = new_id
|
||||||
del item[field_name]
|
del item[field_name]
|
||||||
else:
|
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:
|
def fix_bitfield_keys(data: TableData, table: TableName, field_name: Field) -> None:
|
||||||
for item in data[table]:
|
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 zerver_message and zerver_usermessage
|
||||||
import_message_data(import_dir)
|
import_message_data(import_dir)
|
||||||
|
|
||||||
# As the export of Reactions is not supported, Zulip exported
|
re_map_foreign_keys(data, 'zerver_reaction', 'message', related_table="message")
|
||||||
# data would not contain this field.
|
re_map_foreign_keys(data, 'zerver_reaction', 'user_profile', related_table="user_profile")
|
||||||
# However this is supported in slack importer script
|
re_map_foreign_keys(data, 'zerver_reaction', 'emoji_code', related_table="realmemoji", id_field=True,
|
||||||
if 'zerver_reaction' in data:
|
reaction_field=True)
|
||||||
re_map_foreign_keys(data, 'zerver_reaction', 'message', related_table="message")
|
update_model_ids(Reaction, data, 'zerver_reaction', 'reaction')
|
||||||
re_map_foreign_keys(data, 'zerver_reaction', 'user_profile', related_table="user_profile")
|
bulk_import_model(data, Reaction, 'zerver_reaction')
|
||||||
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.
|
# Do attachments AFTER message data is loaded.
|
||||||
# TODO: de-dup how we read these json files.
|
# TODO: de-dup how we read these json files.
|
||||||
|
|||||||
Reference in New Issue
Block a user