sf_migrate 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,16 @@
1
- sugar_url: <url>
2
- sugar_username: <username>
3
- sugar_password: <password>
1
+ # SalesForce API Keys (required for export)
2
+ salesforce_consumer_key : <SF_consumer_key>
3
+ salesforce_consumer_secret : <SF_consumer_secret>
4
+ salesforce_username : <SF_username>
5
+ salesforce_password : <SF_password>
4
6
 
5
- salesforce_consumer_key: <SF_consumer_key>
6
- salesforce_consumer_secret: <SF_consumer_secret>
7
- salesforce_username: <SF_username>
8
- salesforce_password: <SF_password>
7
+ # SugarCRM instance and credentials (required for import)
8
+ sugar_url : <url>
9
+ sugar_username : <username>
10
+ sugar_password : <password>
9
11
 
10
- db_type: mysql2
11
- db_user: <db_user>
12
- db_password: <db_password>
13
- db_database: <schema_name>
12
+ # Email Settings
13
+ mail_from : <email_from_address>
14
+ smtp_host : <smtp_host>
15
+ smtp_port : <smtp_port>
16
+ smtp_domain : <smtp_domain>
data/lib/import.rb CHANGED
@@ -864,7 +864,6 @@ module SalesforceMigration
864
864
  put_email_objects_into_iso_group(security_group, 'merchant', merchant)
865
865
  put_payment_methods_objects_into_iso_group(security_group, merchant)
866
866
  put_bank_accounts_into_iso_group(security_group, merchant)
867
- put_contracts_into_iso_group(security_group, merchant)
868
867
  else
869
868
  @logger.error("Couldn't find a ISO SecurityGroup for Merchant - #{merchant.name}")
870
869
  end
@@ -873,23 +872,6 @@ module SalesforceMigration
873
872
  end
874
873
  end
875
874
 
876
- def put_contracts_into_iso_group(security_group, merchant)
877
- return unless security_group and merchant
878
-
879
- @logger.info("Putting Contracts for #{merchant.name} into ISO group")
880
-
881
- case @action
882
- when "initial_run"
883
- contracts_for_merchant_id = find_related_records(@contracts, 'sf_account_id', merchant.sf_id)
884
- when "update"
885
- contracts_for_merchant_id = find_related_records('contract', 'sf_account_id', merchant.sf_id)
886
- end
887
-
888
- return if contracts_for_merchant_id.blank?
889
-
890
- associate_module_by_ids!(security_group, 'contract', contracts_for_merchant_id, false, true)
891
- end
892
-
893
875
  def put_bank_accounts_into_iso_group(security_group, merchant)
894
876
  return unless security_group and merchant
895
877
 
data/lib/mailer.rb CHANGED
@@ -6,19 +6,16 @@ module SalesforceMigration
6
6
 
7
7
  def initialize(options)
8
8
  @@config = YAML.load_file(options[:config_file])
9
- @logger = SalesforceMigration::Runner::create_logger
10
-
11
- # Ugly way to fix the bug with user_hash update
12
- # We set up a connection and update it manually.update_attributes does not work.
13
- # The issue is forwarded to sugarcrm gem crew
14
- ActiveRecord::Base.establish_connection(
15
- :adapter => @@config['db_type'],
16
- :host => "localhost",
17
- :username => @@config['db_user'],
18
- :password => @@config['db_password'],
19
- :database => @@config['db_database']
20
- )
9
+
10
+ @smtp_options = { :address => @@config['smtp_host'],
11
+ :port => @@config['smtp_port'],
12
+ :domain => @@config['smtp_domain'],
13
+ :authentication => nil,
14
+ :enable_starttls_auto => true}
15
+
16
+ SugarCRM.connect(@@config['sugar_url'], @@config['sugar_username'], @@config['sugar_password'])
21
17
 
18
+ @logger = SalesforceMigration::Runner::create_logger
22
19
  @logger.info("Starting the mailer")
23
20
  start
24
21
  @logger.info("Mailer finished")
@@ -26,8 +23,10 @@ module SalesforceMigration
26
23
 
27
24
  private
28
25
 
29
- #Search the agent portal database for all users, who are inactive
30
- #This is the script, that activates them
26
+ #
27
+ # Fetch all Inactive users from the Database and send each one an email.
28
+ # On the backend: set a hashed password and set status to 'Active'
29
+ #
31
30
  def start
32
31
  inactive_users = SugarCRM::User.find_all_by_status('Inactive')
33
32
 
@@ -35,26 +34,36 @@ module SalesforceMigration
35
34
  inactive_users.each do |user|
36
35
  @logger.info("Sending email to #{user.last_name}")
37
36
 
38
- plain_password = generate_password
39
- hash_password = Digest::MD5.hexdigest plain_password
37
+ plain_password = generate_password
38
+ md5_password = Digest::MD5.hexdigest plain_password
39
+ crypt_password = UnixCrypt::MD5.build md5_password
40
40
 
41
- sm = send_mail(user.email1, user.user_name, plain_password)
42
- if sm
43
- query = "UPDATE users SET user_hash='#{hash_password}', status='Active' WHERE id='#{user.id}'"
44
- ActiveRecord::Base.connection.execute(query);
41
+ email_is_delivered = send_mail(user.email1, user.user_name, plain_password)
42
+
43
+ if email_is_delivered
44
+ user.status = 'Active'
45
+ user.user_hash = crypt_password
46
+ user.save!
45
47
 
46
48
  @logger.info("Updated user #{user.last_name} status to active")
49
+ else
50
+ @logger.info("Couldn't send credentials for #{user.last_name} to email address #{user.email1}")
47
51
  end
48
52
  end
53
+ else
54
+ @logger.info("No unnotified users found in database")
49
55
  end
50
56
  end
51
57
 
52
- #Send the welcoming email to the user
53
- #We need the welcoming text
54
- #@param [String] the email address
58
+ # Send the welcoming email to the user
59
+ # We need the welcoming text
60
+ #
61
+ # @param [String] the email address
62
+ #
63
+ # @return [Boolean] true on successful delivery / false otherwise
55
64
  def send_mail(email, username, password)
56
65
  mail = Mail.new do
57
- from 'agentportal@emerchantpay.com'
66
+ from @@config['mail_from']
58
67
  to email
59
68
  subject 'Welcome to Emerchantpay Agent Portal'
60
69
  html_part do
@@ -62,22 +71,18 @@ module SalesforceMigration
62
71
  body Mailer::create_template(username, password)
63
72
  end
64
73
  end
65
- mail.delivery_method :smtp, {:address => "emp-ldn-exch01.emp.internal.com",
66
- :port => 25,
67
- :domain => "emp.internal.com",
68
- :authentication => nil,
69
- :enable_starttls_auto => true}
74
+ mail.delivery_method :smtp, @smtp_options
70
75
 
71
76
  if mail.deliver!
72
77
  true
73
78
  else
74
- @logger.error("Email for user #{last_name} failed!")
79
+ false
75
80
  end
76
81
  end
77
82
 
78
- # Generates the plain text password that is going to be
79
- # send to the user in the email
80
- # ActiveSupport::SecureRandom is deprecated in Rails > 3.1
83
+ #
84
+ # Generates the plain text password
85
+ #
81
86
  def generate_password
82
87
  str = SecureRandom.hex(6)
83
88
  str
@@ -85,17 +90,19 @@ module SalesforceMigration
85
90
 
86
91
  def self.create_template(username, password)
87
92
  email_template = <<-TEMPLATE
88
- Dear valued partner,<br/><br/>
93
+ Dear Valued Partner,<br/><br/>
89
94
 
90
95
  We have created an account for you to access the newly created eMerchantPay <a href="#{@@config["sugar_url"]}">Agent Portal</a><br/><br/>
91
96
 
92
97
  Your account data is:<br/><br/>
93
-
98
+
94
99
  Login: <b>#{username}</b><br/>
95
100
  Password: <b>#{password}</b><br/><br/>
96
-
101
+
102
+ Note: We've made significant upgrades to the <a href="#{@@config["sugar_url"]}">Agent Portal</a>. Please be so kind enough to use your new credentials, enhanced for security and better hashing.<br/><br/>
103
+
97
104
  Features:<br/>
98
-
105
+
99
106
  <ul>
100
107
  <li>Based on the acclaimed SugarCRM, check details <a href="http://www.sugarcrm.com">here</a></li>
101
108
  <li>Exports of merchants and various data items in different formats for further processing</li>
@@ -104,7 +111,7 @@ module SalesforceMigration
104
111
  <li>Can be accessed by mobile phone</li>
105
112
  <li>And many others...</li>
106
113
  </ul>
107
-
114
+
108
115
  <br/>
109
116
  If you have any questions, send an email to support@emerchantpay.com (also available by clicking the Support link from the main menu in the <a href="#{@@config["sugar_url"]}">Agent Portal</a>)
110
117
  <br/><br/>
@@ -115,4 +122,4 @@ module SalesforceMigration
115
122
  email_template
116
123
  end
117
124
  end
118
- end
125
+ end
data/lib/sf_migrate.rb CHANGED
@@ -7,8 +7,8 @@ require 'fileutils'
7
7
  require 'databasedotcom'
8
8
  require 'sugarcrm'
9
9
  require 'mail'
10
- require 'active_support/core_ext'
11
- require 'active_record'
10
+ require 'securerandom'
11
+ require 'unix_crypt'
12
12
  require 'fields'
13
13
  require 'export'
14
14
  require 'import'
@@ -24,7 +24,7 @@ module SalesforceMigration
24
24
  # Where do we need to store the csvs?
25
25
  options[:csv_dir] = "/var/sugarcrm/csv"
26
26
  options[:log_dir] = "/var/log/sugarcrm"
27
- options[:config_file] = File.join(File.dirname(__FILE__), "../config/credentials.yaml")
27
+ options[:config_file] = "/var/sugarcrm/credentials.yaml"
28
28
  @log_dir = options[:log_dir]
29
29
  create_logger
30
30
  optparse = OptionParser.new do |opts|
@@ -48,18 +48,18 @@ module SalesforceMigration
48
48
  options[:send_mail] = m
49
49
  end
50
50
  opts.on( '-h', '--help', 'Display this screen' ) do
51
- puts opts
52
- exit
53
- end
51
+ puts opts
52
+ exit
53
+ end
54
54
  end
55
55
  optparse.parse!
56
- begin
57
- SalesforceMigration::Export.new(options)
58
- SalesforceMigration::Import.new(options)
59
- SalesforceMigration::Mailer.new(options) if options[:send_mail]
60
- rescue => e
61
- @logger.error(e)
62
- end
56
+ begin
57
+ SalesforceMigration::Export.new(options) if options[:action]
58
+ SalesforceMigration::Import.new(options) if options[:action]
59
+ SalesforceMigration::Mailer.new(options) if options[:send_mail]
60
+ rescue => e
61
+ @logger.error(e)
62
+ end
63
63
  end
64
64
 
65
65
  def create_logger
@@ -73,7 +73,6 @@ module SalesforceMigration
73
73
  original_formatter.call("IMPORT", datetime, progname, msg)
74
74
  }
75
75
  @logger
76
- end
77
-
76
+ end
78
77
  end
79
78
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sf_migrate
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 1
10
- version: 1.2.1
9
+ - 2
10
+ version: 1.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Emil Petkov
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2014-02-04 00:00:00 Z
19
+ date: 2014-02-06 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: sugarcrm_emp
@@ -51,69 +51,53 @@ dependencies:
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
- name: activesupport
54
+ name: mail
55
55
  prerelease: false
56
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- hash: 3
61
+ hash: 29
62
62
  segments:
63
- - 3
64
63
  - 2
65
- - 6
66
- version: 3.2.6
64
+ - 5
65
+ - 3
66
+ version: 2.5.3
67
67
  type: :runtime
68
68
  version_requirements: *id003
69
69
  - !ruby/object:Gem::Dependency
70
- name: activerecord
70
+ name: roo
71
71
  prerelease: false
72
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- hash: 21
77
+ hash: 59
78
78
  segments:
79
- - 3
79
+ - 1
80
+ - 10
80
81
  - 2
81
- - 13
82
- version: 3.2.13
82
+ version: 1.10.2
83
83
  type: :runtime
84
84
  version_requirements: *id004
85
85
  - !ruby/object:Gem::Dependency
86
- name: mail
86
+ name: unix_crypt
87
87
  prerelease: false
88
88
  requirement: &id005 !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- hash: 29
93
+ hash: 27
94
94
  segments:
95
- - 2
96
- - 5
95
+ - 1
97
96
  - 3
98
- version: 2.5.3
97
+ - 0
98
+ version: 1.3.0
99
99
  type: :runtime
100
100
  version_requirements: *id005
101
- - !ruby/object:Gem::Dependency
102
- name: roo
103
- prerelease: false
104
- requirement: &id006 !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- hash: 59
110
- segments:
111
- - 1
112
- - 10
113
- - 2
114
- version: 1.10.2
115
- type: :runtime
116
- version_requirements: *id006
117
101
  description: SalesForce to SugarCRM migration tool
118
102
  email:
119
103
  - p.manchev@emerchantpay.com