0.48 More rewrite based on recent success with blocker.
This commit is contained in:
parent
66ff59a915
commit
edb05aa37b
30
plugin.rb
30
plugin.rb
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
# name: discourse-legacy_links
|
# name: discourse-legacy_links
|
||||||
# about: A plugin to handle legacy Gossamer Forums URLs
|
# about: A plugin to handle legacy Gossamer Forums URLs
|
||||||
# version: 0.47
|
# version: 0.48
|
||||||
# authors: saint@federated.computer
|
# authors: saint@federated.computer
|
||||||
# url: https://gitea.federated.computer/saint/discourse-legacy_links.git
|
# url: https://gitea.federated.computer/saint/discourse-legacy_links.git
|
||||||
|
|
||||||
@ -65,19 +65,33 @@ after_initialize do
|
|||||||
def find_post_by_custom_field(post_id)
|
def find_post_by_custom_field(post_id)
|
||||||
Rails.logger.info("DiscourseLegacyLinks: Searching for post with original_gossamer_id: #{post_id}")
|
Rails.logger.info("DiscourseLegacyLinks: Searching for post with original_gossamer_id: #{post_id}")
|
||||||
|
|
||||||
topic = Topic.joins(:custom_fields)
|
post_custom_field = PostCustomField.find_by(name: 'original_gossamer_id', value: post_id.to_s)
|
||||||
.where(topic_custom_fields: { name: 'original_gossamer_id', value: post_id.to_s })
|
|
||||||
.first
|
|
||||||
|
|
||||||
if topic
|
if post_custom_field
|
||||||
post = topic.posts.first
|
post = post_custom_field.post
|
||||||
Rails.logger.info("DiscourseLegacyLinks: Found topic #{topic.id}, first post id: #{post&.id || 'nil'}")
|
Rails.logger.info("DiscourseLegacyLinks: Found post with id: #{post.id}")
|
||||||
post
|
post
|
||||||
else
|
else
|
||||||
Rails.logger.warn("DiscourseLegacyLinks: No topic found with original_gossamer_id: #{post_id}")
|
Rails.logger.warn("DiscourseLegacyLinks: No post found with original_gossamer_id: #{post_id}")
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# def find_post_by_custom_field(post_id)
|
||||||
|
# Rails.logger.info("DiscourseLegacyLinks: Searching for post with original_gossamer_id: #{post_id}")
|
||||||
|
#
|
||||||
|
# topic = Topic.joins(:custom_fields)
|
||||||
|
# .where(topic_custom_fields: { name: 'original_gossamer_id', value: post_id.to_s })
|
||||||
|
# .first
|
||||||
|
#
|
||||||
|
# if topic
|
||||||
|
# post = topic.posts.first
|
||||||
|
# Rails.logger.info("DiscourseLegacyLinks: Found topic #{topic.id}, first post id: #{post&.id || 'nil'}")
|
||||||
|
# post
|
||||||
|
# else
|
||||||
|
# Rails.logger.warn("DiscourseLegacyLinks: No topic found with original_gossamer_id: #{post_id}")
|
||||||
|
# nil
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
# Redirects to the URL of the found post
|
# Redirects to the URL of the found post
|
||||||
def redirect_to_post(post)
|
def redirect_to_post(post)
|
||||||
|
Loading…
Reference in New Issue
Block a user