Commit 99bfd1fb by jyurek

Ironed out the refresh task clobbering problem.

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@217 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent c8ad2e9c
...@@ -346,9 +346,11 @@ module Thoughtbot #:nodoc: ...@@ -346,9 +346,11 @@ module Thoughtbot #:nodoc:
return if attachment[:files].blank? return if attachment[:files].blank?
ensure_directories_for attachment ensure_directories_for attachment
attachment[:files].each do |style, atch| attachment[:files].each do |style, atch|
atch.rewind
data = atch.read
File.open( path_for(attachment, style), "w" ) do |file| File.open( path_for(attachment, style), "w" ) do |file|
atch.rewind file.rewind
file.write(atch.read) file.write(data)
end end
end end
attachment[:files] = nil attachment[:files] = nil
...@@ -367,6 +369,8 @@ module Thoughtbot #:nodoc: ...@@ -367,6 +369,8 @@ module Thoughtbot #:nodoc:
end end
def make_thumbnails attachment def make_thumbnails attachment
attachment[:files] ||= {}
attachment[:files][:original] ||= File.new( path_for(attachment, :original) )
attachment[:thumbnails].each do |style, geometry| attachment[:thumbnails].each do |style, geometry|
begin begin
attachment[:files][style] = make_thumbnail(attachment, attachment[:files][:original], geometry) attachment[:files][style] = make_thumbnail(attachment, attachment[:files][:original], geometry)
...@@ -451,6 +455,7 @@ module Thoughtbot #:nodoc: ...@@ -451,6 +455,7 @@ module Thoughtbot #:nodoc:
data.content_type = uri.content_type data.content_type = uri.content_type
data data
rescue OpenURI::HTTPError => e rescue OpenURI::HTTPError => e
self.errors.add_to_base("The file at #{uri.to_s} could not be found.")
$stderr.puts "#{e.message}: #{uri.to_s}" $stderr.puts "#{e.message}: #{uri.to_s}"
return nil return nil
end end
...@@ -487,7 +492,12 @@ module Thoughtbot #:nodoc: ...@@ -487,7 +492,12 @@ module Thoughtbot #:nodoc:
# Returns the file's normal name. # Returns the file's normal name.
def original_filename def original_filename
self.path @original_filename ||= self.path
end
# In case we need to override the name, like in the case of refreshing.
def original_filename= name
@original_filename = name
end end
# Returns the size of the file. # Returns the size of the file.
......
require 'environment'
def obtain_class def obtain_class
class_name = ENV['CLASS'] || ENV['class'] class_name = ENV['CLASS'] || ENV['class']
@klass = eval(class_name) @klass = eval(class_name)
...@@ -22,9 +24,12 @@ namespace :paperclip do ...@@ -22,9 +24,12 @@ namespace :paperclip do
puts "Regenerating thumbnails for #{instances.length} instances:" puts "Regenerating thumbnails for #{instances.length} instances:"
instances.each do |instance| instances.each do |instance|
names.each do |name| names.each do |name|
original_file = instance.send("#{name}_file_name", :original) # original_file = instance.send("#{name}_file_name", :original)
next if original_file.blank? # next if original_file.blank?
instance.send("#{name}=", File.new(original_file)) # original_name = instance["#{name}_file_name"]
# file = File.new(original_file)
# file.original_filename = original_name
# instance.send("#{name}=", file)
instance.send("process_#{name}_thumbnails") instance.send("process_#{name}_thumbnails")
end end
print instance.save ? "." : "x"; $stdout.flush print instance.save ? "." : "x"; $stdout.flush
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment