sf_migrate 1.2.7 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/export.rb +62 -61
- data/lib/fields.rb +9 -9
- data/lib/import.rb +64 -53
- data/lib/mailer.rb +9 -12
- data/lib/sf_migrate.rb +24 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzAxYzI3YTAyMWJlMzlmNGEwY2M5ZDNhMGVkNjhlYmZiYjFkZmEzYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTk1OTFhZjJhMjlkNDJjY2UwN2MzZjNjYzJiMjhhZGQ1OTk2ZmI3Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzA3N2VlNWE0NDEyMTE0NmViNDM3MTU2NDVjODM3NDA5MTlkYTg5MjM4YzIx
|
10
|
+
MWViNjUwODE2YjIyYTI1ZTYzNTc1MzJjOTNhZTU2Y2FlOTZjYWZlMzRjODU0
|
11
|
+
NjU4NDdlMDk0MWM0MzI1ZmZhNzAwNWE5Yjg4ZmE2MjFhN2Y1NWM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWQ4NDlmMzQzNDA0ODNiYzc2MzQ2MDQwYzgxZTBkOWJhYzAxNjliOGNiMTMx
|
14
|
+
ZDk2OWU1Njk5ZTJjZTgxYjg0ODVkZTM5YmVkNzFiNTcyM2RkNDcxMWMxNGZj
|
15
|
+
OWY3NjI2MzUxNjEzZjk3Njk1Y2U5MzFlZjM0NDU3MTI0ZWM2MzQ=
|
data/lib/export.rb
CHANGED
@@ -6,26 +6,21 @@ module SalesforceMigration
|
|
6
6
|
#
|
7
7
|
# @param [Hash] options hash representing passed command line options
|
8
8
|
def initialize(options)
|
9
|
-
consumer_key = $credentials['salesforce_consumer_key']
|
10
|
-
consumer_secret = $credentials['salesforce_consumer_secret']
|
11
|
-
username = $credentials['salesforce_username']
|
12
|
-
password = $credentials['salesforce_password']
|
13
9
|
@csv_dir = options[:csv_dir]
|
14
10
|
@action = options[:action]
|
15
11
|
@last_modified_date = options[:last_modified_date]
|
16
|
-
|
17
|
-
@
|
18
|
-
@client
|
19
|
-
|
20
|
-
@logger.info("Authentication to SalesForce successfull")
|
12
|
+
$logger.info("Export action has started!")
|
13
|
+
@client = Databasedotcom::Client.new :client_id => $credentials['salesforce_consumer_key'], :client_secret => $credentials['salesforce_consumer_secret']
|
14
|
+
@client.authenticate :username => $credentials['salesforce_username'], :password => $credentials['salesforce_password']
|
15
|
+
$logger.info("Authentication to SalesForce successfull")
|
21
16
|
start
|
22
|
-
|
17
|
+
$logger.info("Export action completed successfully!")
|
23
18
|
end
|
24
19
|
|
25
20
|
private
|
26
21
|
def start
|
27
22
|
%w(ISOs__c Agent__c Account Acquirer__c Contract Payment_Methods__c Banks__c MerchantToAPM__c ccrmbasic__Email__c Email_Association__c User).each do |type|
|
28
|
-
|
23
|
+
$logger.info "Writing CSV for #{type}"
|
29
24
|
write_to_csv type
|
30
25
|
end
|
31
26
|
end
|
@@ -39,7 +34,7 @@ module SalesforceMigration
|
|
39
34
|
file_name = generate_name(type)
|
40
35
|
|
41
36
|
CSV.open(file_name, "wb:UTF-8") do |file|
|
42
|
-
|
37
|
+
$logger.info "Opened #{file_name} for export"
|
43
38
|
file << fields
|
44
39
|
records.each do |record|
|
45
40
|
arr = []
|
@@ -51,49 +46,6 @@ module SalesforceMigration
|
|
51
46
|
end
|
52
47
|
end
|
53
48
|
end
|
54
|
-
|
55
|
-
# In order to fix the Invalid Session Id in SugarCRM we need to remove all
|
56
|
-
# quotes from text fields, because they mess up the JSON object which comunicate with
|
57
|
-
# our SugarCRM instance.
|
58
|
-
# Note that on Mac we don`t need this method.
|
59
|
-
def remove_quotes(field)
|
60
|
-
field.gsub(/'/, "").strip if field.is_a? String
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
# Return the header fields
|
65
|
-
def return_fields(type)
|
66
|
-
return constantize "SalesforceMigration::Fields::#{type.slice(0..-4).upcase}_FIELDS" if type.end_with?("__c")
|
67
|
-
return constantize "SalesforceMigration::Fields::#{type.upcase}_FIELDS"
|
68
|
-
end
|
69
|
-
|
70
|
-
# Get all records for specific type of object
|
71
|
-
#
|
72
|
-
# @param [String] type export type name
|
73
|
-
#
|
74
|
-
# @return [Databasedotcom::Collection] the requested records
|
75
|
-
def get_records(type)
|
76
|
-
if @action == 'initial_run'
|
77
|
-
@logger.info "Getting all records from SalesForce for #{type} object"
|
78
|
-
records = get_all_sobjects(type)
|
79
|
-
else
|
80
|
-
@logger.info "Getting records for yesterday from SalesForce for #{type} object"
|
81
|
-
records = @client.materialize(type)
|
82
|
-
|
83
|
-
begin
|
84
|
-
datetime = DateTime.parse(@last_modified_date)
|
85
|
-
rescue
|
86
|
-
if defined? @last_modified_date == nil
|
87
|
-
datetime = DateTime.now - 1
|
88
|
-
else
|
89
|
-
raise ArgumentError, "Invalid Date", caller
|
90
|
-
end
|
91
|
-
end
|
92
|
-
p datetime
|
93
|
-
exit
|
94
|
-
records.query("lastmodifieddate >= #{datetime}")
|
95
|
-
end
|
96
|
-
end
|
97
49
|
|
98
50
|
# Generates a name for CSV file depending on the action
|
99
51
|
#
|
@@ -116,6 +68,20 @@ module SalesforceMigration
|
|
116
68
|
"#{dir}/#{type}_export.csv"
|
117
69
|
end
|
118
70
|
end
|
71
|
+
|
72
|
+
# In order to fix the Invalid Session Id in SugarCRM we need to remove all
|
73
|
+
# quotes from text fields, because they mess up the JSON object which comunicate with
|
74
|
+
# our SugarCRM instance.
|
75
|
+
# Note that on Mac we don`t need this method.
|
76
|
+
def remove_quotes(field)
|
77
|
+
field.gsub(/'/, "").strip if field.is_a? String
|
78
|
+
end
|
79
|
+
|
80
|
+
# Return the header fields
|
81
|
+
def return_fields(type)
|
82
|
+
return constantize "SalesforceMigration::Fields::#{type.slice(0..-4).upcase}_FIELDS" if type.end_with?("__c")
|
83
|
+
return constantize "SalesforceMigration::Fields::#{type.upcase}_FIELDS"
|
84
|
+
end
|
119
85
|
|
120
86
|
# Borrowed from activesupport/lib/active_support/inflector/methods.rb, line 212
|
121
87
|
def constantize(camel_cased_word)
|
@@ -128,6 +94,24 @@ module SalesforceMigration
|
|
128
94
|
constant
|
129
95
|
end
|
130
96
|
|
97
|
+
# Get all records for specific type of object
|
98
|
+
#
|
99
|
+
# @param [String] type export type name
|
100
|
+
#
|
101
|
+
# @return [Databasedotcom::Collection] the requested records
|
102
|
+
def get_records(type)
|
103
|
+
if @action == 'initial_run'
|
104
|
+
$logger.info "Getting all records from SalesForce for #{type} object"
|
105
|
+
else
|
106
|
+
if @last_modified_date.blank?
|
107
|
+
$logger.info "Getting records for yesterday from SalesForce for #{type} object"
|
108
|
+
else
|
109
|
+
$logger.info "Getting records from #{Date.parse(@last_modified_date)} up until now from SalesForce for #{type} object"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
get_all_sobjects(type)
|
113
|
+
end
|
114
|
+
|
131
115
|
# Get all objects of given type. Databasedotcom pulls only 250 records by query
|
132
116
|
#
|
133
117
|
# @param [String] type type of sobject
|
@@ -135,14 +119,31 @@ module SalesforceMigration
|
|
135
119
|
# @return [Array<Databasedotcom::Sobject::Sobject>] All available sobjects
|
136
120
|
# Some objects, like Merchants and Emails are exported VIA a certain criteria
|
137
121
|
def get_all_sobjects(type)
|
122
|
+
begin
|
123
|
+
datetime = DateTime.parse(@last_modified_date)
|
124
|
+
rescue
|
125
|
+
if @last_modified_date.blank?
|
126
|
+
datetime = DateTime.now - 1
|
127
|
+
else
|
128
|
+
raise ArgumentError, "Invalid Date", caller
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
138
132
|
case type
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
133
|
+
when 'Account'
|
134
|
+
records = @client.materialize(type).query("Agents__c != ''") if @action == 'initial_run'
|
135
|
+
records = @client.materialize(type).query("Agents__c != '' AND lastmodifieddate >= #{datetime}") if @action == 'update'
|
136
|
+
when 'Contract'
|
137
|
+
records = @client.materialize(type).query("Contract.Account.Agents__c != ''") if @action == 'initial_run'
|
138
|
+
records = @client.materialize(type).query("Contract.Account.Agents__c != '' AND lastmodifieddate >= #{datetime}") if @action == 'update'
|
139
|
+
when 'ccrmbasic__Email__c'
|
140
|
+
records = @client.materialize(type).query("ccrmbasic__Contact__c != ''") if @action == 'initial_run'
|
141
|
+
records = @client.materialize(type).query("ccrmbasic__Contact__c != '' AND lastmodifieddate >= #{datetime}") if @action == 'update'
|
142
|
+
else
|
143
|
+
records = @client.materialize(type).all if @action == 'initial_run'
|
144
|
+
records = @client.materialize(type).query("lastmodifieddate >= #{datetime}") if @action == 'update'
|
145
145
|
end
|
146
|
+
|
146
147
|
sobjects = records.dup.to_a
|
147
148
|
while records.next_page?
|
148
149
|
sobjects += records.next_page
|
data/lib/fields.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module SalesforceMigration
|
2
2
|
class Fields
|
3
3
|
# Salesforce objects and the fields for import
|
4
|
-
ISOS_FIELDS = %w{Active__c Address__c Adult_Chargeback_Fee__c Adult_Commission__c Adult_Transaction_Fee__c Agreement_Received__c Background_Check_Complete__c Business_Phone_Number__c Cell_Phone_Number__c Comments__c
|
5
|
-
AGENT_FIELDS = %w{Id IsDeleted Name LastActivityDate
|
6
|
-
ACCOUNT_FIELDS = %w{Additional_Url__c Agents__c AnnualRevenue Approval_Citeria__c Approve_1__c Approve_2__c Approve_3__c BillingCity BillingCountry BillingPostalCode BillingState BillingStreet City__c
|
7
|
-
PAYMENT_METHODS_FIELDS = %w{Accounts__c Business_Contact__c Business_Type_Coments__c Business_type__c Buy_Rates__c Chargeback_Comments__c Chargeback__c Client_Integration__c Countries2__c Countries__c
|
8
|
-
BANKS_FIELDS = %w{Account_Number__c BIC_Code__c Merchant_2__c Bank_Address__c Bank_Name__c Contract__c
|
4
|
+
ISOS_FIELDS = %w{Active__c Address__c Adult_Chargeback_Fee__c Adult_Commission__c Adult_Transaction_Fee__c Agreement_Received__c Background_Check_Complete__c Business_Phone_Number__c Cell_Phone_Number__c Comments__c CreatedById CreatedDate Curren__c CurrencyIsoCode Email_Address__c Fax_Number__c Gambling_Chargeback_Fee__c Gambling_Commission_Fee__c Gambling_Transaction_Fee__c General_Conventional_Chargeback_Fee__c General_Conventional_Commission_Fee__c General_Conventional_Transaction_Fee__c General_Non_Conventional_Chargeback_Fee__c General_Non_Conventional_Commission_Fee__c General_Non_Conventional_Transaction_Fee__c ISO_ID_Assigned__c ISO_ID_Number__c ISO_Owner_Name__c Id IsDeleted KYC_Gathered__c LastActivityDate LastModifiedBy LastModifiedById LastModifiedDate Name New_Hire_Package_Received__c Owner OwnerId Pharmacy_Chargeback_Fee__c Pharmacy_Commission_Fee__c Pharmacy_Transaction_Fee__c Projected_Deals_Count__c Recruiter__c Region__c System_Access_Granted__c Training_Completed__c Welcome_Call_Completed__c Welcome_Package_Sent__c eMerchantPay_ISO_ID__c}
|
5
|
+
AGENT_FIELDS = %w{Id IsDeleted Name LastActivityDate CreatedDate CreatedById LastModifiedDate LastModifiedById LastModifiedBy Owner OwnerId Agent_Billing_Address__c Agent_Cell_Phone__c Agent_Id__c Agent_Phone__c Agent_Skype__c Agreement_Received__c Agreement_Sent__c Background_Check_Complete__c Business_Phone_Number__c Comments__c Commission_Fee__c Email_Address__c eMerchantPay_Agent_ID__c Fee_Comments__c ISO_Company__c New_Hire_Package_Received__c One_Time_Commission_Currency__c Recruiter__c Region__c Split_percentage__c System_Access_Granted__c Title__c Transaction_Fee__c}
|
6
|
+
ACCOUNT_FIELDS = %w{Additional_Url__c Agents__c AnnualRevenue Approval_Citeria__c Approve_1__c Approve_2__c Approve_3__c BillingCity BillingCountry BillingPostalCode BillingState BillingStreet City__c CreatedById CreatedDate Credit_Card__c CurrencyIsoCode Current_Volume__c Description Descriptor__c FD_Merchant_Number__c Fax ISO_Name__c Id IsDeleted Industry Info_Capture__c Integration__c Integrator__c Integrator_2__c Iovation__c IPSP__c IPSP_Name2__c IsPartner Jigsaw LastModifiedById LastModifiedDate Merchant_Email__c Merchant_Type__c Name NumberOfEmployees Overlying_Company__c OwnerId Phone Projected_Monthly_Volume__c Recruiter__c Risk_Analyst__c Secondary_FD_Merchant_Number__c ShippingCity ShippingCountry ShippingPostalCode ShippingState ShippingStreet Status_Comments__c Status__c Threat_Metrix__c Type__c Url__c VBV_MC3D__c Vacation1__c Website} # OwnerName OwnerPhone OwnerEmail}
|
7
|
+
PAYMENT_METHODS_FIELDS = %w{Accounts__c Business_Contact__c Business_Type_Coments__c Business_type__c Buy_Rates__c Chargeback_Comments__c Chargeback__c Client_Integration__c Countries2__c Countries__c CreatedById CreatedDate CurrencyIsoCode Id IsDeleted Integration__c LastModifiedBy LastModifiedById LastModifiedDate Name Our_Buy_Rates__c Owner OwnerId Proccessing_Currency__c Processing_Currency__c Rebilling_Comments__c Rebilling__c Refund_Comments__c Refund__c Release_Date__c Settlement_Currency__c Settlement_Cycle__c Settlement__c Tech_Contact__c Type__c V_terminal_Comments__c V_terminal__c}
|
8
|
+
BANKS_FIELDS = %w{Account_Number__c BIC_Code__c Merchant_2__c Bank_Address__c Bank_Name__c Contract__c CreatedById CreatedDate CurrencyIsoCode Holder_Address__c IBAN__c Id IsDeleted LastModifiedById LastModifiedDate Name OwnerId Processing_Currency__c Routing_Number__c SWIFT__c Settlement_Currency__c}
|
9
9
|
MERCHANTTOAPM_FIELDS = %w{Merchant__c Payment_Methods__c}
|
10
10
|
CCRMBASIC__EMAIL_FIELDS = %w{Actual_Subject__c Agent__c ccrmbasic__Account__c ccrmbasic__Body__c ccrmbasic__Cc__c ccrmbasic__Direction__c ccrmbasic__From__c ccrmbasic__Internal_Contact__c ccrmbasic__To__c Id IsDeleted Name}
|
11
11
|
EMAIL_ASSOCIATION_FIELDS = %w{Merchant_Name__c Email__c}
|
12
12
|
CONTRACT_FIELDS = %w{Id IsDeleted AccountId CurrencyIsoCode StartDate EndDate BillingStreet BillingCity BillingState BillingPostalCode BillingCountry ContractTerm OwnerId Status StatusCode ContractNumber CreatedDate CreatedById LastModifiedDate LastModifiedById SystemModstamp LastActivityDate Commission_Fee__c Transaction_Fee_Approved__c Transaction_Fee_Declined__c Charge_Back_Fee__c Rolling_Reserve__c Rolling_Reserve_Period__c VBV_Fee__c Wiring_Fee__c PCI_Compliance_Test_Fee__c Billing_Period_Duration_Weekly__c Discover__c Delay_in_Payment_Weeks__c Amex__c Guaranty__c Amount_Number__c Currency__c Treasury_Executive__c Acquirer__c Proccessing_Start_Date__c Proccessing_End_Date__c Acquirer_Approval_Timeframe__c Url__c Date_of_Submission_to_the_Acquirer__c Date_of_Approval__c Refund_Fee__c Registration_Fee__c Integrator_1__c Integrator_2__c Descriptor__c City_Field__c Acquirer_Rejection_Timeframe__c Date_of_Rejection__c Date_of_Issuing_the_MID__c Date_of_Terminal_Setup__c Date_of_Activation__c Deactivation_Date__c Comments__c Threat_Matrix__c Iovation__c Info_Capture__c VBV_MC3D__c PCI_Compliance__c Website_Compliance__c Reason_of_Deactivation__c VISA__c MC__c JCB__c UATP__c Integration_Type__c Payment_Status__c Payment_Suspension_Reason__c IPSP_name__c Visa_MCC_Code__c MC_MCC_Code__c Rejection_Reason__c Type_Of_Agreement__c}
|
13
|
-
ACQUIRER_FIELDS = %w{Id IsDeleted OwnerId Owner Name CurrencyIsoCode CreatedDate CreatedById
|
14
|
-
SYSTEM_FIELDS = %w{id acquirer ownerid createddate createdbyid integrator
|
15
|
-
SYSTEM_READABLE_FIELDS = %w{id acquirer_id owner_id created_date created_by_id integrator_id
|
13
|
+
ACQUIRER_FIELDS = %w{Id IsDeleted OwnerId Owner Name CurrencyIsoCode CreatedDate CreatedById LastModifiedDate LastModifiedById LastModifiedBy SystemModstamp LastActivityDate Acquirer_Address__c Acquirer_Country__c SPLIT__c Chargeback_Fee__c One_time_Setup_Fee__c Swift_Wire_Transfer_Fee__c Card_Type__c Card_Scheme__c Currency__c Risk_Level__c Transaction__c Fees_Approved__c Fees_Declined__c Fees_other__c Flat_Commision_Fee__c EUR_Interchange__c Non_EUR_Interchange__c }
|
14
|
+
SYSTEM_FIELDS = %w{id acquirer ownerid createddate createdbyid integrator ipsp iso lastactivitydate lastmodifieddate lastmodifiedbyid systemmodstamp recruiter region risk_analyst}
|
15
|
+
SYSTEM_READABLE_FIELDS = %w{id acquirer_id owner_id created_date created_by_id integrator_id ipsp_id iso_id last_activity_date last_modified_date last_modified_by_id system_modstamp recruiter_id region_id risk_analyst_id}
|
16
16
|
USER_FIELDS = %w{Id FirstName LastName Phone Email}
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
data/lib/import.rb
CHANGED
@@ -19,10 +19,9 @@ module SalesforceMigration
|
|
19
19
|
@action = options[:action]
|
20
20
|
@isos, @agents, @merchants, @bank_accounts, @agent_users, @iso_users, @emails = [], [], [], [], [], [], []
|
21
21
|
@payment_to_merchants, @emails_to_merchants, @acquirers, @contracts, @users = [], [], [], [], []
|
22
|
-
|
23
|
-
@logger.info("Import action started!")
|
22
|
+
$logger.info("Import action has started!")
|
24
23
|
start
|
25
|
-
|
24
|
+
$logger.info("Import action completed successfully!")
|
26
25
|
end
|
27
26
|
|
28
27
|
private
|
@@ -132,8 +131,8 @@ module SalesforceMigration
|
|
132
131
|
filename = "#{dir}/#{module_name}_export.csv"
|
133
132
|
end
|
134
133
|
|
135
|
-
|
136
|
-
|
134
|
+
$logger.error("Could not create or find a csv filename for module #{module_name}") unless defined? filename
|
135
|
+
$logger.info("Loading CSV file #{filename} for import")
|
137
136
|
csv_file = ::CSV.read(filename, :encoding => 'utf-8')
|
138
137
|
transform_csv_file(csv_file)
|
139
138
|
end
|
@@ -144,7 +143,7 @@ module SalesforceMigration
|
|
144
143
|
#
|
145
144
|
# @return [Array] transformed CSV file
|
146
145
|
def transform_csv_file(csv_file)
|
147
|
-
|
146
|
+
$logger.info("Transforming CSV file")
|
148
147
|
transformed = []
|
149
148
|
headers = csv_file.shift
|
150
149
|
headers.map!(&method(:prepare_custom_headers))
|
@@ -179,14 +178,16 @@ module SalesforceMigration
|
|
179
178
|
end
|
180
179
|
end
|
181
180
|
# Set the "deleted" flag according to SugarCRM's default fields
|
182
|
-
|
181
|
+
unless record['isdeleted'].blank?
|
182
|
+
record['deleted'] = record['isdeleted']
|
183
|
+
record.delete('isdeleted')
|
184
|
+
end
|
183
185
|
end
|
184
186
|
records
|
185
187
|
end
|
186
188
|
|
187
|
-
|
188
189
|
def transform_emails!(records)
|
189
|
-
|
190
|
+
$logger.info("Transforming Email fields")
|
190
191
|
records.each do |record|
|
191
192
|
record['sf_agent_id'] = record['agent']
|
192
193
|
record['sf_merchant_id'] = record['ccrmbasic__account']
|
@@ -211,7 +212,7 @@ module SalesforceMigration
|
|
211
212
|
end
|
212
213
|
|
213
214
|
def transform_payment_methods!(records)
|
214
|
-
|
215
|
+
$logger.info("Transforming Payment Method's fields")
|
215
216
|
records.each do |record|
|
216
217
|
record['business_type_comments'] = record['business_type_coments']
|
217
218
|
|
@@ -219,9 +220,8 @@ module SalesforceMigration
|
|
219
220
|
end
|
220
221
|
end
|
221
222
|
|
222
|
-
|
223
223
|
def transform_settlement_bank_accounts!(records)
|
224
|
-
|
224
|
+
$logger.info("Transforming Settlement Bank Account fields")
|
225
225
|
records.each do |record|
|
226
226
|
record['sf_contract_id'] = record['contract']
|
227
227
|
record['sf_merchant_id'] = record['merchant_2']
|
@@ -232,7 +232,7 @@ module SalesforceMigration
|
|
232
232
|
end
|
233
233
|
|
234
234
|
def transform_acquirers!(records)
|
235
|
-
|
235
|
+
$logger.info("Transforming Acquirer fields")
|
236
236
|
records.each do |record|
|
237
237
|
record['currency_iso_code'] = record['currencyisocode']
|
238
238
|
record['fees_transaction'] = record['transaction']
|
@@ -243,7 +243,7 @@ module SalesforceMigration
|
|
243
243
|
end
|
244
244
|
|
245
245
|
def transform_contracts!(records)
|
246
|
-
|
246
|
+
$logger.info("Transforming Contract fields")
|
247
247
|
records.each do |record|
|
248
248
|
record['name'] = record['contractnumber']
|
249
249
|
record['sf_account_id'] = record['accountid']
|
@@ -267,8 +267,8 @@ module SalesforceMigration
|
|
267
267
|
record['chargeback_fee'] = record['charge_back_fee']
|
268
268
|
record['billing_period_duration'] = record['billing_period_duration_weekly']
|
269
269
|
record['payment_delay'] = record['delay_in_payment_weeks']
|
270
|
-
record['
|
271
|
-
record['
|
270
|
+
record['integrator_1_sf_id'] = record['integrator_1']
|
271
|
+
record['integrator_2_sf_id'] = record['integrator_2']
|
272
272
|
record['date_of_issuing_mid'] = record['date_of_issuing_the_mid']
|
273
273
|
record['date_of_deactivation'] = record['deactivation_date']
|
274
274
|
record['threatmetrix'] = record['threat_matrix']
|
@@ -311,7 +311,7 @@ module SalesforceMigration
|
|
311
311
|
end
|
312
312
|
|
313
313
|
def transform_users!(records)
|
314
|
-
|
314
|
+
$logger.info("Transforming User fields")
|
315
315
|
records.each do |record|
|
316
316
|
record['name'] = "#{record['firstname']} #{record['lastname']}"
|
317
317
|
|
@@ -321,7 +321,7 @@ module SalesforceMigration
|
|
321
321
|
end
|
322
322
|
|
323
323
|
def transform_isos!(records)
|
324
|
-
|
324
|
+
$logger.info("Transforming ISO fields")
|
325
325
|
records.each do |record|
|
326
326
|
record['general_c_chargeback_fee'] = record['general_conventional_chargeback_fee']
|
327
327
|
record['general_c_commission_fee'] = record['general_conventional_commission_fee']
|
@@ -340,7 +340,7 @@ module SalesforceMigration
|
|
340
340
|
end
|
341
341
|
|
342
342
|
def transform_agents!(records)
|
343
|
-
|
343
|
+
$logger.info("Transforming Agent fields")
|
344
344
|
records.each do |record|
|
345
345
|
record['sf_iso_id'] = record['iso_company']
|
346
346
|
|
@@ -349,21 +349,25 @@ module SalesforceMigration
|
|
349
349
|
end
|
350
350
|
|
351
351
|
def transform_merchants!(records)
|
352
|
-
|
352
|
+
$logger.info("Transforming Merchant fields")
|
353
353
|
records.each do |record|
|
354
|
-
record['sf_agent_id']
|
355
|
-
record['
|
356
|
-
record['
|
357
|
-
record['
|
354
|
+
record['sf_agent_id'] = record['agents']
|
355
|
+
record['sf_integrator_id'] = record['integrator_1']
|
356
|
+
record['sf_integrator_2_id'] = record['integrator_2']
|
357
|
+
record['ipsp_name'] = record['ipsp_name2']
|
358
|
+
record['url'] = record['url'].to_s.gsub(/<[^>]*>|^[\n\r]*/, '')
|
359
|
+
record['additional_url'] = record['additional_url'].to_s.gsub(/(<[^>]*>|^[\n\r]*)/, '')
|
358
360
|
|
359
361
|
record.delete 'agents'
|
360
362
|
record.delete 'sf_region'
|
361
363
|
record.delete 'ipsp_name2'
|
364
|
+
record.delete 'integrator_1'
|
365
|
+
record.delete 'integrator_2'
|
362
366
|
end
|
363
367
|
end
|
364
368
|
|
365
369
|
def transform_email_to_merchants!(records)
|
366
|
-
|
370
|
+
$logger.info("Transforming Emails to Merchant fields");
|
367
371
|
records.each do |record|
|
368
372
|
record['sf_id'] = record['email']
|
369
373
|
record['sf_merchant_id'] = record['merchant_name']
|
@@ -374,7 +378,7 @@ module SalesforceMigration
|
|
374
378
|
end
|
375
379
|
|
376
380
|
def transform_apm_to_merchants!(records)
|
377
|
-
|
381
|
+
$logger.info("Transforming APM to Merchant fields");
|
378
382
|
records.each do |record|
|
379
383
|
record['sf_id'] = record['payment_methods']
|
380
384
|
record['sf_merchant_id'] = record['merchant']
|
@@ -495,7 +499,7 @@ module SalesforceMigration
|
|
495
499
|
|
496
500
|
case @action
|
497
501
|
when 'initial_run'
|
498
|
-
|
502
|
+
$logger.info("Creating new records for #{type} type")
|
499
503
|
records.each do |record|
|
500
504
|
create_sugar_record(module_type, record, type)
|
501
505
|
end
|
@@ -507,14 +511,14 @@ module SalesforceMigration
|
|
507
511
|
|
508
512
|
if existing_record
|
509
513
|
if existing_record.is_a?(Array)
|
510
|
-
|
514
|
+
$logger.error("More than one record for #{type} #{record['name']} - SalesForce Id (#{record['sf_id']}")
|
511
515
|
existing_record = existing_record.first
|
512
516
|
end
|
513
517
|
|
514
|
-
|
518
|
+
$logger.info("Updating record for #{type} #{record['name']}")
|
515
519
|
existing_record.update_attributes!(record)
|
516
520
|
else
|
517
|
-
|
521
|
+
$logger.info("Creating new record for #{type} #{record['name']}")
|
518
522
|
create_sugar_record(module_type, record, type)
|
519
523
|
end
|
520
524
|
end
|
@@ -609,7 +613,7 @@ module SalesforceMigration
|
|
609
613
|
# @return [SugarCRM::Namespace::Object] - the object
|
610
614
|
def create_associations(obj, type)
|
611
615
|
# You need to save! the object before passing it, as it won't create associations
|
612
|
-
|
616
|
+
$logger.info("Creating associations for #{type} #{obj.name}")
|
613
617
|
|
614
618
|
case type
|
615
619
|
when "agent"
|
@@ -636,7 +640,7 @@ module SalesforceMigration
|
|
636
640
|
#
|
637
641
|
# @param [SugarCRM::Namespace::EmpIso] Iso object
|
638
642
|
def create_security_group_iso(iso)
|
639
|
-
|
643
|
+
$logger.info("Creating SecurityGroup #{iso.name}")
|
640
644
|
security_group = SugarCRM::SecurityGroup.new(:name => iso.name) unless find_sugarcrm_object('security_group','name', iso.name)
|
641
645
|
security_group.save! if security_group
|
642
646
|
end
|
@@ -647,10 +651,10 @@ module SalesforceMigration
|
|
647
651
|
# @param [SugarCRM::Namespace::Object] obj object for which a user will be created
|
648
652
|
# @param [String] type type of the object
|
649
653
|
def create_user(obj, type)
|
650
|
-
|
654
|
+
$logger.info("Creating user for #{type} #{obj.name}")
|
651
655
|
if (defined?(obj.emerchantpay_iso_id) && (obj.emerchantpay_iso_id.blank? || obj.email_address.blank?)) ||
|
652
656
|
(defined?(obj.emerchantpay_agent_id) && (obj.emerchantpay_agent_id.blank? || obj.email_address.blank?))
|
653
|
-
|
657
|
+
$logger.error("Record |#{obj.name}| with type |#{type}| have empty fields (which are required), thus its skipped!")
|
654
658
|
else
|
655
659
|
user = SugarCRM::User.new
|
656
660
|
user.user_name = (type == 'agent') ? obj.emerchantpay_agent_id : obj.emerchantpay_iso_id
|
@@ -689,7 +693,14 @@ module SalesforceMigration
|
|
689
693
|
related_to_id = object.sf_id
|
690
694
|
end
|
691
695
|
|
692
|
-
|
696
|
+
case @action
|
697
|
+
when "update"
|
698
|
+
if relation_field == "sf_agent_id"
|
699
|
+
relation_data = type unless %(payment_method).include? type
|
700
|
+
else
|
701
|
+
relation_data = type unless %(email payment_method).include? type
|
702
|
+
end
|
703
|
+
end
|
693
704
|
|
694
705
|
found_records = find_related_records(relation_data, relation_field, related_to_id)
|
695
706
|
|
@@ -733,11 +744,11 @@ module SalesforceMigration
|
|
733
744
|
|
734
745
|
# Warn the user that we might've stumbbled upon some duplication or non-empty database (SalesForce Ids shoud be unique)
|
735
746
|
if user.is_a?(Array)
|
736
|
-
|
747
|
+
$logger.error("We found a SalesForce Id with two created SugarCRM users.")
|
737
748
|
user = user.first
|
738
749
|
end
|
739
750
|
|
740
|
-
|
751
|
+
$logger.info("Assigning #{user.last_name} as owner to #{object_to_assign.name}")
|
741
752
|
|
742
753
|
object_to_assign.assigned_user_id = user.id
|
743
754
|
object_to_assign.save!
|
@@ -761,7 +772,7 @@ module SalesforceMigration
|
|
761
772
|
end
|
762
773
|
when "update"
|
763
774
|
# Check if we are dealing with file-relations (stored as Array)
|
764
|
-
|
775
|
+
unless relation_data.is_a?(String)
|
765
776
|
relation_data.each { |record| search_results << record['sf_id'] if compare_salesforce_ids(record[relation_field], related_to_id) }
|
766
777
|
# OR extract the objects from SugarCRM
|
767
778
|
else
|
@@ -782,25 +793,25 @@ module SalesforceMigration
|
|
782
793
|
|
783
794
|
def put_isos_into_iso_group
|
784
795
|
if @isos
|
785
|
-
|
796
|
+
$logger.info("Puting ISOs into ISO groups")
|
786
797
|
role = SugarCRM::ACLRole.find_by_name("isos")
|
787
798
|
@isos.each do |iso|
|
788
799
|
security_group = find_sugarcrm_object('security_group','name', iso.name)
|
789
800
|
|
790
801
|
if security_group
|
791
|
-
|
802
|
+
$logger.info("Puting ISO #{iso.name} into its ISO group")
|
792
803
|
iso.associate! security_group
|
793
804
|
role.associate! security_group
|
794
805
|
|
795
806
|
user = SugarCRM::User.find_by_last_name(iso.name)
|
796
807
|
|
797
808
|
if user.nil?
|
798
|
-
|
809
|
+
$logger.error("ISO (#{iso.name}) doesn't have a user record")
|
799
810
|
else
|
800
811
|
user.associate! security_group
|
801
812
|
end
|
802
813
|
else
|
803
|
-
|
814
|
+
$logger.error("Couldn't find a SecurityGroup for ISO - #{iso.name}")
|
804
815
|
end
|
805
816
|
end
|
806
817
|
end
|
@@ -808,13 +819,13 @@ module SalesforceMigration
|
|
808
819
|
|
809
820
|
def put_agents_into_iso_group
|
810
821
|
if @agents
|
811
|
-
|
822
|
+
$logger.info("Putting agent records, agent users and agent role into ISO groups")
|
812
823
|
@agents.each do |agent|
|
813
824
|
security_group = find_sugarcrm_object('security_group','name', agent.emp_iso.first.name) unless agent.emp_iso.empty?
|
814
825
|
role = SugarCRM::ACLRole.find_by_name('agents')
|
815
826
|
if security_group
|
816
827
|
|
817
|
-
|
828
|
+
$logger.info("Puting Agent #{agent.name} in Security Group #{security_group.name}")
|
818
829
|
agent.associate! security_group
|
819
830
|
role.associate! security_group
|
820
831
|
|
@@ -823,12 +834,12 @@ module SalesforceMigration
|
|
823
834
|
user = SugarCRM::User.find_by_last_name(agent.name)
|
824
835
|
|
825
836
|
if user.nil?
|
826
|
-
|
837
|
+
$logger.error("Agent (#{agent.emp_iso.first.name}) doesn't have a user record")
|
827
838
|
else
|
828
839
|
user.associate! security_group
|
829
840
|
end
|
830
841
|
else
|
831
|
-
|
842
|
+
$logger.error("Couldn't find a ISO SecurityGroup for Agent - #{agent.emp_iso.first.name}")
|
832
843
|
end
|
833
844
|
end
|
834
845
|
end
|
@@ -840,13 +851,13 @@ module SalesforceMigration
|
|
840
851
|
# make a separate merchant select in every other method.
|
841
852
|
def put_merchants_into_iso_group
|
842
853
|
if @merchants
|
843
|
-
|
854
|
+
$logger.info("Puting merchants into ISO groups")
|
844
855
|
@merchants.each do |merchant|
|
845
856
|
unless (merchant.emp_agent.blank? || merchant.emp_agent.first.emp_iso.blank?)
|
846
857
|
security_group = find_sugarcrm_object('security_group','name', merchant.emp_agent.first.emp_iso.first.name)
|
847
858
|
|
848
859
|
if security_group
|
849
|
-
|
860
|
+
$logger.info("Puting merchant #{merchant.name} into ISO group")
|
850
861
|
merchant.associate! security_group
|
851
862
|
|
852
863
|
put_email_objects_into_iso_group(security_group, 'merchant', merchant)
|
@@ -854,7 +865,7 @@ module SalesforceMigration
|
|
854
865
|
put_bank_accounts_into_iso_group(security_group, merchant)
|
855
866
|
put_contracts_into_iso_group(security_group, merchant)
|
856
867
|
else
|
857
|
-
|
868
|
+
$logger.error("Couldn't find a ISO SecurityGroup for Merchant - #{merchant.name}")
|
858
869
|
end
|
859
870
|
end
|
860
871
|
end
|
@@ -864,7 +875,7 @@ module SalesforceMigration
|
|
864
875
|
def put_contracts_into_iso_group(security_group, merchant)
|
865
876
|
return unless security_group and merchant
|
866
877
|
|
867
|
-
|
878
|
+
$logger.info("Putting Contracts for #{merchant.name} into #{security_group.name} group")
|
868
879
|
|
869
880
|
case @action
|
870
881
|
when "initial_run"
|
@@ -881,7 +892,7 @@ module SalesforceMigration
|
|
881
892
|
def put_bank_accounts_into_iso_group(security_group, merchant)
|
882
893
|
return unless security_group and merchant
|
883
894
|
|
884
|
-
|
895
|
+
$logger.info("Puting Bank Accounts for #{merchant.name} into #{security_group.name} group")
|
885
896
|
|
886
897
|
case @action
|
887
898
|
when "initial_run"
|
@@ -898,7 +909,7 @@ module SalesforceMigration
|
|
898
909
|
def put_email_objects_into_iso_group(security_group, type, obj)
|
899
910
|
return unless security_group and type and obj
|
900
911
|
|
901
|
-
|
912
|
+
$logger.info("Puting Emails for #{obj.name} into #{security_group.name} group")
|
902
913
|
|
903
914
|
case type
|
904
915
|
when "agent"
|
@@ -925,7 +936,7 @@ module SalesforceMigration
|
|
925
936
|
def put_payment_methods_objects_into_iso_group(security_group, merchant)
|
926
937
|
return unless security_group and merchant
|
927
938
|
|
928
|
-
|
939
|
+
$logger.info("Puting Payment Methods for #{merchant.name} into #{security_group.name} group")
|
929
940
|
|
930
941
|
payment_methods = find_related_records(@payment_to_merchants, 'sf_merchant_id', merchant.sf_id)
|
931
942
|
|
data/lib/mailer.rb
CHANGED
@@ -5,18 +5,15 @@ module SalesforceMigration
|
|
5
5
|
class Mailer
|
6
6
|
|
7
7
|
def initialize(options)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
:port => @@config['smtp_port'],
|
12
|
-
:domain => @@config['smtp_domain'],
|
8
|
+
@smtp_options = { :address => $credentials['smtp_host'],
|
9
|
+
:port => $credentials['smtp_port'],
|
10
|
+
:domain => $credentials['smtp_domain'],
|
13
11
|
:authentication => nil,
|
14
12
|
:enable_starttls_auto => true}
|
15
13
|
|
16
|
-
|
17
|
-
@logger.info("Starting the mailer")
|
14
|
+
$logger.info("Mailer action has started!")
|
18
15
|
start
|
19
|
-
|
16
|
+
$logger.info("Mailer action completed successfully!")
|
20
17
|
end
|
21
18
|
|
22
19
|
private
|
@@ -30,7 +27,7 @@ module SalesforceMigration
|
|
30
27
|
|
31
28
|
if inactive_users
|
32
29
|
inactive_users.each do |user|
|
33
|
-
|
30
|
+
$logger.info("Sending email to #{user.last_name}")
|
34
31
|
|
35
32
|
plain_password = generate_password
|
36
33
|
md5_password = Digest::MD5.hexdigest plain_password
|
@@ -43,13 +40,13 @@ module SalesforceMigration
|
|
43
40
|
user.user_hash = crypt_password
|
44
41
|
user.save!
|
45
42
|
|
46
|
-
|
43
|
+
$logger.info("Updated user #{user.last_name} status to active")
|
47
44
|
else
|
48
|
-
|
45
|
+
$logger.info("Couldn't send credentials for #{user.last_name} to email address #{user.email1}")
|
49
46
|
end
|
50
47
|
end
|
51
48
|
else
|
52
|
-
|
49
|
+
$logger.info("No unnotified users found in database")
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
data/lib/sf_migrate.rb
CHANGED
@@ -54,27 +54,43 @@ module SalesforceMigration
|
|
54
54
|
end
|
55
55
|
optparse.parse!
|
56
56
|
begin
|
57
|
-
|
58
|
-
|
57
|
+
pre_init_with options
|
58
|
+
alter_log_formatter_to "EXPORT"
|
59
59
|
SalesforceMigration::Export.new(options) if options[:action]
|
60
|
+
alter_log_formatter_to "IMPORT"
|
60
61
|
SalesforceMigration::Import.new(options) if options[:action]
|
62
|
+
alter_log_formatter_to "MAIL"
|
61
63
|
SalesforceMigration::Mailer.new(options) if options[:send_mail]
|
62
64
|
rescue => e
|
63
|
-
|
65
|
+
$logger.error(e)
|
64
66
|
end
|
65
67
|
end
|
68
|
+
|
69
|
+
def pre_init_with options
|
70
|
+
$logger = create_logger
|
71
|
+
$credentials = YAML.load_file(options[:config_file])
|
72
|
+
SugarCRM.connect($credentials['sugar_url'], $credentials['sugar_username'], $credentials['sugar_password'])
|
73
|
+
end
|
66
74
|
|
67
75
|
def create_logger
|
68
|
-
|
76
|
+
formatter = Logger::Formatter.new
|
69
77
|
today = lambda { Date.today.to_s }
|
70
78
|
dateDir = "#{@log_dir}/#{today.call}"
|
71
79
|
dateLog = "#{dateDir}/migration.log"
|
72
80
|
FileUtils.mkdir_p(dateDir) unless Dir.exists? dateDir
|
73
|
-
|
74
|
-
|
75
|
-
|
81
|
+
|
82
|
+
logger = Logger.new(dateLog)
|
83
|
+
logger.formatter = proc { |severity, datetime, progname, msg|
|
84
|
+
formatter.call("IMPORT", datetime, progname, msg)
|
76
85
|
}
|
77
|
-
|
86
|
+
logger
|
87
|
+
end
|
88
|
+
|
89
|
+
def alter_log_formatter_to action
|
90
|
+
formatter = Logger::Formatter.new
|
91
|
+
$logger.formatter = proc { |severity, datetime, progname, msg|
|
92
|
+
formatter.call(action, datetime, progname, msg)
|
93
|
+
}
|
78
94
|
end
|
79
95
|
end
|
80
96
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sf_migrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Petkov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sugarcrm_emp
|