mail_manager 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.DS_Store +0 -0
- data/.gitignore +20 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +27 -0
- data/Guardfile +24 -0
- data/LICENSE.txt +22 -0
- data/MIT-LICENSE +20 -0
- data/Manifest.txt +141 -0
- data/Procfile +4 -0
- data/README +243 -0
- data/README.md +29 -0
- data/README.rdoc +3 -0
- data/Rakefile +33 -0
- data/app/.DS_Store +0 -0
- data/app/assets/javascripts/mail_manager/application.js +15 -0
- data/app/assets/stylesheets/mail_manager/application.css +13 -0
- data/app/controllers/mail_manager/application_controller.rb +4 -0
- data/app/controllers/mail_manager/base_controller.rb +22 -0
- data/app/controllers/mail_manager/bounces_controller.rb +32 -0
- data/app/controllers/mail_manager/contacts_controller.rb +75 -0
- data/app/controllers/mail_manager/mailing_lists_controller.rb +49 -0
- data/app/controllers/mail_manager/mailings_controller.rb +102 -0
- data/app/controllers/mail_manager/messages_controller.rb +30 -0
- data/app/controllers/mail_manager/subscriptions_controller.rb +104 -0
- data/app/helpers/mail_manager/application_helper.rb +4 -0
- data/app/helpers/mail_manager/subscriptions_helper.rb +8 -0
- data/app/models/.DS_Store +0 -0
- data/app/models/mail_manager.rb +12 -0
- data/app/models/mail_manager/bounce.rb +133 -0
- data/app/models/mail_manager/contact.rb +91 -0
- data/app/models/mail_manager/contactable_registry.rb +190 -0
- data/app/models/mail_manager/mailable_registry.rb +127 -0
- data/app/models/mail_manager/mailer.rb +267 -0
- data/app/models/mail_manager/mailing.rb +266 -0
- data/app/models/mail_manager/mailing_list.rb +36 -0
- data/app/models/mail_manager/message.rb +127 -0
- data/app/models/mail_manager/subscription.rb +126 -0
- data/app/models/mail_manager/test_message.rb +175 -0
- data/app/models/status_history.rb +60 -0
- data/app/views/layouts/mail_manager/application.html.erb +14 -0
- data/app/views/mail_manager/bounces/_email_parts.html.erb +30 -0
- data/app/views/mail_manager/bounces/index.html.erb +32 -0
- data/app/views/mail_manager/bounces/show.html.erb +38 -0
- data/app/views/mail_manager/contacts/_form.html.erb +27 -0
- data/app/views/mail_manager/contacts/double_opt_in.html.erb +1 -0
- data/app/views/mail_manager/contacts/edit.html.erb +12 -0
- data/app/views/mail_manager/contacts/index.html.erb +86 -0
- data/app/views/mail_manager/contacts/new.html.erb +9 -0
- data/app/views/mail_manager/contacts/show.html.erb +22 -0
- data/app/views/mail_manager/contacts/subscribe.html.erb +2 -0
- data/app/views/mail_manager/contacts/thank_you.html.erb +12 -0
- data/app/views/mail_manager/help/_available_email_substitutions.html.erb +5 -0
- data/app/views/mail_manager/mailer/double_opt_in.erb +6 -0
- data/app/views/mail_manager/mailer/unsubscribed.erb +5 -0
- data/app/views/mail_manager/mailer/unsubscribed.html.erb +5 -0
- data/app/views/mail_manager/mailing_lists/_form.html.erb +20 -0
- data/app/views/mail_manager/mailing_lists/edit.html.erb +13 -0
- data/app/views/mail_manager/mailing_lists/index.html.erb +39 -0
- data/app/views/mail_manager/mailing_lists/new.html.erb +9 -0
- data/app/views/mail_manager/mailing_lists/show.html.erb +13 -0
- data/app/views/mail_manager/mailings/_form.html.erb +81 -0
- data/app/views/mail_manager/mailings/edit.html.erb +12 -0
- data/app/views/mail_manager/mailings/index.html.erb +52 -0
- data/app/views/mail_manager/mailings/new.html.erb +9 -0
- data/app/views/mail_manager/mailings/show.html.erb +28 -0
- data/app/views/mail_manager/mailings/test.html.erb +12 -0
- data/app/views/mail_manager/messages/index.html.erb +37 -0
- data/app/views/mail_manager/subscriptions/_form.html.erb +37 -0
- data/app/views/mail_manager/subscriptions/_subscriptions.html.erb +13 -0
- data/app/views/mail_manager/subscriptions/edit.html.erb +11 -0
- data/app/views/mail_manager/subscriptions/index.html.erb +32 -0
- data/app/views/mail_manager/subscriptions/new.html.erb +9 -0
- data/app/views/mail_manager/subscriptions/show.html.erb +8 -0
- data/app/views/mail_manager/subscriptions/unsubscribe.html.erb +2 -0
- data/app/views/mail_manager/subscriptions/unsubscribe_by_email_address.html.erb +13 -0
- data/config/daemons.yml +5 -0
- data/config/routes.rb +43 -0
- data/db/migrate/001_mail_mgr_initial.rb +84 -0
- data/db/migrate/002_mail_mgr_create_contact.rb +60 -0
- data/db/migrate/003_mail_mgr_test_message.rb +23 -0
- data/db/migrate/004_add_deleted_at_to_mailing_lists.rb +15 -0
- data/db/migrate/005_contacts_deleted_at.rb +15 -0
- data/db/migrate/006_mail_mgr_mailing_list_add_defaults_to_active.rb +15 -0
- data/db/migrate/007_mail_mgr_message_add_from_email_address.rb +15 -0
- data/db/mlm_migrate/001_mlm_initial.rb +67 -0
- data/db/mlm_migrate/002_mailable_as_polymorphic.rb +27 -0
- data/db/mlm_migrate/003_contact_as_polymorphic.rb +64 -0
- data/db/mlm_migrate/004_bounce_mlm_mailing_id.rb +26 -0
- data/db/mlm_migrate/005_mlm_to_mail_mgr_scoped.rb +29 -0
- data/engine_plan.rb +13 -0
- data/features/bounce_management.feature +0 -0
- data/features/contact_management.feature +24 -0
- data/features/mailable.feature +23 -0
- data/features/mailing_management.feature +78 -0
- data/features/message.feature +11 -0
- data/features/step_definitions/email_steps.rb +50 -0
- data/features/step_definitions/mlm_steps.rb +11 -0
- data/features/step_definitions/pickle_steps.rb +41 -0
- data/features/step_definitions/webrat_steps.rb +115 -0
- data/features/subscription_management.feature +17 -0
- data/features/support/env.rb +31 -0
- data/features/support/paths.rb +44 -0
- data/lib/daemons/mail_manager.rb +38 -0
- data/lib/daemons/mail_manager_ctl +15 -0
- data/lib/deleteable.rb +50 -0
- data/lib/lock.rb +36 -0
- data/lib/mail_manager.rb +5 -0
- data/lib/mail_manager/config.rb +50 -0
- data/lib/mail_manager/engine.rb +43 -0
- data/lib/mail_manager/version.rb +3 -0
- data/lib/tasks/mail_manager.rake +143 -0
- data/lib/tasks/mail_manager_tasks.rake +4 -0
- data/lib/tasks/rspec.rake +165 -0
- data/lib/workers/mail_manager/bounce_job.rb +52 -0
- data/lib/workers/mail_manager/mailing_job.rb +30 -0
- data/lib/workers/mail_manager/message_job.rb +38 -0
- data/lib/workers/mail_manager/test_message_job.rb +37 -0
- data/mail_manager.gemspec +29 -0
- data/script/rails +8 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/test_app/README.rdoc +261 -0
- data/spec/test_app/Rakefile +7 -0
- data/spec/test_app/app/assets/javascripts/application.js +15 -0
- data/spec/test_app/app/assets/javascripts/users.js +2 -0
- data/spec/test_app/app/assets/stylesheets/application.css +13 -0
- data/spec/test_app/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/test_app/app/assets/stylesheets/users.css +4 -0
- data/spec/test_app/app/controllers/application_controller.rb +3 -0
- data/spec/test_app/app/controllers/users_controller.rb +83 -0
- data/spec/test_app/app/helpers/application_helper.rb +2 -0
- data/spec/test_app/app/helpers/users_helper.rb +2 -0
- data/spec/test_app/app/models/user.rb +13 -0
- data/spec/test_app/app/views/layouts/application.html.erb +14 -0
- data/spec/test_app/app/views/users/_form.html.erb +33 -0
- data/spec/test_app/app/views/users/edit.html.erb +6 -0
- data/spec/test_app/app/views/users/index.html.erb +29 -0
- data/spec/test_app/app/views/users/new.html.erb +5 -0
- data/spec/test_app/app/views/users/show.html.erb +25 -0
- data/spec/test_app/config.ru +4 -0
- data/spec/test_app/config/application.rb +65 -0
- data/spec/test_app/config/boot.rb +10 -0
- data/spec/test_app/config/database.yml +25 -0
- data/spec/test_app/config/environment.rb +14 -0
- data/spec/test_app/config/environments/development.rb +37 -0
- data/spec/test_app/config/environments/production.rb +67 -0
- data/spec/test_app/config/environments/test.rb +37 -0
- data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_app/config/initializers/inflections.rb +15 -0
- data/spec/test_app/config/initializers/mime_types.rb +5 -0
- data/spec/test_app/config/initializers/secret_token.rb +7 -0
- data/spec/test_app/config/initializers/session_store.rb +8 -0
- data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/test_app/config/locales/en.yml +5 -0
- data/spec/test_app/config/lockable.yml +3 -0
- data/spec/test_app/config/mail_manager.yml +21 -0
- data/spec/test_app/config/routes.rb +7 -0
- data/spec/test_app/db/migrate/20131217101010_create_users.rb +13 -0
- data/spec/test_app/db/migrate/20131221064151_mail_mgr_initial.rb +84 -0
- data/spec/test_app/db/migrate/20131221064152_mail_mgr_create_contact.rb +60 -0
- data/spec/test_app/db/migrate/20131221064153_mail_mgr_test_message.rb +23 -0
- data/spec/test_app/db/migrate/20131221064154_add_deleted_at_to_mailing_lists.rb +15 -0
- data/spec/test_app/db/migrate/20131221064155_contacts_deleted_at.rb +15 -0
- data/spec/test_app/db/migrate/20131221064156_mail_mgr_mailing_list_add_defaults_to_active.rb +15 -0
- data/spec/test_app/db/migrate/20131221064157_mail_mgr_message_add_from_email_address.rb +15 -0
- data/spec/test_app/db/migrate/20131221072600_create_delayed_jobs.rb +22 -0
- data/spec/test_app/db/schema.rb +131 -0
- data/spec/test_app/db/structure.sql +31 -0
- data/spec/test_app/public/404.html +26 -0
- data/spec/test_app/public/422.html +26 -0
- data/spec/test_app/public/500.html +25 -0
- data/spec/test_app/public/favicon.ico +0 -0
- data/spec/test_app/script/delayed_job +5 -0
- data/spec/test_app/script/lockable +36 -0
- data/spec/test_app/script/rails +6 -0
- data/spec/test_app/spec/controllers/users_controller_spec.rb +160 -0
- data/spec/test_app/spec/factories/mailing_lists.rb +7 -0
- data/spec/test_app/spec/factories/mailings.rb +6 -0
- data/spec/test_app/spec/factories/original_factories.rb.txt +107 -0
- data/spec/test_app/spec/factories/users.rb +10 -0
- data/spec/test_app/spec/models/mail_manager/bounce_spec.rb +17 -0
- data/spec/test_app/spec/models/mail_manager/mailing_list_spec.rb +15 -0
- data/spec/test_app/spec/models/user_spec.rb +37 -0
- data/spec/test_app/spec/requests/users_spec.rb +11 -0
- data/spec/test_app/spec/routing/users_routing_spec.rb +35 -0
- data/spec/test_app/spec/support/database_cleaner.rb +23 -0
- data/spec/test_app/spec/support/files/bad_utf8_chars.eml +32 -0
- data/spec/test_app/spec/views/users/edit.html.erb_spec.rb +24 -0
- data/spec/test_app/spec/views/users/index.html.erb_spec.rb +29 -0
- data/spec/test_app/spec/views/users/new.html.erb_spec.rb +24 -0
- data/spec/test_app/spec/views/users/show.html.erb_spec.rb +21 -0
- data/zeus.json +22 -0
- metadata +424 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
class MailMgrInitial < ActiveRecord::Migration
|
2
|
+
def self.table_prefix
|
3
|
+
MailManager.table_prefix
|
4
|
+
rescue
|
5
|
+
'mail_manager_'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.up
|
9
|
+
create_table :"#{table_prefix}mailing_lists" do |t|
|
10
|
+
t.string :name
|
11
|
+
t.text :description
|
12
|
+
t.string :status
|
13
|
+
t.datetime :status_changed_at
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
create_table :"#{table_prefix}subscriptions" do |t|
|
17
|
+
t.integer :contactable_id
|
18
|
+
t.string :contactable_type
|
19
|
+
t.string :first_name
|
20
|
+
t.string :last_name
|
21
|
+
t.string :email_address
|
22
|
+
t.integer :mailing_list_id
|
23
|
+
t.string :status
|
24
|
+
t.datetime :status_changed_at
|
25
|
+
t.integer :updated_by
|
26
|
+
t.timestamps
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table :"#{table_prefix}mailings" do |t|
|
30
|
+
t.string :subject
|
31
|
+
t.string :from_email_address
|
32
|
+
t.string :mailable_type
|
33
|
+
t.integer :mailable_id
|
34
|
+
t.string :status
|
35
|
+
t.datetime :status_changed_at
|
36
|
+
t.datetime :scheduled_at
|
37
|
+
t.boolean :include_images
|
38
|
+
t.timestamps
|
39
|
+
end
|
40
|
+
|
41
|
+
create_table :"#{table_prefix}mailing_lists_#{table_prefix}mailings", :id => false do |t|
|
42
|
+
t.integer :mailing_id
|
43
|
+
t.integer :mailing_list_id
|
44
|
+
end
|
45
|
+
create_table :"#{table_prefix}messages" do |t|
|
46
|
+
t.string :type
|
47
|
+
t.string :test_email_address
|
48
|
+
t.integer :subscription_id
|
49
|
+
t.integer :mailing_id
|
50
|
+
t.string :guid
|
51
|
+
t.string :status
|
52
|
+
t.datetime :status_changed_at
|
53
|
+
t.text :result
|
54
|
+
t.timestamps
|
55
|
+
end
|
56
|
+
create_table :"#{table_prefix}bounces" do |t|
|
57
|
+
t.integer :message_id
|
58
|
+
t.integer :mailing_id
|
59
|
+
t.string :status
|
60
|
+
t.datetime :status_changed_at
|
61
|
+
t.text :bounce_message
|
62
|
+
t.text :comments
|
63
|
+
t.timestamps
|
64
|
+
end
|
65
|
+
create_table :"#{table_prefix}mailables" do |t|
|
66
|
+
t.string :name, :null => false
|
67
|
+
t.text :email_html
|
68
|
+
t.text :email_text
|
69
|
+
t.boolean :reusable
|
70
|
+
t.integer :updated_by
|
71
|
+
t.timestamps
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.down
|
76
|
+
drop_table :"#{table_prefix}mailables"
|
77
|
+
drop_table :"#{table_prefix}bounces"
|
78
|
+
drop_table :"#{table_prefix}messages"
|
79
|
+
drop_table :"#{table_prefix}mailing_lists_#{table_prefix}mailings"
|
80
|
+
drop_table :"#{table_prefix}mailings"
|
81
|
+
drop_table :"#{table_prefix}subscriptions"
|
82
|
+
drop_table :"#{table_prefix}mailing_lists"
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class MailMgrCreateContact < ActiveRecord::Migration
|
2
|
+
def self.table_prefix
|
3
|
+
MailManager.table_prefix
|
4
|
+
rescue
|
5
|
+
'mail_manager_'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.up
|
9
|
+
create_table :"#{table_prefix}contacts" do |t|
|
10
|
+
t.integer :contactable_id
|
11
|
+
t.string :contactable_type
|
12
|
+
t.string :email_address
|
13
|
+
t.string :first_name
|
14
|
+
t.string :last_name
|
15
|
+
t.integer :upated_by
|
16
|
+
t.integer :created_by
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
add_column :"#{table_prefix}subscriptions", :contact_id, :integer
|
20
|
+
transaction do
|
21
|
+
MailManager::Subscription.all.each do |subscription|
|
22
|
+
if subscription.contactable_type.eql?('MailManager::Subscription')
|
23
|
+
contact = MailManager::Contact.
|
24
|
+
find_by_email_address_and_contactable_type_and_contactable_id(subscription.email_address,nil,nil)
|
25
|
+
else
|
26
|
+
contact = MailManager::Contact.
|
27
|
+
find_by_email_address_and_contactable_type_and_contactable_id(subscription.email_address,
|
28
|
+
subscription.contactable_type, subscription.contactable_id)
|
29
|
+
end
|
30
|
+
if contact.nil?
|
31
|
+
contact = MailManager::Contact.new(
|
32
|
+
:first_name => subscription.first_name,
|
33
|
+
:last_name => subscription.last_name,
|
34
|
+
:email_address => subscription.email_address)
|
35
|
+
contact.save!
|
36
|
+
end
|
37
|
+
unless subscription.contactable_type.eql?('MailManager::Subscription')
|
38
|
+
contact.update_attribute(:contactable_type,subscription.contactable_type)
|
39
|
+
contact.update_attribute(:contactable_id,subscription.contactable_id)
|
40
|
+
end
|
41
|
+
subscription.contact = contact
|
42
|
+
subscription.save
|
43
|
+
end
|
44
|
+
end
|
45
|
+
remove_column :"#{table_prefix}subscriptions", :first_name
|
46
|
+
remove_column :"#{table_prefix}subscriptions", :last_name
|
47
|
+
remove_column :"#{table_prefix}subscriptions", :email_address
|
48
|
+
remove_column :"#{table_prefix}subscriptions", :contactable_type
|
49
|
+
remove_column :"#{table_prefix}subscriptions", :contactable_id
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.down
|
53
|
+
drop_table :"#{table_prefix}contacts"
|
54
|
+
add_column :"#{table_prefix}subscriptions", :first_name, :string
|
55
|
+
add_column :"#{table_prefix}subscriptions", :last_name, :string
|
56
|
+
add_column :"#{table_prefix}subscriptions", :email_address, :string
|
57
|
+
add_column :"#{table_prefix}subscriptions", :contactable_type, :string
|
58
|
+
add_column :"#{table_prefix}subscriptions", :contactable_id, :integer
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class MailMgrTestMessage < ActiveRecord::Migration
|
2
|
+
def self.table_prefix
|
3
|
+
MailManager.table_prefix
|
4
|
+
rescue
|
5
|
+
'mail_manager_'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.up
|
9
|
+
change_table :"#{table_prefix}messages" do |t|
|
10
|
+
# t.string :type
|
11
|
+
# t.string :test_email_address
|
12
|
+
t.integer :contact_id
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
change_table :"#{table_prefix}messages" do |t|
|
18
|
+
# t.remove :type
|
19
|
+
# t.remove :test_email_address
|
20
|
+
t.remove :contact_id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class AddDeletedAtToMailingLists < ActiveRecord::Migration
|
2
|
+
def self.table_prefix
|
3
|
+
MailManager.table_prefix
|
4
|
+
rescue
|
5
|
+
'mail_manager_'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.up
|
9
|
+
add_column :"#{table_prefix}mailing_lists", :deleted_at, :datetime
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
remove_column :"#{table_prefix}mailing_lists", :deleted_at
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class ContactsDeletedAt < ActiveRecord::Migration
|
2
|
+
def self.table_prefix
|
3
|
+
MailManager.table_prefix
|
4
|
+
rescue
|
5
|
+
'mail_manager_'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.up
|
9
|
+
add_column :"#{table_prefix}contacts", :deleted_at, :datetime
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
remove_column :"#{table_prefix}contacts", :deleted_at
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class MailMgrMailingListAddDefaultsToActive < ActiveRecord::Migration
|
2
|
+
def self.table_prefix
|
3
|
+
MailManager.table_prefix
|
4
|
+
rescue
|
5
|
+
'mail_manager_'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.up
|
9
|
+
add_column :"#{table_prefix}mailing_lists", :defaults_to_active, :boolean
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
remove_column :"#{table_prefix}mailing_lists", :defaults_to_active
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class MailMgrMessageAddFromEmailAddress < ActiveRecord::Migration
|
2
|
+
def self.table_prefix
|
3
|
+
MailManager.table_prefix
|
4
|
+
rescue
|
5
|
+
'mail_manager_'
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.up
|
9
|
+
add_column :"#{table_prefix}messages", :from_email_address, :string
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
remove_column :"#{table_prefix}messages", :from_email_address
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class MlmInitial < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :mlm_mailing_lists do |t|
|
4
|
+
t.string :name
|
5
|
+
t.text :description
|
6
|
+
t.string :status
|
7
|
+
t.datetime :status_changed_at
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
create_table :mlm_subscriptions do |t|
|
11
|
+
t.integer :mlm_contact_id
|
12
|
+
t.integer :mlm_mailing_list_id
|
13
|
+
t.string :status
|
14
|
+
t.datetime :status_changed_at
|
15
|
+
t.integer :updated_by
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
create_table :mlm_mailings do |t|
|
19
|
+
t.string :subject
|
20
|
+
t.string :from_email_address
|
21
|
+
t.string :mailable
|
22
|
+
t.string :status
|
23
|
+
t.datetime :status_changed_at
|
24
|
+
t.datetime :scheduled_at
|
25
|
+
t.boolean :include_images
|
26
|
+
t.timestamps
|
27
|
+
end
|
28
|
+
create_table :mlm_mailing_lists_mlm_mailings, :id => false do |t|
|
29
|
+
t.integer :mlm_mailing_id
|
30
|
+
t.integer :mlm_mailing_list_id
|
31
|
+
end
|
32
|
+
create_table :mlm_messages do |t|
|
33
|
+
t.integer :mlm_contact_id
|
34
|
+
t.integer :mlm_mailing_id
|
35
|
+
t.string :guid
|
36
|
+
t.string :status
|
37
|
+
t.datetime :status_changed_at
|
38
|
+
t.text :result
|
39
|
+
t.timestamps
|
40
|
+
end
|
41
|
+
create_table :mlm_bounces do |t|
|
42
|
+
t.integer :mlm_message_id
|
43
|
+
t.string :status
|
44
|
+
t.datetime :status_changed_at
|
45
|
+
t.text :bounce_message
|
46
|
+
t.text :comments
|
47
|
+
t.timestamps
|
48
|
+
end
|
49
|
+
create_table :mlm_mailables do |t|
|
50
|
+
t.string :name, :null => false
|
51
|
+
t.text :email_html
|
52
|
+
t.text :email_text
|
53
|
+
t.boolean :reusable
|
54
|
+
t.integer :updated_by
|
55
|
+
t.timestamps
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.down
|
60
|
+
drop_table :mlm_bounces
|
61
|
+
drop_table :mlm_messages
|
62
|
+
drop_table :mlm_mailing_lists_mlm_mailings
|
63
|
+
drop_table :mlm_mailings
|
64
|
+
drop_table :mlm_subscriptions
|
65
|
+
drop_table :mlm_mailing_lists
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module LetsMigrateThis
|
2
|
+
module MigrateClassMethods
|
3
|
+
def port_to_polymorphic_association
|
4
|
+
all.each do |mailing|
|
5
|
+
parts = mailing[:mailable].split(/_/)
|
6
|
+
mailing[:mailable_id] = parts.pop
|
7
|
+
mailing[:mailable_type] = parts.join('_')
|
8
|
+
mailing.save
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
MlmMailing.extend(LetsMigrateThis::MigrateClassMethods)
|
15
|
+
|
16
|
+
class MailableAsPolymorphic < ActiveRecord::Migration
|
17
|
+
def self.up
|
18
|
+
add_column :mlm_mailings, :mailable_type, :string
|
19
|
+
add_column :mlm_mailings, :mailable_id, :integer
|
20
|
+
add_column :mlm_mailings, :mlm_mailable_id, :integer
|
21
|
+
MlmMailing.port_to_polymorphic_association
|
22
|
+
remove_column :mlm_mailings, :mailable
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.down
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
if defined? User.respond_to?(:object_id)
|
3
|
+
module LetsMigrateThisSubscription
|
4
|
+
module MigrateClassMethods
|
5
|
+
def port_to_polymorphic_association
|
6
|
+
all.each do |subscription|
|
7
|
+
next if subscription.mlm_mailing_list_id.nil?
|
8
|
+
user = User.find_by_id(subscription[:mlm_contact_id])
|
9
|
+
next if user.nil?
|
10
|
+
if user.respond_to?(:first_name) and user.respond_to?(:last_name)
|
11
|
+
subscription.first_name = user.first_name
|
12
|
+
subscription.last_name = user.last_name
|
13
|
+
elsif user.full_name. =~ /^[^\s]+\s*,/
|
14
|
+
name_parts = user.full_name.strip.split(/\s+/)
|
15
|
+
subscription.last_name = name_parts.shift.gsub(/,$/,'')
|
16
|
+
subscription.first_name = name_parts.join(' ').gsub(/^,/,'')
|
17
|
+
else
|
18
|
+
name_parts = user.full_name.strip.split(/\s+/)
|
19
|
+
subscription.last_name = name_parts.pop
|
20
|
+
subscription.first_name = name_parts.join(' ')
|
21
|
+
end
|
22
|
+
subscription.email_address = user.email
|
23
|
+
subscription[:contactable_id] = subscription[:mlm_contact_id]
|
24
|
+
subscription[:contactable_type] = 'User'
|
25
|
+
subscription.save
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
MlmSubscription.extend(LetsMigrateThisSubscription::MigrateClassMethods)
|
31
|
+
|
32
|
+
module LetsMigrateThisMessage
|
33
|
+
module MigrateClassMethods
|
34
|
+
def mlm_contact_to_mlm_subscription
|
35
|
+
all.each do |message|
|
36
|
+
message.mlm_subscription = MlmSubscription.
|
37
|
+
find_by_contactable_id_and_contactable_type(message.mlm_contact_id,'User')
|
38
|
+
message.save
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
MlmMessage.extend(LetsMigrateThisMessage::MigrateClassMethods)
|
44
|
+
end
|
45
|
+
MlmMessage.send(:belongs_to, :mlm_subscription)
|
46
|
+
class ContactAsPolymorphic < ActiveRecord::Migration
|
47
|
+
def self.up
|
48
|
+
add_column :mlm_subscriptions, :contactable_type, :string
|
49
|
+
add_column :mlm_subscriptions, :contactable_id, :integer
|
50
|
+
add_column :mlm_subscriptions, :first_name, :string
|
51
|
+
add_column :mlm_subscriptions, :last_name, :string
|
52
|
+
add_column :mlm_subscriptions, :email_address, :string
|
53
|
+
puts "Importing Contact Data into Subscriptions"
|
54
|
+
MlmSubscription.port_to_polymorphic_association if defined? User.respond_to?(:object_id)
|
55
|
+
remove_column :mlm_subscriptions, :mlm_contact_id
|
56
|
+
add_column :mlm_messages, :mlm_subscription_id, :integer
|
57
|
+
puts "Updating Messages to connect to subscriptions instead of MlmContacts"
|
58
|
+
MlmMessage.mlm_contact_to_mlm_subscription if defined? User.respond_to?(:object_id)
|
59
|
+
remove_column :mlm_messages, :mlm_contact_id
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.down
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module LetsMigrateThisBounce
|
2
|
+
module MigrateClassMethods
|
3
|
+
def set_mlm_mailing_id
|
4
|
+
find(:all, :conditions => ["mlm_message_id is not null"]).each do |bounce|
|
5
|
+
unless bounce.mlm_message.nil?
|
6
|
+
bounce.mlm_mailing_id = bounce.mlm_message.mlm_mailing.try(:id)
|
7
|
+
bounce.save
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
MlmBounce.send(:belongs_to, :mlm_message)
|
14
|
+
MlmBounce.extend(LetsMigrateThisBounce::MigrateClassMethods)
|
15
|
+
|
16
|
+
class BounceMlmMailingId < ActiveRecord::Migration
|
17
|
+
def self.up
|
18
|
+
add_column :mlm_bounces, :mlm_mailing_id, :integer
|
19
|
+
puts "Updating Mlm Mailing Ids"
|
20
|
+
MlmBounce.set_mlm_mailing_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.down
|
24
|
+
remove_column :mlm_bounces, :mlm_mailing_id
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class MlmToMailManagerScoped < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
rename_column :mlm_subscriptions, :mlm_mailing_list_id, :mailing_list_id
|
5
|
+
rename_column :mlm_mailing_lists_mlm_mailings, :mlm_mailing_id, :mailing_id
|
6
|
+
rename_column :mlm_mailing_lists_mlm_mailings, :mlm_mailing_list_id, :mailing_list_id
|
7
|
+
rename_column :mlm_messages, :mlm_mailing_id, :mailing_id
|
8
|
+
rename_column :mlm_bounces, :mlm_message_id, :message_id
|
9
|
+
remove_column :mlm_mailings, :mlm_mailable_id
|
10
|
+
rename_column :mlm_messages, :mlm_subscription_id, :subscription_id
|
11
|
+
rename_column :mlm_bounces, :mlm_mailing_id, :mailing_id
|
12
|
+
#this is better done with a straight query
|
13
|
+
conn = ActiveRecord::Base.connection
|
14
|
+
conn.execute("UPDATE `mlm_subscriptions`
|
15
|
+
SET contactable_type='MailManager::Subscription'
|
16
|
+
WHERE contactable_type='MlmSubscription'")
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.down
|
20
|
+
rename_column :mlm_subscriptions, :mailing_list_id, :mlm_mailing_list_id
|
21
|
+
rename_column :mlm_mailing_lists_mlm_mailings, :mailing_id, :mlm_mailing_id
|
22
|
+
rename_column :mlm_mailing_lists_mlm_mailings, :mailing_list_id, :mlm_mailing_list_id
|
23
|
+
rename_column :mlm_messages, :mailing_id, :mlm_mailing_id
|
24
|
+
rename_column :mlm_bounces, :message_id, :mlm_message_id
|
25
|
+
add_column :mlm_mailings, :mlm_mailable_id, :integer
|
26
|
+
rename_column :mlm_messages, :subscription_id, :mlm_subscription_id
|
27
|
+
rename_column :mlm_bounces, :mailing_id, :mlm_mailing_id
|
28
|
+
end
|
29
|
+
end
|