From 2bb33debfb2ada973215f4be7c829ef8a17eb13c Mon Sep 17 00:00:00 2001 From: Francis Irving Date: Wed, 14 Jul 2010 12:29:05 +0100 Subject: Make changing photo work --- app/models/user.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/user.rb b/app/models/user.rb index eb8089cf1..4cd3394b4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -275,17 +275,23 @@ class User < ActiveRecord::Base return PublicBody.extract_domain_from_email(self.email) end - # XXX profile photos not fully implemented yet + # A photograph of the user (to make it all more human) def set_profile_photo(new_profile_photo) + old_profile_photo = nil ActiveRecord::Base.transaction do if !self.profile_photo.nil? old_profile_photo = self.profile_photo self.profile_photo = nil - old_profile_photo.destroy end new_profile_photo.user = self self.profile_photo = new_profile_photo end + if !old_profile_photo.nil? + # This doesn't work in the transaction, as destroy starts + # a new transaction immediately (the database foreign key + # constraint detects it). Yuck. + old_profile_photo.destroy + end end # Used for default values of last_daily_track_email -- cgit v1.2.3