salesforce_ar_sync 5.3.0 → 5.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 469e85715a39bc27f3ce3af76aa9178d9c1abf4c2ec7239efbf842dc6ad71d71
4
- data.tar.gz: 7e9f9732581785b7242392aab88a0078d58d791d96836f3377745428cae0a91e
3
+ metadata.gz: 40fc50d80886fc52df3a5e7746cedd628bd6caa59208f98fd4d9da679ce4c02b
4
+ data.tar.gz: 5a281b4603cab7430a4e7c9b615c5797a9af146a4e3eaf0221136f2ca76d5041
5
5
  SHA512:
6
- metadata.gz: eee86f8fe5a96e0f58349863cdad1ee9ac385175658c8e090c9acee8d005c5de2fb18d37b91929f4373cec34baf25ddd0306415d667e310fc98cab9538fd49d5
7
- data.tar.gz: 97e2f7b8bd5eb49342b49d100b23de407feb95b8262ce8c8695488abf369d8150e70cd889acf62fda6c4e0792fcec68061cd48498b764999252ec3fbb34c77b0
6
+ metadata.gz: 8f811c64d88b6fdeba01af7d5bd97b48aed716de2d9014413ffef4a417eab3155db55655e101edd507adf80e5dc7f2e6066d2430bd57421ecc85102ec4f67ebf
7
+ data.tar.gz: 1d1d0b72a10dc10e2d47a151fb4dde0281db7ec340f0b910cc899613eb393247ec6ef68b7bcfbc79ecbcabdc70604ea58880382605ccc99fb2fa2583d325e884
@@ -71,24 +71,49 @@ module SalesforceArSync
71
71
  def salesforce_update(attributes = {})
72
72
  raise ArgumentError, "#{salesforce_id_attribute_name} parameter required" if attributes[salesforce_id_attribute_name].blank?
73
73
 
74
+ attempt_salesforce_update(attributes)
75
+ end
76
+
77
+ private
78
+
79
+ def find_record(attributes)
74
80
  data_source = unscoped_updates ? unscoped : self
75
81
  object = data_source.find_by(salesforce_id: attributes[salesforce_id_attribute_name])
76
82
  object ||= data_source.find_by(activerecord_web_id_attribute_name => attributes[salesforce_web_id_attribute_name]) if salesforce_sync_web_id? && attributes[salesforce_web_id_attribute_name]
83
+ return object if object.present?
77
84
 
78
- if !object && additional_lookup_fields
85
+ if additional_lookup_fields
79
86
  additional_lookup_fields.each do |attribute_name, salesforce_attribute_name|
80
87
  object = data_source.find_by(attribute_name => attributes[salesforce_attribute_name]) if attributes[salesforce_attribute_name]
88
+ break if object
81
89
  end
90
+ return object
82
91
  end
92
+ end
83
93
 
84
- if object.nil?
85
- object = new
94
+ def build_record(attributes)
95
+ new.tap do |object|
86
96
  salesforce_default_attributes_for_create.merge(salesforce_id: attributes[salesforce_id_attribute_name]).each_pair do |k, v|
87
97
  object.send("#{k}=", v)
88
98
  end
89
99
  end
100
+ end
101
+
102
+ def attempt_salesforce_update(attributes, retried: false)
103
+ object = find_record(attributes) || build_record(attributes)
104
+ return unless object
105
+
106
+ object.salesforce_process_update(attributes) if salesforce_stale?(object, attributes[:SystemModstamp])
107
+ rescue ActiveRecord::RecordNotUnique
108
+ raise if retried
109
+
110
+ attempt_salesforce_update(attributes, retried: true)
111
+ end
112
+
113
+ def salesforce_stale?(object, modstamp)
114
+ return false if modstamp.blank?
90
115
 
91
- object.salesforce_process_update(attributes) if object && (object.salesforce_updated_at.nil? || (object.salesforce_updated_at && object.salesforce_updated_at < Time.parse(attributes[:SystemModstamp])))
116
+ object.salesforce_updated_at.nil? || object.salesforce_updated_at < Time.parse(modstamp)
92
117
  end
93
118
  end
94
119
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SalesforceArSync
4
- VERSION = '5.3.0'
4
+ VERSION = '5.3.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce_ar_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Halliday
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2025-09-23 00:00:00.000000000 Z
15
+ date: 2026-06-30 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: actionpack-xml_parser