diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 5abce9ee032abb96b6b2a55ad666a5ac2310ff8e..00dd5e109a7c5c512a2bc6c3546bdf4ef546c60a 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -3,16 +3,16 @@ class Notifier < ActionMailer::Base helper :notifier helper :people - def self.admin(string, recipients, opts = {}) + def self.admin(string, recipients, opts = {}, subject=nil) mails = [] recipients.each do |rec| - mail = single_admin(string, rec, opts.dup) + mail = single_admin(string, rec, opts.dup, subject) mails << mail end mails end - def single_admin(string, recipient, opts={}) + def single_admin(string, recipient, opts={}, subject=nil) @receiver = recipient @string = string.html_safe @@ -22,13 +22,15 @@ class Notifier < ActionMailer::Base } end + unless subject + subject = I18n.t('notifier.single_admin.subject') + end + default_opts = {:to => @receiver.email, :from => AppConfig.mail.sender_address, - :subject => I18n.t('notifier.single_admin.subject'), :host => AppConfig.pod_uri.host} + :subject => subject, :host => AppConfig.pod_uri.host} default_opts.merge!(opts) - - mail(default_opts) do |format| format.text format.html diff --git a/lib/tasks/podmin.rake b/lib/tasks/podmin.rake index f48f042a3dbe792e31f3c6a581d6894b5646b682..547db8722b1d21243b4d9e03c0d0fc1543917cf1 100644 --- a/lib/tasks/podmin.rake +++ b/lib/tasks/podmin.rake @@ -1,17 +1,10 @@ namespace :podmin do - desc <<DESC - Send an email to users as admin. - Parameters - users def - "all", "active_yearly", "active_monthly" or "active_halfyear" - msg_path - path to a file that contains the HTML message to send -DESC - task :admin_mail, [:users_def, :msg_path] => :environment do |t, args| + desc "Send an email to users as admin" + task :admin_mail, [:users_def, :msg_path, :subject] => :environment do |t, args| if args[:users_def] == 'all' # to all except deleted and deactivated, of course - users = User.where(locked_at: nil) + users = User.where("locked_at is null and username is not null") elsif args[:users_def] == 'active_yearly' users = User.yearly_actives elsif args[:users_def] == 'active_monthly' @@ -19,11 +12,17 @@ DESC elsif args[:users_def] == 'active_halfyear' users = User.halfyear_actives end - file = File.open(args[:msg_path]) - msg = file.read - file.close - mails = Notifier.admin(msg.html_safe, users) - mails.each(&:deliver) + msg = File.read(args[:msg_path]) + mails = Notifier.admin(msg.html_safe, users, :subject => args[:subject]) + count = 0 + mails.each do |mail| + mail.deliver + count += 1 + if count % 100 == 0 + puts "#{count} out of #{mails.count} delivered" + end + end + puts "#{count} out of #{mails.count} delivered" end end \ No newline at end of file