app/models/email_campaign/campaign.rb in email_campaign-0.1.4 vs app/models/email_campaign/campaign.rb in email_campaign-0.1.5
- old
+ new
@@ -7,11 +7,12 @@
has_many :recipients, :class_name => 'EmailCampaign::Recipient', :foreign_key => 'email_campaign_id'
# new_recipients should be an Array of objects that respond to #email, #name, and #subscriber_id
# (falls back to #id if #subscriber_id doesn't exist; either way, id should be unique within campaign)
- def add_recipients(new_recipients)
+ def add_recipients(new_recipients, options = {})
+ options.stringify_keys!
new_recipients = [ new_recipients ] unless new_recipients.is_a?(Array)
processed = 0
skipped = 0
valid = 0
@@ -20,11 +21,17 @@
unsubscribed = 0
new_recipients.each do |rcpt|
subscriber_id = rcpt.respond_to?(:subscriber_id) ? rcpt.subscriber_id : rcpt.id
- if subscriber_id && recipients.where(:subscriber_id => subscriber_id).count > 0
- skipped += 1
+ if subscriber_id && r = recipients.find_by_subscriber_id(subscriber_id)
+ if options['force']
+ r.requeue
+ valid += 1
+ else
+ skipped += 1
+ end
+
next
end
processed += 1
r = recipients.build(:name => rcpt.name.strip, :email_address => rcpt.email_address.strip,