Skip to content

Commit

Permalink
Cuts out complex buggy logic for a simpler approach
Browse files Browse the repository at this point in the history
  • Loading branch information
mkornatz committed Apr 18, 2017
1 parent fab0050 commit 282f897
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions services/OneCampaignMonitor_SubscribersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 282f897

Please sign in to comment.