Skip to content

Commit

Permalink
Fix propagation of mail user preferences if they didn't exist yet
Browse files Browse the repository at this point in the history
Mailer-CRM could got into state, where Mailer didn't have
the default user preferences created yet, but CRM wanted to update
them. CRM didn't correctly build the request, because it was based
on the existing user preferences provided by Mailer (which were empty).

The change request now operates with the submitted data and uses
preferences provided by Mailer as an optional feature. If they don't
exist, CRM assumes that the user IS NOT subscribed to the newsletter
and builds the change requests based on that information.

remp/crm#2883
  • Loading branch information
rootpd committed Jun 22, 2023
1 parent 577b0e7 commit 073df55
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Forms/EmailSettingsFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ public function create(?int $userId = null)
$buttonsGroup = $form->addGroup('buttons')
->setOption('label', null);

$form->addHidden('user_id', $userId);

foreach ($mailTypes as $mailType) {
$title = $mailType->title;
$isSubscribed = $mailSubscriptions[$mailType->id]['is_subscribed'] ?? false;
Expand Down Expand Up @@ -156,8 +154,9 @@ public function formSucceeded(Form $form, ArrayHash $values)

$subscribeRequests = [];
$userPreferences = $this->mailUserSubscriptionsRepository->userPreferences($values['user_id']);
foreach ($userPreferences as $mailTypeId => $mailSubscription) {
if ($mailSubscription['is_subscribed'] === $parsedTypeValues[$mailTypeId]['is_subscribed']) {
foreach ($parsedTypeValues as $mailTypeId => $values) {
$isSubscribed = $userPreferences[$mailTypeId]['is_subscribed'] ?? false;
if ($isSubscribed === $parsedTypeValues[$mailTypeId]['is_subscribed']) {
continue;
}
$request = (new MailSubscribeRequest())
Expand Down

0 comments on commit 073df55

Please sign in to comment.