I eventually managed to get the time to put this one together, rake
script below...
#(run => ''rake images:[task]'' or ''rake
RAILS_ENV=production
images:[task]'')
namespace :images do
desc "list images"
task(:list => :environment) do
# list all images
@photos = Image.find(:all, :conditions => [''parent_id is
null''])
@photos.each do |@photo|
iFile = @photo.filename #@photo.public_filename
iPath = RAILS_ROOT+"/public#{@photo.public_filename}"
iID = @photo.id.to_s
iUser_ID = @photo.user_id.to_s
iWidth = @photo.width.to_s
iHeight = @photo.height.to_s
puts ''id:''+iID+''
userid:''+iUser_ID+'' width:''+iWidth+''
height:''+iHeight+'' file:''+iFile+''
path:''+iPath
end
end
desc "add test image"
task(:add_test => :environment) do
# add image
iFile = ''test2.jpg''
iPath = ''/var/www/apps/dates/test.jpg''
@img = Image.new(:filename => iFile, :content_type =>
''image/jpeg'',
:temp_path => iPath, :user_id => 1).save!
end
desc "update test image"
task(:update_test => :environment) do
# update image
iFile = ''test2.jpg''
iPath = ''/var/www/apps/dates/test2.jpg''
@img = Image.find(''101'')
if @img.update_attributes(:filename => iFile, :content_type =>
''image/jpeg'', :temp_path => iPath, :user_id => 1)
puts iFile + '' updated!''
end
end
desc "reimage all existing images - test"
task(:reimage_test => :environment) do
# re-import all existing images - test
@photos = Image.find(:all, :conditions => [''parent_id is null
and
user_id = 2''])
@photos.each do |@photo|
iFile = @photo.filename
iPath = RAILS_ROOT+"/public#{@photo.public_filename}"
iType = @photo.content_type
iUser_ID = @photo.user_id
if @photo.update_attributes(:filename => iFile, :content_type =>
iType, :temp_path => iPath, :user_id => iUser_ID)
puts iFile + '' updated!''
end
end
end
desc "reimage all existing images"
task(:reimage => :environment) do
# re-import all existing images
@photos = Image.find(:all, :conditions => [''parent_id is
null''])
@photos.each do |@photo|
iFile = @photo.filename
iPath = RAILS_ROOT+"/public#{@photo.public_filename}"
iType = @photo.content_type
iUser_ID = @photo.user_id
if @photo.update_attributes(:filename => iFile, :content_type =>
iType, :temp_path => iPath, :user_id => iUser_ID)
puts iFile + '' updated!''
end
end
end
end
it''s a bit quick & dirty but it does the job.
all the best,
John.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---