2016-02-12 23:52:43 +08:00
|
|
|
namespace :paperclip do
|
|
|
|
|
|
|
|
def trim_url(url)
|
|
|
|
url.split("?").first
|
|
|
|
end
|
|
|
|
|
|
|
|
def print_model_files(model, file_attr)
|
|
|
|
|
|
|
|
model.all.each do |a|
|
|
|
|
file = a.send file_attr
|
|
|
|
styles = file.options[:styles]
|
|
|
|
url = file.url
|
|
|
|
|
|
|
|
puts trim_url(url)
|
|
|
|
|
|
|
|
if styles
|
|
|
|
styles.each do |style, option|
|
|
|
|
url = file.url style
|
|
|
|
puts trim_url(url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-13 21:14:41 +08:00
|
|
|
desc 'List all paperclip files'
|
2016-02-12 23:52:43 +08:00
|
|
|
task files: :environment do
|
|
|
|
print_model_files Asset, :file
|
|
|
|
print_model_files User, :avatar
|
|
|
|
end
|
|
|
|
|
2017-01-13 21:14:41 +08:00
|
|
|
desc 'Reprocess the Assets attachents styles'
|
|
|
|
task reprocess: :environment do
|
|
|
|
error = false
|
|
|
|
Asset.find_each(batch_size: 100) do |asset|
|
|
|
|
next unless asset.is_image?
|
|
|
|
begin
|
|
|
|
asset.file.reprocess! :medium, :large
|
|
|
|
rescue
|
|
|
|
error = true
|
|
|
|
$stderr.puts "exception while processing #{asset.file_file_name} " \
|
|
|
|
"ID: #{asset.id}:"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
$stderr.puts 'All gone well! ' \
|
|
|
|
'You can grab a beer now and enjoy the evening.' unless error
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|