Sha256: 028df064d5b42df711e1d3d92db420f25e9dfe791dadb8a8ddab1694aa72cb52

Contents?: true

Size: 668 Bytes

Versions: 6

Compression:

Stored size: 668 Bytes

Contents

module Cms
  class EmailMessage < ActiveRecord::Base

    scope :undelivered, :conditions => "delivered_at is null"
    validates_presence_of :recipients
    after_create :deliver_now

    def delivered?
      !!delivered_at
    end

    def self.deliver!
      # Send all messages, 100 at a time
      undelivered.all(:limit => 100).each do |m|
        m.deliver!
      end
    end

    #TODO: Take this out when we have an email queue processor
    def deliver_now
      deliver!
    end

    def deliver!
      return false if delivered?
      Cms::EmailMessageMailer.email_message(self).deliver
      update_attributes(:delivered_at => Time.now)
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
browsercms-3.4.2 app/models/cms/email_message.rb
browsercms-3.4.2.rc1 app/models/cms/email_message.rb
browsercms-3.4.1 app/models/cms/email_message.rb
browsercms-3.4.0 app/models/cms/email_message.rb
browsercms-3.4.0.rc2 app/models/cms/email_message.rb
browsercms-3.4.0.rc1 app/models/cms/email_message.rb