FIX: handle missing parent category when exporting user archive
https://meta.discourse.org/t/download-my-posts-failed/67613?u=techapj
This commit is contained in:
parent
bf2c35aa99
commit
e993d53260
|
@ -218,13 +218,15 @@ module Jobs
|
||||||
topic_data = Topic.with_deleted.find_by(id: user_archive['topic_id']) if topic_data.nil?
|
topic_data = Topic.with_deleted.find_by(id: user_archive['topic_id']) if topic_data.nil?
|
||||||
return user_archive_array if topic_data.nil?
|
return user_archive_array if topic_data.nil?
|
||||||
category = topic_data.category
|
category = topic_data.category
|
||||||
sub_category = "-"
|
sub_category_name = "-"
|
||||||
if category
|
if category
|
||||||
category_name = category.name
|
category_name = category.name
|
||||||
if !category.parent_category_id.nil?
|
if category.parent_category_id.present?
|
||||||
# sub category
|
# sub category
|
||||||
category_name = Category.find_by(id: category.parent_category_id).name
|
if parent_category = Category.find_by(id: category.parent_category_id)
|
||||||
sub_category = category.name
|
category_name = parent_category.name
|
||||||
|
sub_category_name = category.name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# PM
|
# PM
|
||||||
|
@ -233,7 +235,7 @@ module Jobs
|
||||||
is_pm = topic_data.archetype == "private_message" ? I18n.t("csv_export.boolean_yes") : I18n.t("csv_export.boolean_no")
|
is_pm = topic_data.archetype == "private_message" ? I18n.t("csv_export.boolean_yes") : I18n.t("csv_export.boolean_no")
|
||||||
url = "#{Discourse.base_url}/t/#{topic_data.slug}/#{topic_data.id}/#{user_archive['post_number']}"
|
url = "#{Discourse.base_url}/t/#{topic_data.slug}/#{topic_data.id}/#{user_archive['post_number']}"
|
||||||
|
|
||||||
topic_hash = { "post" => user_archive['raw'], "topic_title" => topic_data.title, "category" => category_name, "sub_category" => sub_category, "is_pm" => is_pm, "url" => url }
|
topic_hash = { "post" => user_archive['raw'], "topic_title" => topic_data.title, "category" => category_name, "sub_category" => sub_category_name, "is_pm" => is_pm, "url" => url }
|
||||||
user_archive.merge!(topic_hash)
|
user_archive.merge!(topic_hash)
|
||||||
|
|
||||||
HEADER_ATTRS_FOR['user_archive'].each do |attr|
|
HEADER_ATTRS_FOR['user_archive'].each do |attr|
|
||||||
|
|
Loading…
Reference in New Issue