salesforce-sql 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f01df703e1067d09fb1b74a5917ec59687d8fd6f
4
- data.tar.gz: d741bb84bea358a71e1f551e34f5da4d076913c4
3
+ metadata.gz: 39135041a9aef55d8bc41f053c6734a48a81539c
4
+ data.tar.gz: 217155859971b571c010ff51ca06924d3149633e
5
5
  SHA512:
6
- metadata.gz: 697263b8ecb8dad4fc84bf186cf92eb4697904e4106019dcd87d1bdd0143744a1013be5f8fa8a1b8d425f5aaf8e9b291fa557cc0a470f67763f0386cfcd8896d
7
- data.tar.gz: ed27f47aa432dc6fc289f773ba3ac9a263cc0a7f65ef2ae428b27ff7445b9fc76d4cf6ca24fb908696fe5f16a24261207ea1f0f432588229020a3c112920ac1d
6
+ metadata.gz: 81ac9b04b995b7ce8cac6ac74fc9186a1a05f94424594f3b1c611b4bbd178ddd739c1fafa576c5c33db9d446b23814e1736bd30d26a59a64d51347a5aa736ab7
7
+ data.tar.gz: 10e95d94b77fede78cf71c6746c35f88924ac5479349c66b62002df3dd8d9f6c04ffd650f3fc6fd301a15145ad38aa95f193d66edd17fc5b791561cf1bc7a876
@@ -5,6 +5,9 @@ module Salesforce
5
5
  attr_accessor :debug
6
6
  attr_accessor :username
7
7
  attr_accessor :step
8
+ attr_accessor :salesforce_bulk_client
9
+ attr_accessor :restforce_client
10
+ attr_accessor :default_ignore_fields
8
11
 
9
12
  def initialize credentials
10
13
 
@@ -20,7 +23,6 @@ module Salesforce
20
23
  @default_ignore_fields = [
21
24
  'Id',
22
25
  'IsDeleted',
23
- 'IsPartner',
24
26
  'MasterRecordId',
25
27
  'ParentId',
26
28
  'OwnerId',
@@ -100,6 +102,49 @@ module Salesforce
100
102
 
101
103
  end
102
104
 
105
+ # Description: It will resolve the id mapping for a set of records
106
+ # parameters:
107
+ # source: The Salesforce::SQL of the source organization
108
+ # dependency_object: The DEPENDENCY object name
109
+ # dependency_object_pk: the DEPENENCY field to be used as primary key
110
+ # object_fk_field: The foreign key field name in the OBJECT
111
+
112
+ def map_ids source: , records: , object_fk_field: , dependency_object_pk: , dependency_object: nil
113
+
114
+ # Get dependency object ids from the object
115
+ dependency_ids = records.map{|row| row[object_fk_field]}.compact.sort.uniq
116
+
117
+ # Use those Ids to get the object records from source including the dependency_object_pk
118
+ source_object = source.query "Select Id,#{dependency_object_pk} FROM #{dependency_object}", dependency_ids
119
+
120
+ # Get the dependency_object_pk values and export the IDs from the target object
121
+ dependency_object_pk_values = source_object.map {|row| row[dependency_object_pk].gsub("'", %q(\\\')) if not row[dependency_object_pk].nil? }.compact
122
+ target_object = self.query_select_in "Select Id,#{dependency_object_pk} FROM #{dependency_object} WHERE #{dependency_object_pk}", dependency_object_pk_values
123
+
124
+ # Now we have source_object and target_object ids and values, we can do the mapping on records
125
+ records.map! do |record|
126
+
127
+ # If the :object_fk_field is nil, then there is no reference to map and we import the record as itis
128
+ next record if record[object_fk_field].nil?
129
+
130
+ # Grab the source dependency item for this record using the :object_fk_field id, if the source item doesn't exist, don't insert the record
131
+ source_item = source_object.select {|row| row['Id'] == record[object_fk_field] }
132
+ next if source_item.empty?
133
+
134
+ # Grab the target dependency item for this record using the :dependency_object_pk, if the target item doesnt exist, don't insert the record
135
+ target_item = target_object.select {|row| row[dependency_object_pk] == source_item.first[dependency_object_pk]}
136
+ next if target_item.empty?
137
+
138
+ # The actual mapping
139
+ record[object_fk_field] = target_item.first['Id']
140
+ record
141
+
142
+ end
143
+
144
+ records
145
+
146
+ end
147
+
103
148
  # Description: Copy an object from one source to target
104
149
  # Parameters:
105
150
  # object: The object to copy
@@ -137,7 +182,7 @@ module Salesforce
137
182
  source_object = source.query "Select Id,#{dep[:dependency_object_pk]} FROM #{dep[:dependency_object]}", dependency_ids
138
183
 
139
184
  # Get the dependency_object_pk values and export the IDs from the target object
140
- dependency_object_pk_values = source_object.map {|row| row[dep[:dependency_object_pk]].gsub("'", %q(\\\'))}
185
+ dependency_object_pk_values = source_object.map {|row| row[dep[:dependency_object_pk]].gsub("'", %q(\\\')) if not row[dep[:dependency_object_pk]].nil? }.compact
141
186
  target_object = self.query_select_in "Select Id,#{dep[:dependency_object_pk]} FROM #{dep[:dependency_object]} WHERE #{dep[:dependency_object_pk]}", dependency_object_pk_values
142
187
 
143
188
  # Now we have source_object and target_object ids and values, we can do the mapping on bulk_import_records
@@ -207,8 +252,6 @@ module Salesforce
207
252
  count_after - count_before
208
253
  end
209
254
 
210
- private
211
-
212
255
  def bulk_insert object, records
213
256
  (0..(records.size-1)).step(@bulk_api_step).each do |n|
214
257
  job = @salesforce_bulk_client.create object, records[n..n+@bulk_api_step-1]
@@ -1,5 +1,5 @@
1
1
  module Salesforce
2
2
  module Sql
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Breinlinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler