From 7477a22421196a00f9d446fc6db7f035f6e3c2c7 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Sun, 19 Dec 2010 22:46:41 -0800 Subject: [PATCH] safeguard on absolutify rake task --- lib/tasks/migrations.rake | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/tasks/migrations.rake b/lib/tasks/migrations.rake index a0056498e..5c1b04476 100644 --- a/lib/tasks/migrations.rake +++ b/lib/tasks/migrations.rake @@ -39,22 +39,24 @@ namespace :migrations do require File.join(Rails.root,"config/environment") Photo.all.each do |photo| - # extract root - pod_url = photo.person.url - pod_url.chop! if pod_url[-1,1] == '/' + unless photo.remote_photo_path + # extract root + pod_url = photo.person.url + pod_url.chop! if pod_url[-1,1] == '/' - if photo.image.url - remote_path = "#{pod_url}#{photo.image.url}" - else - remote_path = "#{pod_url}#{photo.remote_photo_path}/#{photo.remote_photo_name}" + if photo.image.url + remote_path = "#{pod_url}#{photo.image.url}" + else + remote_path = "#{pod_url}#{photo.remote_photo_path}/#{photo.remote_photo_name}" + end + + # get path/filename + name_start = remote_path.rindex '/' + photo.remote_photo_path = "#{remote_path.slice(0, name_start)}/" + photo.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length) + + photo.save! end - - # get path/filename - name_start = remote_path.rindex '/' - photo.remote_photo_path = "#{remote_path.slice(0, name_start)}/" - photo.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length) - - photo.save! end end end