-
Notifications
You must be signed in to change notification settings - Fork 31
Feat/user personalizer #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ref/campaign-processing
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,8 @@ parameters: | |
| env(APP_DEV_EMAIL): '[email protected]' | ||
| app.powered_by_phplist: '%%env(APP_POWERED_BY_PHPLIST)%%' | ||
| env(APP_POWERED_BY_PHPLIST): '0' | ||
| app.preference_page_show_private_lists: '%%env(PREFERENCEPAGE_SHOW_PRIVATE_LISTS)%%' | ||
| env(PREFERENCEPAGE_SHOW_PRIVATE_LISTS): '0' | ||
|
|
||
| # Email configuration | ||
| app.mailer_from: '%%env(MAILER_FROM)%%' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PhpList\Core\Domain\Configuration\Model; | ||
|
|
||
| enum OutputFormat: string | ||
| { | ||
| case Html = 'html'; | ||
| case Text = 'text'; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| namespace PhpList\Core\Domain\Messaging\MessageHandler; | ||
|
|
||
| use PhpList\Core\Domain\Configuration\Model\ConfigOption; | ||
| use PhpList\Core\Domain\Configuration\Model\OutputFormat; | ||
| use PhpList\Core\Domain\Configuration\Service\Provider\ConfigProvider; | ||
| use PhpList\Core\Domain\Configuration\Service\UserPersonalizer; | ||
| use PhpList\Core\Domain\Messaging\Message\SubscriptionConfirmationMessage; | ||
|
|
@@ -20,24 +21,13 @@ | |
| #[AsMessageHandler] | ||
| class SubscriptionConfirmationMessageHandler | ||
| { | ||
| private EmailService $emailService; | ||
| private ConfigProvider $configProvider; | ||
| private LoggerInterface $logger; | ||
| private UserPersonalizer $userPersonalizer; | ||
| private SubscriberListRepository $subscriberListRepository; | ||
|
|
||
| public function __construct( | ||
| EmailService $emailService, | ||
| ConfigProvider $configProvider, | ||
| LoggerInterface $logger, | ||
| UserPersonalizer $userPersonalizer, | ||
| SubscriberListRepository $subscriberListRepository, | ||
| private readonly EmailService $emailService, | ||
| private readonly ConfigProvider $configProvider, | ||
| private readonly LoggerInterface $logger, | ||
| private readonly UserPersonalizer $userPersonalizer, | ||
| private readonly SubscriberListRepository $subscriberListRepository, | ||
| ) { | ||
| $this->emailService = $emailService; | ||
| $this->configProvider = $configProvider; | ||
| $this->logger = $logger; | ||
| $this->userPersonalizer = $userPersonalizer; | ||
| $this->subscriberListRepository = $subscriberListRepository; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -47,14 +37,19 @@ public function __invoke(SubscriptionConfirmationMessage $message): void | |
| { | ||
| $subject = $this->configProvider->getValue(ConfigOption::SubscribeEmailSubject); | ||
| $textContent = $this->configProvider->getValue(ConfigOption::SubscribeMessage); | ||
| $personalizedTextContent = $this->userPersonalizer->personalize($textContent, $message->getUniqueId()); | ||
| $listOfLists = $this->getListNames($message->getListIds()); | ||
| $replacedTextContent = str_replace('[LISTS]', $listOfLists, $personalizedTextContent); | ||
| $replacedTextContent = str_replace('[LISTS]', $listOfLists, $textContent); | ||
|
|
||
| $personalizedTextContent = $this->userPersonalizer->personalize( | ||
| value: $replacedTextContent, | ||
| email: $message->getUniqueId(), | ||
| format: OutputFormat::Text, | ||
| ); | ||
|
Comment on lines
+41
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: [LISTS] replacement conflicts with UserPersonalizer. The flow now replaces The pipeline failure confirms this: The test expects 🔎 Proposed fixRemove the manual $subject = $this->configProvider->getValue(ConfigOption::SubscribeEmailSubject);
$textContent = $this->configProvider->getValue(ConfigOption::SubscribeMessage);
- $listOfLists = $this->getListNames($message->getListIds());
- $replacedTextContent = str_replace('[LISTS]', $listOfLists, $textContent);
-
- $personalizedTextContent = $this->userPersonalizer->personalize(
- value: $replacedTextContent,
+
+ $personalizedTextContent = $this->userPersonalizer->personalize(
+ value: $textContent,
email: $message->getUniqueId(),
format: OutputFormat::Text,
);If you need to ensure the list IDs are available to the personalizer, that should be handled through the subscriber's subscriptions rather than passing them separately. Also applies to: 52-52, 61-61 🧰 Tools🪛 GitHub Actions: phpList Core Build[error] 46-46: Expectation failed for method name is "personalize" when invoked 1 time(s). Parameter 0 for invocation UserPersonalizer::personalize('Hi {{name}}, you subscribed to: ', 'user-123', OutputFormat): string does not match expected value. Expected 'Hi {{name}}, you subscribed to: [LISTS]' but got 'Hi {{name}}, you subscribed to: ' 🤖 Prompt for AI Agents |
||
|
|
||
| $email = (new Email()) | ||
| ->to($message->getEmail()) | ||
| ->subject($subject) | ||
| ->text($replacedTextContent); | ||
| ->text($personalizedTextContent); | ||
|
|
||
| $this->emailService->sendEmail($email); | ||
|
|
||
|
|
@@ -63,14 +58,6 @@ public function __invoke(SubscriptionConfirmationMessage $message): void | |
|
|
||
| private function getListNames(array $listIds): string | ||
| { | ||
| $listNames = []; | ||
| foreach ($listIds as $id) { | ||
| $list = $this->subscriberListRepository->find($id); | ||
| if ($list) { | ||
| $listNames[] = $list->getName(); | ||
| } | ||
| } | ||
|
|
||
| return implode(', ', $listNames); | ||
| return implode(', ', $this->subscriberListRepository->getListNames($listIds)); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: phpList/core
Length of output: 178
🏁 Script executed:
Repository: phpList/core
Length of output: 38
🏁 Script executed:
Repository: phpList/core
Length of output: 117
🏁 Script executed:
Repository: phpList/core
Length of output: 6367
🏁 Script executed:
Repository: phpList/core
Length of output: 595
String-to-boolean conversion will cause incorrect behavior.
The parameter
$preferencePageShowPrivateListsis type-hinted asbool(line 28 of UserPersonalizer.php), but the services configuration passes a string value from parameters.yml.dist. In PHP,(bool)'0'evaluates totrue(non-empty string), notfalse. This means the feature will behave opposite to the intended default—always showing private lists when it should hide them.Use an integer instead of a string in parameters.yml.dist:
Or apply explicit casting in services.yml using
!php/constor a cast operator.🤖 Prompt for AI Agents