From 282f897a0201d440babe47a99d437bf80bbe2a0c Mon Sep 17 00:00:00 2001 From: mkornatz Date: Tue, 18 Apr 2017 15:44:18 -0400 Subject: [PATCH] Cuts out complex buggy logic for a simpler approach --- .../OneCampaignMonitor_SubscribersService.php | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/services/OneCampaignMonitor_SubscribersService.php b/services/OneCampaignMonitor_SubscribersService.php index cdd71c8..0478fe6 100644 --- a/services/OneCampaignMonitor_SubscribersService.php +++ b/services/OneCampaignMonitor_SubscribersService.php @@ -102,32 +102,14 @@ public function update($listId, $email, $name=null, $customFields=array(), $resu $existingSubscriber = $result->response; - // Count the number of occurances of custom field to know - // which is a Multi-Valued Select Many field - $fieldOccurances = []; foreach ($existingSubscriber->CustomFields as $existingField) { - if (array_key_exists($existingField->Key, $fieldOccurances)) { - $fieldOccurances[$existingField->Key]++; - } else { - $fieldOccurances[$existingField->Key] = 1; - } + $subscriber['CustomFields'][] = [ + 'Key' => $existingField->Key, + 'Value' => $existingField->Value + ]; } - - // For any Multi-Valued Select Many field, make sure to append the - // existing field values - foreach($fieldOccurances as $key => $value) { - if ($value > 1) { - foreach($existingSubscriber->CustomFields as $existingField) { - if ($existingField->Key == $key) { - $subscriber['CustomFields'][] = $existingField; - } - } - } - } - } else { - $subscriber['CustomFields'] = $parsedCustomFields; } - + $result = $connection->update($email, $subscriber); $error = null;