summaryrefslogtreecommitdiffstats
path: root/db/migrate
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-10-10 21:17:15 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-10-10 21:17:15 +0000
commitd2986eb98fa4ec163cf09c82a36fff3ca8f5f48b (patch)
tree3781839a2930d7c3d326c2a9f9765bc26bccc4c2 /db/migrate
parenteabf1ff3e703609f4ec80d98a2f56a91674fdcbc (diff)
downloadredmine-d2986eb98fa4ec163cf09c82a36fff3ca8f5f48b.tar.gz
redmine-d2986eb98fa4ec163cf09c82a36fff3ca8f5f48b.zip
Correctly update all mail_notification options. #6549
* Need to check for 't' values to support sqlite * Need to check the membership count for the 'selected' option Based on patch contributed by Felix Schäfer git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4246 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20100129193813_update_mail_notification_values.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/db/migrate/20100129193813_update_mail_notification_values.rb b/db/migrate/20100129193813_update_mail_notification_values.rb
index bfe0a5952..35ad91709 100644
--- a/db/migrate/20100129193813_update_mail_notification_values.rb
+++ b/db/migrate/20100129193813_update_mail_notification_values.rb
@@ -1,8 +1,22 @@
# Patch the data from a boolean change.
class UpdateMailNotificationValues < ActiveRecord::Migration
def self.up
- User.update_all("mail_notification = 'all'", "mail_notification = '1'")
- User.update_all("mail_notification = 'only_my_events'", "mail_notification = '0'")
+ User.record_timestamps = false
+ User.all.each do |u|
+ u.mail_notification = if u.mail_notification =~ /\A(1|t)\z/
+ # User set for all email (t is for sqlite)
+ 'all'
+ else
+ # User wants to recieve notifications on specific projects?
+ if u.memberships.count(:conditions => {:mail_notification => true}) > 0
+ 'selected'
+ else
+ 'only_my_events'
+ end
+ end
+ u.save!
+ end
+ User.record_timestamps = true
end
def self.down