mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
Improve restore from tombstone rake task.
This commit is contained in:
parent
3af5b19002
commit
b62b6ba12c
1 changed files with 29 additions and 13 deletions
|
@ -403,6 +403,10 @@ def recover_from_tombstone
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
original_setting = SiteSetting.max_image_size_kb
|
||||||
|
SiteSetting.max_image_size_kb = 10240
|
||||||
|
|
||||||
public_path = Rails.root.join("public")
|
public_path = Rails.root.join("public")
|
||||||
|
|
||||||
Post.find_each do |post|
|
Post.find_each do |post|
|
||||||
|
@ -410,21 +414,33 @@ def recover_from_tombstone
|
||||||
|
|
||||||
doc.css("img[src]").each do |img|
|
doc.css("img[src]").each do |img|
|
||||||
url = img["src"]
|
url = img["src"]
|
||||||
|
|
||||||
|
next unless url =~ /^\/uploads\//
|
||||||
|
|
||||||
upload = Upload.find_by(url: url)
|
upload = Upload.find_by(url: url)
|
||||||
|
|
||||||
if !upload
|
if !upload && url
|
||||||
File.open(File.join(public_path, 'uploads', 'tombstone', url[9..-1])) do |file|
|
tombstone_path = File.join(public_path, 'uploads', 'tombstone', url.gsub(/^\/uploads\//, ""))
|
||||||
|
|
||||||
|
if File.exists?(tombstone_path)
|
||||||
|
File.open(tombstone_path) do |file|
|
||||||
new_upload = Upload.create_for(Discourse::SYSTEM_USER_ID, file, File.basename(url), File.size(file))
|
new_upload = Upload.create_for(Discourse::SYSTEM_USER_ID, file, File.basename(url), File.size(file))
|
||||||
|
|
||||||
if new_upload.persisted?
|
if new_upload.persisted?
|
||||||
putc "."
|
putc "."
|
||||||
DbHelper.remap(url, new_upload.url)
|
DbHelper.remap(url, new_upload.url)
|
||||||
else
|
else
|
||||||
puts "Failed to create upload for #{url}."
|
puts "Failed to create upload for #{url}: #{new_upload.errors.full_messages}."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "Failed to find file (#{tombstone_path}) in tombstone."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
|
SiteSetting.max_image_size_kb = original_setting
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue