sf_migrate 1.2.8 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/export.rb +14 -13
- data/lib/fields.rb +5 -5
- data/lib/import.rb +58 -65
- data/lib/mailer.rb +8 -8
- data/lib/sf_migrate.rb +44 -39
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZTk1OTFhZjJhMjlkNDJjY2UwN2MzZjNjYzJiMjhhZGQ1OTk2ZmI3Mw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 82aec29fedabcbd9db839de6f4f4fc4af4778adf
|
4
|
+
data.tar.gz: 517dda0a66207a3462337df126134976fe8cad94
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MWViNjUwODE2YjIyYTI1ZTYzNTc1MzJjOTNhZTU2Y2FlOTZjYWZlMzRjODU0
|
11
|
-
NjU4NDdlMDk0MWM0MzI1ZmZhNzAwNWE5Yjg4ZmE2MjFhN2Y1NWM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MWQ4NDlmMzQzNDA0ODNiYzc2MzQ2MDQwYzgxZTBkOWJhYzAxNjliOGNiMTMx
|
14
|
-
ZDk2OWU1Njk5ZTJjZTgxYjg0ODVkZTM5YmVkNzFiNTcyM2RkNDcxMWMxNGZj
|
15
|
-
OWY3NjI2MzUxNjEzZjk3Njk1Y2U5MzFlZjM0NDU3MTI0ZWM2MzQ=
|
6
|
+
metadata.gz: 9a2456753dcd1539acd4353fdc435fefb33b28103c4de19b84c7fbeb934beb6b4de95e1f81e3539d691f521f85ced4098c8726e1ce37a48a2d6d6826408ea92b
|
7
|
+
data.tar.gz: 0b3b78950a7c826f03d98f55e794b55b745b79e48d1da70462b2e9d82e39f145141a7961e46d57522ef4732784c72a7e12158d253e9230f0185f21c6f6335bfd
|
data/lib/export.rb
CHANGED
@@ -5,13 +5,13 @@ module SalesforceMigration
|
|
5
5
|
# Initilize migration export object, authenticates to SalesForce and start the export
|
6
6
|
#
|
7
7
|
# @param [Hash] options hash representing passed command line options
|
8
|
-
def initialize
|
9
|
-
@csv_dir = options[:csv_dir]
|
10
|
-
@action = options[:action]
|
11
|
-
@last_modified_date = options[:last_modified_date]
|
8
|
+
def initialize
|
9
|
+
@csv_dir = $options[:csv_dir]
|
10
|
+
@action = $options[:action]
|
11
|
+
@last_modified_date = $options[:last_modified_date]
|
12
12
|
$logger.info("Export action has started!")
|
13
|
-
@client = Databasedotcom::Client.new :client_id => $
|
14
|
-
@client.authenticate :username => $
|
13
|
+
@client = Databasedotcom::Client.new :client_id => $config['salesforce_consumer_key'], :client_secret => $config['salesforce_consumer_secret']
|
14
|
+
@client.authenticate :username => $config['salesforce_username'], :password => $config['salesforce_password']
|
15
15
|
$logger.info("Authentication to SalesForce successfull")
|
16
16
|
start
|
17
17
|
$logger.info("Export action completed successfully!")
|
@@ -20,7 +20,7 @@ module SalesforceMigration
|
|
20
20
|
private
|
21
21
|
def start
|
22
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|
|
23
|
-
$logger.info
|
23
|
+
$logger.info("Writing CSV for #{type}")
|
24
24
|
write_to_csv type
|
25
25
|
end
|
26
26
|
end
|
@@ -59,11 +59,12 @@ module SalesforceMigration
|
|
59
59
|
# generate_name('Account') #=> '/tmp/update/2012-07-07/Account_export.csv'
|
60
60
|
def generate_name(type)
|
61
61
|
if @action == 'initial_run'
|
62
|
-
|
63
|
-
|
62
|
+
csv_initial_dir = "#{@csv_dir}/initial/"
|
63
|
+
FileUtils.mkdir_p(csv_initial_dir) unless Dir.exists? csv_initial_dir
|
64
|
+
"#{csv_initial_dir}/#{type}_export.csv"
|
64
65
|
else
|
65
66
|
today = lambda { Date.today.to_s }
|
66
|
-
dir
|
67
|
+
dir = "#{@csv_dir}/update/#{today.call}"
|
67
68
|
FileUtils.mkdir_p(dir) unless Dir.exists? dir
|
68
69
|
"#{dir}/#{type}_export.csv"
|
69
70
|
end
|
@@ -101,12 +102,12 @@ module SalesforceMigration
|
|
101
102
|
# @return [Databasedotcom::Collection] the requested records
|
102
103
|
def get_records(type)
|
103
104
|
if @action == 'initial_run'
|
104
|
-
$logger.info "Getting all records
|
105
|
+
$logger.info "Getting all records for SalesForce Object: #{type}"
|
105
106
|
else
|
106
107
|
if @last_modified_date.blank?
|
107
|
-
$logger.info "Getting records
|
108
|
+
$logger.info "Getting records since yesterday for SalesForce Object: #{type}"
|
108
109
|
else
|
109
|
-
$logger.info "Getting records from #{Date.parse(@last_modified_date)} up until now
|
110
|
+
$logger.info "Getting records from #{Date.parse(@last_modified_date)} up until now for SalesForce Object: #{type}"
|
110
111
|
end
|
111
112
|
end
|
112
113
|
get_all_sobjects(type)
|
data/lib/fields.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
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 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
|
5
|
-
AGENT_FIELDS = %w{Id IsDeleted Name LastActivityDate CreatedDate CreatedById LastModifiedDate LastModifiedById
|
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}
|
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
|
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 LastModifiedById LastModifiedDate Name New_Hire_Package_Received__c 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 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}
|
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 LastModifiedById LastModifiedDate Name Our_Buy_Rates__c 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
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
|
13
|
+
ACQUIRER_FIELDS = %w{Id IsDeleted OwnerId Name CurrencyIsoCode CreatedDate CreatedById LastModifiedDate LastModifiedById 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
14
|
SYSTEM_FIELDS = %w{id acquirer ownerid createddate createdbyid integrator ipsp iso lastactivitydate lastmodifieddate lastmodifiedbyid systemmodstamp recruiter region risk_analyst}
|
15
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}
|
data/lib/import.rb
CHANGED
@@ -14,9 +14,9 @@ module SalesforceMigration
|
|
14
14
|
# Initialize migration import object and start the import
|
15
15
|
#
|
16
16
|
# @param [Hash] options hash representing passed command line options
|
17
|
-
def initialize
|
18
|
-
@csv_dir
|
19
|
-
@action
|
17
|
+
def initialize
|
18
|
+
@csv_dir = $options[:csv_dir]
|
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
22
|
$logger.info("Import action has started!")
|
@@ -124,11 +124,10 @@ module SalesforceMigration
|
|
124
124
|
|
125
125
|
case @action
|
126
126
|
when "initial_run"
|
127
|
-
filename
|
127
|
+
filename = "#{@csv_dir}/initial/#{module_name}_export.csv"
|
128
128
|
when "update"
|
129
|
-
today
|
130
|
-
|
131
|
-
filename = "#{dir}/#{module_name}_export.csv"
|
129
|
+
today = lambda { Date.today.to_s }
|
130
|
+
filename = "#{@csv_dir}/update/#{today.call}/#{module_name}_export.csv"
|
132
131
|
end
|
133
132
|
|
134
133
|
$logger.error("Could not create or find a csv filename for module #{module_name}") unless defined? filename
|
@@ -145,7 +144,7 @@ module SalesforceMigration
|
|
145
144
|
def transform_csv_file(csv_file)
|
146
145
|
$logger.info("Transforming CSV file")
|
147
146
|
transformed = []
|
148
|
-
headers
|
147
|
+
headers = csv_file.shift
|
149
148
|
headers.map!(&method(:prepare_custom_headers))
|
150
149
|
|
151
150
|
csv_file.each do |row|
|
@@ -167,11 +166,11 @@ module SalesforceMigration
|
|
167
166
|
#
|
168
167
|
# @return [Array<SugarCRM::Namespace::Object>] records
|
169
168
|
def prefix_sf_attribute_names(records)
|
170
|
-
|
169
|
+
field_names_system = SalesforceMigration::Fields::SYSTEM_FIELDS
|
171
170
|
field_names_readable = SalesforceMigration::Fields::SYSTEM_READABLE_FIELDS
|
172
171
|
|
173
172
|
records.each do |record|
|
174
|
-
|
173
|
+
field_names_system.each_with_index do |field, index|
|
175
174
|
if record.key?(field)
|
176
175
|
record["sf_#{field_names_readable[index].downcase}"] = record[field]
|
177
176
|
record.delete(field)
|
@@ -235,7 +234,7 @@ module SalesforceMigration
|
|
235
234
|
$logger.info("Transforming Acquirer fields")
|
236
235
|
records.each do |record|
|
237
236
|
record['currency_iso_code'] = record['currencyisocode']
|
238
|
-
record['fees_transaction']
|
237
|
+
record['fees_transaction'] = record['transaction']
|
239
238
|
|
240
239
|
record.delete 'currencyisocode'
|
241
240
|
record.delete 'transaction'
|
@@ -245,37 +244,37 @@ module SalesforceMigration
|
|
245
244
|
def transform_contracts!(records)
|
246
245
|
$logger.info("Transforming Contract fields")
|
247
246
|
records.each do |record|
|
248
|
-
record['name']
|
249
|
-
record['sf_account_id']
|
250
|
-
record['currency_iso_code']
|
251
|
-
record['start_date']
|
252
|
-
record['end_date']
|
253
|
-
record['billing_street']
|
254
|
-
record['billing_city']
|
255
|
-
record['billing_state']
|
256
|
-
record['billing_postal_code']
|
257
|
-
record['billing_country']
|
258
|
-
record['contract_term']
|
259
|
-
record['status_code']
|
260
|
-
record['contract_number']
|
261
|
-
record['guarantee']
|
262
|
-
record['guaranteed_amount']
|
263
|
-
record['treasury_executive_sf_id']
|
264
|
-
record['processing_start_date']
|
265
|
-
record['processing_end_date']
|
247
|
+
record['name'] = record['contractnumber']
|
248
|
+
record['sf_account_id'] = record['accountid']
|
249
|
+
record['currency_iso_code'] = record['currencyisocode']
|
250
|
+
record['start_date'] = record['startdate']
|
251
|
+
record['end_date'] = record['enddate']
|
252
|
+
record['billing_street'] = record['billingstreet']
|
253
|
+
record['billing_city'] = record['billingcity']
|
254
|
+
record['billing_state'] = record['billingstate']
|
255
|
+
record['billing_postal_code'] = record['billingpostalcode']
|
256
|
+
record['billing_country'] = record['billingcountry']
|
257
|
+
record['contract_term'] = record['contractterm']
|
258
|
+
record['status_code'] = record['statuscode']
|
259
|
+
record['contract_number'] = record['contractnumber']
|
260
|
+
record['guarantee'] = record['guaranty']
|
261
|
+
record['guaranteed_amount'] = record['amount_number']
|
262
|
+
record['treasury_executive_sf_id'] = record['treasury_executive']
|
263
|
+
record['processing_start_date'] = record['proccessing_start_date']
|
264
|
+
record['processing_end_date'] = record['proccessing_end_date']
|
266
265
|
record['date_of_submission_to_acqirer'] = record['date_of_submission_to_the_acquirer']
|
267
|
-
record['chargeback_fee']
|
268
|
-
record['billing_period_duration']
|
269
|
-
record['payment_delay']
|
270
|
-
record['integrator_1_sf_id']
|
271
|
-
record['integrator_2_sf_id']
|
272
|
-
record['date_of_issuing_mid']
|
273
|
-
record['date_of_deactivation']
|
274
|
-
record['threatmetrix']
|
275
|
-
record['deactivation_reason']
|
276
|
-
record['mastercard']
|
277
|
-
record['ipsp_name_sf_id']
|
278
|
-
record['mastercard_mcc_code']
|
266
|
+
record['chargeback_fee'] = record['charge_back_fee']
|
267
|
+
record['billing_period_duration'] = record['billing_period_duration_weekly']
|
268
|
+
record['payment_delay'] = record['delay_in_payment_weeks']
|
269
|
+
record['integrator_1_sf_id'] = record['integrator_1']
|
270
|
+
record['integrator_2_sf_id'] = record['integrator_2']
|
271
|
+
record['date_of_issuing_mid'] = record['date_of_issuing_the_mid']
|
272
|
+
record['date_of_deactivation'] = record['deactivation_date']
|
273
|
+
record['threatmetrix'] = record['threat_matrix']
|
274
|
+
record['deactivation_reason'] = record['reason_of_deactivation']
|
275
|
+
record['mastercard'] = record['mc']
|
276
|
+
record['ipsp_name_sf_id'] = record['ipsp_name']
|
277
|
+
record['mastercard_mcc_code'] = record['mc_mcc_code']
|
279
278
|
|
280
279
|
record.delete 'contractnumber'
|
281
280
|
record.delete 'accountid'
|
@@ -501,6 +500,7 @@ module SalesforceMigration
|
|
501
500
|
when 'initial_run'
|
502
501
|
$logger.info("Creating new records for #{type} type")
|
503
502
|
records.each do |record|
|
503
|
+
correct_field_types! record
|
504
504
|
create_sugar_record(module_type, record, type)
|
505
505
|
end
|
506
506
|
when 'update'
|
@@ -511,7 +511,7 @@ module SalesforceMigration
|
|
511
511
|
|
512
512
|
if existing_record
|
513
513
|
if existing_record.is_a?(Array)
|
514
|
-
$logger.error("
|
514
|
+
$logger.error("Duplicated record found: #{record['name']} (#{type}) - SalesForceId (#{record['sf_id']}")
|
515
515
|
existing_record = existing_record.first
|
516
516
|
end
|
517
517
|
|
@@ -539,14 +539,14 @@ module SalesforceMigration
|
|
539
539
|
# @param record [SugarCRM::Namespace::Object]
|
540
540
|
# @param type
|
541
541
|
def create_sugar_record(module_type, record, type)
|
542
|
-
|
543
|
-
|
542
|
+
|
544
543
|
obj = module_type.new(record)
|
545
544
|
obj.save!
|
546
|
-
obj = create_associations(obj, type)
|
545
|
+
obj = create_associations(obj, type)
|
546
|
+
|
547
547
|
create_security_group_iso obj if type == 'iso'
|
548
|
-
|
549
548
|
create_user(obj, type) if %(iso agent).include? type
|
549
|
+
|
550
550
|
populate_var_pool(obj, type)
|
551
551
|
end
|
552
552
|
|
@@ -617,19 +617,14 @@ module SalesforceMigration
|
|
617
617
|
|
618
618
|
case type
|
619
619
|
when "agent"
|
620
|
-
associate_with!
|
621
|
-
|
622
|
-
associate_with!('email', @emails, 'sf_agent_id', obj)
|
620
|
+
associate_with! 'iso', @isos, 'sf_id', obj
|
621
|
+
associate_with! 'email', @emails, 'sf_agent_id', obj
|
623
622
|
when "merchant"
|
624
|
-
associate_with!
|
625
|
-
|
626
|
-
associate_with!
|
627
|
-
|
628
|
-
associate_with!
|
629
|
-
|
630
|
-
associate_with!('payment_method', @payment_to_merchants, 'sf_merchant_id', obj)
|
631
|
-
|
632
|
-
associate_with!('settlement_bank_account', @bank_accounts, 'sf_merchant_id', obj)
|
623
|
+
associate_with! 'agent', @agents, 'sf_id', obj
|
624
|
+
associate_with! 'contract', @contracts, 'sf_account_id', obj
|
625
|
+
associate_with! 'email', @emails_to_merchants, 'sf_merchant_id', obj
|
626
|
+
associate_with! 'payment_method', @payment_to_merchants, 'sf_merchant_id', obj
|
627
|
+
associate_with! 'settlement_bank_account', @bank_accounts, 'sf_merchant_id', obj
|
633
628
|
|
634
629
|
assign_user_as_owner_to_record(obj, obj)
|
635
630
|
end
|
@@ -660,7 +655,7 @@ module SalesforceMigration
|
|
660
655
|
user.user_name = (type == 'agent') ? obj.emerchantpay_agent_id : obj.emerchantpay_iso_id
|
661
656
|
user.last_name = obj.name
|
662
657
|
user.emp_type = type
|
663
|
-
user.email1 = obj.email_address
|
658
|
+
user.email1 = obj.email_address
|
664
659
|
user.status = 'Inactive'
|
665
660
|
user.salesforce_id = obj.sf_id
|
666
661
|
user.system_generated_password = false
|
@@ -742,9 +737,8 @@ module SalesforceMigration
|
|
742
737
|
|
743
738
|
return if user.blank?
|
744
739
|
|
745
|
-
# Warn the user that we might've stumbbled upon some duplication or non-empty database (SalesForce Ids shoud be unique)
|
746
740
|
if user.is_a?(Array)
|
747
|
-
$logger.error("
|
741
|
+
$logger.error("Duplicated User found, SalesForceId: #{salesforce_id}")
|
748
742
|
user = user.first
|
749
743
|
end
|
750
744
|
|
@@ -763,19 +757,18 @@ module SalesforceMigration
|
|
763
757
|
when "initial_run"
|
764
758
|
relation_data.each do |record|
|
765
759
|
# Check if we are dealing with file-relations (stored as Array)
|
766
|
-
# OR if we're using SugarCRM records (store as Object)
|
767
|
-
|
768
760
|
record_id = (relation_data.first.is_a?(Hash)) ? record['sf_id'] : record.sf_id
|
761
|
+
# OR if we're using SugarCRM records (store as Object)
|
769
762
|
relate_id = (relation_data.first.is_a?(Hash)) ? record[relation_field] : record.send(relation_field.to_sym)
|
770
763
|
|
771
764
|
search_results << record_id if compare_salesforce_ids(relate_id, related_to_id)
|
772
765
|
end
|
773
766
|
when "update"
|
774
|
-
# Check if we are dealing with file-relations (stored as Array)
|
775
767
|
unless relation_data.is_a?(String)
|
768
|
+
# Check if we are dealing with file-relations (stored as Array)
|
776
769
|
relation_data.each { |record| search_results << record['sf_id'] if compare_salesforce_ids(record[relation_field], related_to_id) }
|
777
|
-
# OR extract the objects from SugarCRM
|
778
770
|
else
|
771
|
+
# OR extract the objects from SugarCRM
|
779
772
|
records = find_sugarcrm_object(relation_data, relation_field, related_to_id)
|
780
773
|
|
781
774
|
return if records.blank?
|
data/lib/mailer.rb
CHANGED
@@ -4,10 +4,10 @@ module SalesforceMigration
|
|
4
4
|
|
5
5
|
class Mailer
|
6
6
|
|
7
|
-
def initialize
|
8
|
-
@smtp_options = { :address => $
|
9
|
-
:port => $
|
10
|
-
:domain => $
|
7
|
+
def initialize
|
8
|
+
@smtp_options = { :address => $config['smtp_host'],
|
9
|
+
:port => $config['smtp_port'],
|
10
|
+
:domain => $config['smtp_domain'],
|
11
11
|
:authentication => nil,
|
12
12
|
:enable_starttls_auto => true}
|
13
13
|
|
@@ -58,7 +58,7 @@ module SalesforceMigration
|
|
58
58
|
# @return [Boolean] true on successful delivery / false otherwise
|
59
59
|
def send_mail(email, username, password)
|
60
60
|
mail = Mail.new do
|
61
|
-
from
|
61
|
+
from $config['mail_from']
|
62
62
|
to email
|
63
63
|
subject 'Welcome to Emerchantpay Agent Portal'
|
64
64
|
html_part do
|
@@ -87,14 +87,14 @@ module SalesforceMigration
|
|
87
87
|
email_template = <<-TEMPLATE
|
88
88
|
Dear Valued Partner,<br/><br/>
|
89
89
|
|
90
|
-
We have created an account for you to access the newly created eMerchantPay <a href="#{
|
90
|
+
We have created an account for you to access the newly created eMerchantPay <a href="#{$config["sugar_url"]}">Agent Portal</a><br/><br/>
|
91
91
|
|
92
92
|
Your account data is:<br/><br/>
|
93
93
|
|
94
94
|
Login: <b>#{username}</b><br/>
|
95
95
|
Password: <b>#{password}</b><br/><br/>
|
96
96
|
|
97
|
-
Note: We've made significant upgrades to the <a href="#{
|
97
|
+
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/>
|
98
98
|
|
99
99
|
Features:<br/>
|
100
100
|
|
@@ -108,7 +108,7 @@ module SalesforceMigration
|
|
108
108
|
</ul>
|
109
109
|
|
110
110
|
<br/>
|
111
|
-
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="#{
|
111
|
+
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>)
|
112
112
|
<br/><br/>
|
113
113
|
---<br/><br/>
|
114
114
|
|
data/lib/sf_migrate.rb
CHANGED
@@ -5,85 +5,90 @@ require 'csv'
|
|
5
5
|
require 'yaml'
|
6
6
|
require 'fileutils'
|
7
7
|
require 'databasedotcom'
|
8
|
-
require 'sugarcrm'
|
9
|
-
require 'mail'
|
10
|
-
require 'securerandom'
|
11
|
-
require 'unix_crypt'
|
12
|
-
require 'fields'
|
13
8
|
require 'export'
|
9
|
+
require 'fields'
|
10
|
+
require 'sugarcrm'
|
14
11
|
require 'import'
|
12
|
+
require 'mail'
|
15
13
|
require 'mailer'
|
14
|
+
require 'unix_crypt'
|
15
|
+
require 'securerandom'
|
16
16
|
|
17
17
|
module SalesforceMigration
|
18
18
|
module Runner
|
19
19
|
extend self
|
20
|
-
|
21
|
-
# Start the migration dependening on command line argument: `initial_run` or `update`
|
22
20
|
def start
|
23
|
-
options
|
24
|
-
|
25
|
-
options[:csv_dir]
|
26
|
-
options[:log_dir]
|
27
|
-
options[:config_file] = "/var/sugarcrm/credentials.yaml"
|
28
|
-
@log_dir = options[:log_dir]
|
29
|
-
create_logger
|
21
|
+
options = {}
|
22
|
+
options[:config_file] = "/var/sugarcrm/credentials.yaml"
|
23
|
+
options[:csv_dir] = "/var/sugarcrm/csv"
|
24
|
+
options[:log_dir] = "/var/log/sugarcrm"
|
30
25
|
optparse = OptionParser.new do |opts|
|
31
26
|
opts.banner = "Usage: sf_migrate [options]"
|
32
|
-
opts.on("-a", "--action NAME", "
|
27
|
+
opts.on("-a", "--action NAME", "Specify the action type: initial_run or update") do |action|
|
33
28
|
options[:action] = action
|
34
29
|
end
|
35
|
-
opts.on("-f", "--
|
30
|
+
opts.on("-f", "--config-file CONFIG_FILE", "Supply an optional config file") do |f|
|
36
31
|
options[:config_file] = File.expand_path(f) if File.exists? f
|
37
32
|
end
|
38
|
-
opts.on("-c", "--
|
33
|
+
opts.on("-c", "--csv-dir CSV_DIR", "Set the directory for storing SalesForce's exported CSV objects") do |c|
|
39
34
|
options[:csv_dir] = c
|
40
35
|
end
|
41
|
-
opts.on("-l", "--
|
36
|
+
opts.on("-l", "--log-dir LOG_DIR", "Set the directory for migration.log (invactive in Verbose mode)") do |l|
|
42
37
|
options[:log_dir] = l
|
43
38
|
end
|
44
|
-
opts.on("-t", "--
|
39
|
+
opts.on("-t", "--last-modified-date DATE/DATETIME", "Set the date from which you would like to get results (up until now)") do |t|
|
45
40
|
options[:last_modified_date] = t
|
46
41
|
end
|
47
|
-
opts.on("-m", "--
|
42
|
+
opts.on("-m", "--send-mail", "Send activation email to every new user") do |m|
|
48
43
|
options[:send_mail] = m
|
49
44
|
end
|
45
|
+
opts.on("-v", "--verbose", "Set verbose logging to the terminal") do |v|
|
46
|
+
options[:verbose] = v
|
47
|
+
end
|
50
48
|
opts.on("-h", "--help", "Display this screen") do
|
51
49
|
puts opts
|
52
50
|
exit
|
53
51
|
end
|
54
52
|
end
|
55
53
|
optparse.parse!
|
54
|
+
pre_init_with options
|
56
55
|
begin
|
57
|
-
pre_init_with options
|
58
56
|
alter_log_formatter_to "EXPORT"
|
59
|
-
SalesforceMigration::Export.new(
|
57
|
+
SalesforceMigration::Export.new() if options[:action]
|
60
58
|
alter_log_formatter_to "IMPORT"
|
61
|
-
SalesforceMigration::Import.new(
|
62
|
-
alter_log_formatter_to "
|
63
|
-
SalesforceMigration::Mailer.new(
|
59
|
+
SalesforceMigration::Import.new() if options[:action]
|
60
|
+
alter_log_formatter_to "MAILER"
|
61
|
+
SalesforceMigration::Mailer.new() if options[:send_mail]
|
64
62
|
rescue => e
|
65
63
|
$logger.error(e)
|
66
64
|
end
|
67
65
|
end
|
68
66
|
|
69
67
|
def pre_init_with options
|
70
|
-
$
|
71
|
-
$
|
72
|
-
|
68
|
+
$options = options
|
69
|
+
$config = YAML.load_file(options[:config_file])
|
70
|
+
$logger = start_log
|
71
|
+
|
72
|
+
SugarCRM.connect($config['sugar_url'], $config['sugar_username'], $config['sugar_password'])
|
73
73
|
end
|
74
74
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
75
|
+
def start_log
|
76
|
+
formatter = Logger::Formatter.new
|
77
|
+
today = lambda { Date.today.to_s }
|
78
|
+
dateDir = "#{$options[:log_dir]}/#{today.call}"
|
79
|
+
dateLog = "#{dateDir}/migration.log"
|
80
|
+
FileUtils.mkdir_p(dateDir) unless Dir.exists? dateDir
|
81
|
+
|
82
|
+
unless $options[:verbose]
|
83
|
+
logger = Logger.new dateLog
|
84
|
+
else
|
85
|
+
logger = Logger.new STDOUT
|
86
|
+
end
|
81
87
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
logger
|
88
|
+
logger.formatter = proc { |severity, datetime, progname, msg|
|
89
|
+
formatter.call("IMPORT", datetime, progname, msg)
|
90
|
+
}
|
91
|
+
logger
|
87
92
|
end
|
88
93
|
|
89
94
|
def alter_log_formatter_to action
|
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.
|
4
|
+
version: 1.3.0
|
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-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sugarcrm_emp
|
@@ -107,17 +107,17 @@ require_paths:
|
|
107
107
|
- lib
|
108
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
|
-
- -
|
110
|
+
- - '>='
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.0.3
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Makes a bridge between Salesforce and SugarCRM
|