mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-04 12:51:41 -05:00
1574485443
This refactoring was automated using the command: bundle exec "ruby refactorings/where_dot_first_to_find_by/app.rb"
26 lines
655 B
Ruby
26 lines
655 B
Ruby
class FixLinkPostId < ActiveRecord::Migration
|
|
def up
|
|
to_remove = []
|
|
|
|
TopicLink.where('internal = TRUE AND link_post_id IS NULL').each do |tl|
|
|
|
|
begin
|
|
parsed = URI.parse(tl.url)
|
|
route = Rails.application.routes.recognize_path(parsed.path)
|
|
if route[:topic_id].present?
|
|
post = Post.find_by(topic_id: route[:topic_id], post_number: (route[:post_number] || 1))
|
|
tl.update_column(:link_post_id, post.id) if post.present?
|
|
end
|
|
|
|
rescue ActionController::RoutingError
|
|
to_remove << tl.id
|
|
end
|
|
|
|
end
|
|
|
|
TopicLink.delete_all ["id in (?)", to_remove]
|
|
end
|
|
|
|
def down
|
|
end
|
|
end
|