From aed683390cd0ef9e2d804b46063c9344dcefd31c Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Thu, 25 Apr 2019 02:06:03 +0530 Subject: [PATCH] FIX: Don't treat 'upload_patterns' as constant to make the rake task compatible with multisite --- Gemfile.lock | 2 +- lib/tasks/posts.rake | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a783adf0800..c3d07af8755 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -570,4 +570,4 @@ DEPENDENCIES webpush BUNDLED WITH - 1.17.3 + 2.0.1 diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake index dfca963a88e..0bde9b56ff9 100644 --- a/lib/tasks/posts.rake +++ b/lib/tasks/posts.rake @@ -390,12 +390,6 @@ task 'posts:reorder_posts', [:topic_id] => [:environment] do |_, args| puts "", "Done.", "" end -UPLOAD_PATTERNS ||= [ - /\/uploads\/#{RailsMultisite::ConnectionManagement.current_db}\//, - /\/original\//, - /\/optimized\// -].freeze - def get_missing_uploads PostCustomField.where(name: Post::MISSING_UPLOADS) end @@ -403,6 +397,12 @@ end desc 'Finds missing post upload records from cooked HTML content' task 'posts:missing_uploads' => :environment do get_missing_uploads.delete_all + + upload_patterns = [ + /\/uploads\/#{RailsMultisite::ConnectionManagement.current_db}\//, + /\/original\//, + /\/optimized\// + ] missing_uploads = [] old_scheme_upload_count = 0 count = 0 @@ -416,7 +416,7 @@ task 'posts:missing_uploads' => :environment do Nokogiri::HTML::fragment(post.cooked).css("a/@href", "img/@src").each do |media| src = media.value - next if src.blank? || UPLOAD_PATTERNS.none? { |pattern| src =~ pattern } + next if src.blank? || upload_patterns.none? { |pattern| src =~ pattern } src = "#{SiteSetting.force_https ? "https" : "http"}:#{src}" if src.start_with?("//") next unless Discourse.store.has_been_uploaded?(src) || src =~ /\A\/[^\/]/i