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
This commit is contained in:
Eric Davis 2010-10-10 21:17:15 +00:00
parent eabf1ff3e7
commit d2986eb98f
1 changed files with 16 additions and 2 deletions

View File

@ -1,8 +1,22 @@
# Patch the data from a boolean change. # Patch the data from a boolean change.
class UpdateMailNotificationValues < ActiveRecord::Migration class UpdateMailNotificationValues < ActiveRecord::Migration
def self.up def self.up
User.update_all("mail_notification = 'all'", "mail_notification = '1'") User.record_timestamps = false
User.update_all("mail_notification = 'only_my_events'", "mail_notification = '0'") 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 end
def self.down def self.down