0.51 Final touches
This commit is contained in:
		
							
								
								
									
										31
									
								
								plugin.rb
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								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.50
 | 
					# version: 0.51
 | 
				
			||||||
# 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -62,11 +62,16 @@ after_initialize do
 | 
				
			|||||||
#                request.query_string.match(/post=(\d+)/)&.  ||               # Matches URLs with ?post= in query string
 | 
					#                request.query_string.match(/post=(\d+)/)&.  ||               # Matches URLs with ?post= in query string
 | 
				
			||||||
#                request.query_string.match(/parent_post_id=(\d+)/)&.  ||     # Matches URLs with ?parent_post_id= in query string
 | 
					#                request.query_string.match(/parent_post_id=(\d+)/)&.  ||     # Matches URLs with ?parent_post_id= in query string
 | 
				
			||||||
#                request.path.match(%r{/forum/.*?_P(\d+)/?})&.                # Matches URLs like /forum/..._P6751045/
 | 
					#                request.path.match(%r{/forum/.*?_P(\d+)/?})&.                # Matches URLs like /forum/..._P6751045/
 | 
				
			||||||
 | 
					#      post_id = params[:post_id].presence ||
 | 
				
			||||||
 | 
					#                request.path.match(%r{/P(\d+)(?:/|$)})&.  ||                 # Matches URLs like /P40796/ or /P40796 (no trailing slash)
 | 
				
			||||||
 | 
					#                request.path.match(%r{/forum/.*_P(\d+)(?:/|$)})&.  ||        # Matches URLs like /forum/.../P6751045/ or /forum/.../P6751045
 | 
				
			||||||
 | 
					#                request.query_string.match(/post=(\d+)/)&.  ||               # Matches URLs with ?post= in query string
 | 
				
			||||||
 | 
					#                request.query_string.match(/parent_post_id=(\d+)/)&.         # Matches URLs with ?parent_post_id= in query string
 | 
				
			||||||
      post_id = params[:post_id].presence ||
 | 
					      post_id = params[:post_id].presence ||
 | 
				
			||||||
                request.path.match(%r{/P(\d+)(?:/|$)})&.  ||                 # Matches URLs like /P40796/ or /P40796 (no trailing slash)
 | 
					                request.path.match(%r{/P(\d+)(?:/|$)})&.[](1) ||                 # Matches URLs like /P40796/ or /P40796 (no trailing slash)
 | 
				
			||||||
                request.path.match(%r{/forum/.*_P(\d+)(?:/|$)})&.  ||        # Matches URLs like /forum/.../P6751045/ or /forum/.../P6751045
 | 
					                request.path.match(%r{/forum/.*_P(\d+)(?:/|$)})&.[](1) ||        # Matches URLs like /forum/.../P6751045/ or /forum/.../P6751045
 | 
				
			||||||
                request.query_string.match(/post=(\d+)/)&.  ||               # Matches URLs with ?post= in query string
 | 
					                request.query_string.match(/post=(\d+)/)&.[](1) ||               # Matches URLs with ?post= in query string
 | 
				
			||||||
                request.query_string.match(/parent_post_id=(\d+)/)&.         # Matches URLs with ?parent_post_id= in query string
 | 
					                request.query_string.match(/parent_post_id=(\d+)/)&.[](1)        # Matches URLs with ?parent_post_id= in query string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      Rails.logger.info("DiscourseLegacyLinks: Extracted raw post_id: #{post_id || 'nil'}")
 | 
					      Rails.logger.info("DiscourseLegacyLinks: Extracted raw post_id: #{post_id || 'nil'}")
 | 
				
			||||||
      post_id.to_i if post_id
 | 
					      post_id.to_i if post_id
 | 
				
			||||||
@@ -87,22 +92,6 @@ after_initialize do
 | 
				
			|||||||
        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)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user