onebody-updateagent 0.4.2 → 0.4.3
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.
- data/VERSION +1 -1
- data/bin/update_onebody +3 -0
- data/lib/updateagent/schema.rb +2 -1
- data/lib/updateagent/updateagent.rb +16 -15
- data/lib/updateagent/updaters/people_updater.rb +1 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
data/bin/update_onebody
CHANGED
@@ -38,6 +38,9 @@ opt_parser = OptionParser.new do |opts|
|
|
38
38
|
#opts.on("-d", "--delete", "Delete people and families not found in source file") do |d|
|
39
39
|
# options[:delete] = true
|
40
40
|
#end
|
41
|
+
opts.on("--debug", "Enable extra debugging messages.") do |d|
|
42
|
+
config['debug'] = true if config
|
43
|
+
end
|
41
44
|
opts.on("--version", "Show version and exit.") do
|
42
45
|
puts "OneBody UpdateAgent version #{UPDATEAGENT_VERSION}"
|
43
46
|
puts
|
data/lib/updateagent/schema.rb
CHANGED
@@ -11,5 +11,6 @@ family_schema = Schema.new(Family)
|
|
11
11
|
|
12
12
|
DATETIME_ATTRIBUTES = person_schema.type(:datetime) + family_schema.type(:datetime).map { |c| 'family_' + c }
|
13
13
|
BOOLEAN_ATTRIBUTES = person_schema.type(:boolean) + family_schema.type(:boolean).map { |c| 'family_' + c }
|
14
|
-
INTEGER_ATTRIBUTES = person_schema.type(:integer) + family_schema.type(:integer).map { |c| 'family_' + c }
|
14
|
+
INTEGER_ATTRIBUTES = person_schema.type(:integer) + family_schema.type(:integer).map { |c| 'family_' + c } \
|
15
|
+
+ %w(mobile_phone work_phone fax business_phone family_home_phone)
|
15
16
|
IGNORE_ATTRIBUTES = %w(updated_at created_at family_updated_at family_latitude family_longitude)
|
@@ -1,12 +1,10 @@
|
|
1
1
|
# general class to handle comparing and pushing data to the remote end
|
2
2
|
class UpdateAgent
|
3
3
|
|
4
|
-
MAX_HASHES_AT_A_TIME =
|
4
|
+
MAX_HASHES_AT_A_TIME = 500
|
5
5
|
MAX_TO_BATCH_AT_A_TIME = 10
|
6
6
|
SLEEP_PERIOD = 3
|
7
7
|
|
8
|
-
DEBUG = false
|
9
|
-
|
10
8
|
def initialize(data=nil, options={})
|
11
9
|
@options = options
|
12
10
|
@attributes = []
|
@@ -66,6 +64,8 @@ class UpdateAgent
|
|
66
64
|
end
|
67
65
|
elsif INTEGER_ATTRIBUTES.include?(key)
|
68
66
|
value = value.to_s != '' ? value.scan(/\d/).join.to_i : nil
|
67
|
+
else
|
68
|
+
value = value.to_s.gsub(/\r\n|\n|\r/, ' ')
|
69
69
|
end
|
70
70
|
hash[key] = value
|
71
71
|
end
|
@@ -111,7 +111,7 @@ class UpdateAgent
|
|
111
111
|
|
112
112
|
def present_record(row, new=false)
|
113
113
|
puts "#{row['legacy_id'].to_s.ljust(10)} #{name_for(row).to_s.ljust(40)} #{new ? '(new)' : ' '}"
|
114
|
-
if
|
114
|
+
if @options['debug']
|
115
115
|
puts "Local values: #{row.values_for_hash(@attributes).join}"
|
116
116
|
puts "Remote values: #{row['remote_hash']}"
|
117
117
|
end
|
@@ -178,14 +178,12 @@ class UpdateAgent
|
|
178
178
|
|
179
179
|
def finish_sync(create_items=true, mark_complete=true)
|
180
180
|
if create_items
|
181
|
-
@
|
182
|
-
|
183
|
-
|
184
|
-
(
|
185
|
-
|
186
|
-
|
187
|
-
).to_xml
|
188
|
-
)
|
181
|
+
items = @create.map { |r| to_sync_item(r, 'create') } +
|
182
|
+
@update.map { |r| to_sync_item(r, 'update') }
|
183
|
+
items.each_slice(100) do |items|
|
184
|
+
@sync.post(:create_items, {}, items.to_xml)
|
185
|
+
sleep SLEEP_PERIOD
|
186
|
+
end
|
189
187
|
end
|
190
188
|
if mark_complete
|
191
189
|
@sync.complete = true
|
@@ -230,15 +228,16 @@ class UpdateAgent
|
|
230
228
|
# ask remote end for value hashe for each record (50 at a time)
|
231
229
|
# mark records to create or update based on response
|
232
230
|
def compare_hashes(ids, force=false)
|
231
|
+
index = 0
|
232
|
+
print "#{resource.name} 0/#{ids.length}\r"; STDOUT.flush
|
233
233
|
ids.each_slice(MAX_HASHES_AT_A_TIME) do |some_ids|
|
234
|
-
print '.'; STDOUT.flush
|
235
234
|
options = {:attrs => @attributes.join(','), :legacy_id => some_ids.join(',')}
|
236
|
-
options.merge!(:debug => true) if
|
235
|
+
options.merge!(:debug => true) if @options['debug']
|
237
236
|
response = resource.post(:hashify, {}, options.to_xml)
|
238
237
|
hashes = Hash.from_xml(response.body)['records'].to_a
|
239
238
|
hashes.each do |record|
|
240
239
|
row = data_by_id[record['legacy_id'].to_i]
|
241
|
-
if
|
240
|
+
if @options['debug']
|
242
241
|
row['remote_hash'] = record['hash']
|
243
242
|
@update << row if force or row.values_for_hash(@attributes).join != record['hash'] or (resource.name == 'Person' and record['family_id'].nil?)
|
244
243
|
else
|
@@ -246,6 +245,8 @@ class UpdateAgent
|
|
246
245
|
end
|
247
246
|
end
|
248
247
|
@create += some_ids.reject { |id| hashes.map { |h| h['legacy_id'].to_i }.include?(id.to_i) }.map { |id| data_by_id[id.to_i] }
|
248
|
+
index += some_ids.length
|
249
|
+
print "#{resource.name} #{index}/#{ids.length}\r"; STDOUT.flush
|
249
250
|
sleep SLEEP_PERIOD
|
250
251
|
end
|
251
252
|
puts
|
@@ -19,14 +19,12 @@ class PeopleUpdater < UpdateAgent
|
|
19
19
|
person['family'] = existing_family
|
20
20
|
if person.has_key?('email')
|
21
21
|
person['email_changed'] = false
|
22
|
-
@attributes << 'email_changed'
|
23
22
|
end
|
24
23
|
person_data << person
|
25
24
|
else
|
26
25
|
person['family'] = family
|
27
26
|
if person.has_key?('email')
|
28
27
|
person['email_changed'] = false
|
29
|
-
@attributes << 'email_changed'
|
30
28
|
end
|
31
29
|
person_data << person
|
32
30
|
family['barcode_id_changed'] = false if family.has_key?('barcode_id')
|
@@ -35,6 +33,7 @@ class PeopleUpdater < UpdateAgent
|
|
35
33
|
print "splitting family record #{index+1}\r"
|
36
34
|
end
|
37
35
|
puts
|
36
|
+
@attributes << 'email_changed' if @attributes.include?('email')
|
38
37
|
@data = person_data
|
39
38
|
@attributes.reject! { |a| a =~ /^family_/ and a != 'family_id' }
|
40
39
|
@family_agent = FamilyUpdater.new(family_data.values, @options)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onebody-updateagent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Morgan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-21 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|