Class: CampaignDelivery
Overview
== Schema Information
Table name: campaign_deliveries
Database name: primary
id :integer not null, primary key
state :string
created_at :datetime not null
updated_at :datetime not null
campaign_email_id :integer
communication_recipient_id :integer
subscriber_id :integer
Indexes
index_campaign_deliveries_on_communication_recipient_id (communication_recipient_id) WHERE (communication_recipient_id IS NOT NULL) USING hash
index_campaign_deliveries_on_state (state)
index_campaign_deliveries_on_subscriber_id (subscriber_id)
unique_subscriber (campaign_email_id,subscriber_id) UNIQUE
Foreign Keys
fk_rails_... (campaign_email_id => campaign_actions.id)
fk_rails_... (communication_recipient_id => communication_recipients.id) ON DELETE => cascade
fk_rails_... (subscriber_id => subscribers.id)
Instance Attribute Summary collapse
Instance Method Summary
collapse
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Instance Attribute Details
#resend_delivery ⇒ Object
Returns the value of attribute resend_delivery.
36
37
38
|
# File 'app/models/campaign_delivery.rb', line 36
def resend_delivery
@resend_delivery
end
|
Instance Method Details
29
|
# File 'app/models/campaign_delivery.rb', line 29
belongs_to :campaign_email
|
31
|
# File 'app/models/campaign_delivery.rb', line 31
belongs_to :communication_recipient, optional: true
|
#communications ⇒ ActiveRecord::Relation<Communication>
32
|
# File 'app/models/campaign_delivery.rb', line 32
has_many :communications, as: :resource
|
#generate_communication ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'app/models/campaign_delivery.rb', line 68
def generate_communication
return if communications.any?(&:queued?)
comm = CommunicationBuilder.new(
sender_party: campaign_email.sender,
sender: campaign_email.sender_email,
resource: self,
source_id: campaign_email.source_id,
email_template_id: campaign_email.email_template_id,
recipient_party: subscriber.party,
emails: subscriber.email_address,
category: campaign_email.campaign.category
).create(send_immediately: true, skip_suppression_check: true)
update(communication_recipient_id: comm.communication_recipients.first&.id)
end
|
#has_duplicate_subscriber? ⇒ Boolean
115
116
117
118
119
120
|
# File 'app/models/campaign_delivery.rb', line 115
def has_duplicate_subscriber?
CampaignDelivery.joins(:subscriber).exists?([
'subscribers.email_address = ? and campaign_deliveries.campaign_email_id = ? and campaign_deliveries.state != ?', subscriber.email_address, campaign_email_id, 'pending'
])
end
|
#invalid_email? ⇒ Boolean
85
86
87
88
89
|
# File 'app/models/campaign_delivery.rb', line 85
def invalid_email?
return true if subscriber.email_address.blank?
!Truemail.valid?(subscriber.email_address)
end
|
#post_communication_exception_hook ⇒ Object
99
100
101
|
# File 'app/models/campaign_delivery.rb', line 99
def post_communication_exception_hook
exception
end
|
#post_communication_sent_hook ⇒ Object
91
92
93
|
# File 'app/models/campaign_delivery.rb', line 91
def post_communication_sent_hook
sent
end
|
#post_communication_suppressed_hook ⇒ Object
95
96
97
|
# File 'app/models/campaign_delivery.rb', line 95
def post_communication_suppressed_hook
suppressed
end
|
30
|
# File 'app/models/campaign_delivery.rb', line 30
belongs_to :subscriber
|
#subscriber_inactive? ⇒ Boolean
111
112
113
|
# File 'app/models/campaign_delivery.rb', line 111
def subscriber_inactive?
Party.joins('left join parties customers on customers.id = parties.customer_id').where(id: ContactPoint.emails.where(detail: subscriber.email_address).select(:party_id)).where("parties.state in ('closed','bankrupt') or parties.inactive = true or customers.state in ('closed','bankrupt')").exists?
end
|
#subscriber_on_suppression_list? ⇒ Boolean
103
104
105
|
# File 'app/models/campaign_delivery.rb', line 103
def subscriber_on_suppression_list?
EmailPreference.where(email: subscriber.email_address).where("disable_#{campaign_email.campaign.category} is true").exists?
end
|
#subscriber_previously_bounced? ⇒ Boolean
107
108
109
|
# File 'app/models/campaign_delivery.rb', line 107
def subscriber_previously_bounced?
ContactPoint.exists?(category: 'email', detail: subscriber.email_address, state: 'failed')
end
|
#to_s ⇒ Object
122
123
124
|
# File 'app/models/campaign_delivery.rb', line 122
def to_s
"Campaign: #{campaign_email&.campaign&.name || 'missing'}"
end
|