mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 18:58:10 +00:00
new 'uploads:gather' rake task
This commit is contained in:
parent
1f57c7a510
commit
90dfc96206
@ -1,5 +1,44 @@
|
||||
require "digest/sha1"
|
||||
|
||||
################################################################################
|
||||
# gather #
|
||||
################################################################################
|
||||
|
||||
task "uploads:gather" => :environment do
|
||||
require "db_helper"
|
||||
|
||||
public_directory = "#{Rails.root}/public"
|
||||
current_db = RailsMultisite::ConnectionManagement.current_db
|
||||
|
||||
puts "", "Gathering uploads for '#{current_db}'...", ""
|
||||
|
||||
Upload.where("url !~ '^\/uploads\/#{current_db}'").find_each do |upload|
|
||||
begin
|
||||
old_db = upload.url[/^\/uploads\/([^\/]+)\//, 1]
|
||||
from = upload.url.dup
|
||||
to = upload.url.sub("/uploads/#{old_db}/", "/uploads/#{current_db}/")
|
||||
source = "#{public_directory}#{from}"
|
||||
destination = "#{public_directory}#{to}"
|
||||
|
||||
# create destination directory
|
||||
`mkdir -p '#{File.dirname(destination)}'`
|
||||
# copy the file
|
||||
`cp --link '#{source}' '#{destination}'`
|
||||
# ensure file has been succesfuly copied over
|
||||
raise unless File.exists?(destination) && File.size(destination) > 0
|
||||
# remap links in db
|
||||
DbHelper.remap(from, to)
|
||||
rescue
|
||||
putc "!"
|
||||
else
|
||||
putc "."
|
||||
end
|
||||
end
|
||||
|
||||
puts "", "Done!"
|
||||
|
||||
end
|
||||
|
||||
################################################################################
|
||||
# backfill_shas #
|
||||
################################################################################
|
||||
|
Loading…
x
Reference in New Issue
Block a user