mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: 'uploads:recover_from_tombstone' rake task wasn't restoring attachments
This commit is contained in:
parent
b5da0b5796
commit
9e7d5a3cdf
@ -409,8 +409,14 @@ def recover_from_tombstone
|
|||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
original_setting = SiteSetting.max_image_size_kb
|
previous_image_size = SiteSetting.max_image_size_kb
|
||||||
SiteSetting.max_image_size_kb = 10240
|
previous_attachment_size = SiteSetting.max_attachment_size_kb
|
||||||
|
previous_extensions = SiteSetting.authorized_extensions
|
||||||
|
|
||||||
|
SiteSetting.max_image_size_kb = 10 * 1024
|
||||||
|
SiteSetting.max_attachment_size_kb = 10 * 1024
|
||||||
|
SiteSetting.authorized_extensions = "*"
|
||||||
|
|
||||||
current_db = RailsMultisite::ConnectionManagement.current_db
|
current_db = RailsMultisite::ConnectionManagement.current_db
|
||||||
public_path = Rails.root.join("public")
|
public_path = Rails.root.join("public")
|
||||||
paths = Dir.glob(File.join(public_path, 'uploads', 'tombstone', current_db, '**', '*.*'))
|
paths = Dir.glob(File.join(public_path, 'uploads', 'tombstone', current_db, '**', '*.*'))
|
||||||
@ -424,9 +430,10 @@ def recover_from_tombstone
|
|||||||
doc = Nokogiri::HTML::fragment(post.raw)
|
doc = Nokogiri::HTML::fragment(post.raw)
|
||||||
updated = false
|
updated = false
|
||||||
|
|
||||||
doc.css("img[src]").each do |img|
|
image_urls = doc.css("img[src]").map { |img| img["src"] }
|
||||||
url = img["src"]
|
attachment_urls = doc.css("a.attachment[href]").map { |a| a["href"] }
|
||||||
|
|
||||||
|
(image_urls + attachment_urls).each do |url|
|
||||||
next if !url.start_with?("/uploads/")
|
next if !url.start_with?("/uploads/")
|
||||||
next if Upload.exists?(url: url)
|
next if Upload.exists?(url: url)
|
||||||
|
|
||||||
@ -473,7 +480,9 @@ def recover_from_tombstone
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
SiteSetting.max_image_size_kb = original_setting
|
SiteSetting.max_image_size_kb = previous_image_size
|
||||||
|
SiteSetting.max_attachment_size_kb = previous_attachment_size
|
||||||
|
SiteSetting.authorized_extensions = previous_extensions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user