Skip to content

Commit

Permalink
Update subscription_data handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmcleod committed Oct 24, 2024
1 parent 403d5ae commit c0cd477
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions lib/discourse_subscription_client/subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,20 @@ def update_supplier(supplier)
return (supplier.deactivate_all_subscriptions! && @result.connection_error(supplier)) if response.nil?

subscription_data = @result.retrieve_subscriptions(supplier, response)
return supplier.deactivate_all_subscriptions! if @result.errors.any?
return supplier.deactivate_all_subscriptions! if subscription_data.blank?

# deactivate any of the supplier's subscriptions not retrieved from supplier
if supplier.subscriptions.present?
supplier.subscriptions.each do |subscription|
has_match = false
subscription_data.each do |data|
if data_matches_subscription(data, subscription)
data.subscription = subscription
has_match = true
end
supplier.subscriptions.each do |subscription|
has_match = false
subscription_data.each do |data|
if data_matches_subscription(data, subscription)
data.subscription = subscription
has_match = true
end
subscription.deactivate! unless has_match
end
subscription.deactivate! unless has_match
end

return @result.no_subscriptions(supplier) if subscription_data.blank?

subscription_data.each do |data|
if data.subscription.present?
data.subscription.update(subscribed: true)
Expand Down

0 comments on commit c0cd477

Please sign in to comment.