Skip to content

Commit

Permalink
fix for uuid field was not enough
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Apr 21, 2022
1 parent 259be96 commit f319f80
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to this project will be documented in this file.

## [1.21.2] - 2022-04-21
- Fixed: uuid field leads to invalid notification center tokens

## [1.21.1] - 2022-04-21
- Fixed: uuid field leads to invalid notification center tokens

Expand Down
45 changes: 29 additions & 16 deletions classes/EventListener/FormGeneratorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ public function onStoreFormData(array $data, Form $form): array
return $data;
}

public function onProcessFormData(array $submittedData, array $formData, ?array $files, array $labels, Form $form): void
public function onProcessFormData(array &$submittedData, array $formData, ?array $files, array $labels, Form $form): void
{
if (isset($submittedData['uuid']) && Validator::isBinaryUuid($submittedData['uuid'])) {
$submittedData['uuid'] = StringUtil::binToUuid($submittedData['uuid']);
}

if (version_compare(VERSION, '4.7', '>=')) {
if ($form->storeAsSubmission && $form->submissionArchive
&& $form->huhSubAddOptIn && $form->huhSubOptInNotification && isset($submittedData['optInTokenId']))
Expand All @@ -99,25 +103,34 @@ public function onProcessFormData(array $submittedData, array $formData, ?array

public function onSendNotificationMessage(Message $message, array &$tokens, string $language, Gateway $gatewayModel): bool
{
if (version_compare(VERSION, '4.7', '>=')) {
if (!isset($tokens['formconfig_id'])) {
return true;
}
if (isset($tokens['form_uuid']) && Validator::isBinaryUuid($tokens['form_uuid'])) {
$tokens['form_uuid'] = StringUtil::binToUuid($tokens['form_uuid']);
}
if (!isset($tokens['formconfig_id']) || !($tokens['formconfig_storeAsSubmission'] ?? false)) {
return true;
}

if (
!($tokens['formconfig_storeAsSubmission'] ?? false)
|| !($tokens['formconfig_huhSubAddOptIn'] ?? false)
|| !isset($tokens['formconfig_optInIdentifier'])
) {
if (false === json_encode($tokens)) {

return true;
if (Validator::isBinaryUuid($tokens['form_uuid'])) {
$uuid = StringUtil::binToUuid($tokens['form_uuid']);
$tokens['raw_data'] = str_replace($tokens['form_uuid'], $uuid, $tokens['raw_data']);
$tokens['raw_data_filled'] = str_replace($tokens['form_uuid'], $uuid, $tokens['raw_data_filled']);
$tokens['form_uuid'] = $uuid;
}

$tokens['optInToken'] = $tokens['formconfig_optInIdentifier'];
$tokens['optInUrl'] = Environment::get('base').'?token='.$tokens['formconfig_optInIdentifier'];
if (false === json_encode($tokens)) {
System::log(
'The message contained invalid tokens and could not be sent!',
__METHOD__,
TL_ERROR
);
return false;
}
}

if (version_compare(VERSION, '4.7', '>=')) {
if (($tokens['formconfig_huhSubAddOptIn'] ?? false) && isset($tokens['formconfig_optInIdentifier'])) {
$tokens['optInToken'] = $tokens['formconfig_optInIdentifier'];
$tokens['optInUrl'] = Environment::get('base').'?token='.$tokens['formconfig_optInIdentifier'];
}
}

return true;
Expand Down

0 comments on commit f319f80

Please sign in to comment.