Skip to content

Commit cec0eb1

Browse files
committed
MessageDataLoaderTest
1 parent e7f9eca commit cec0eb1

File tree

4 files changed

+52
-66
lines changed

4 files changed

+52
-66
lines changed

src/Domain/Configuration/Service/Provider/DefaultConfigProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,15 @@ private function init(): void
559559
],
560560
'PoweredByImage' => [
561561
'value' => '<p class="poweredby" style="text-align:center"><a href="https://www.phplist.com/poweredby?utm_source=pl&amp;utm_medium=poweredlocalimg&amp;utm_campaign=phpList" title="visit the phpList website"><img src="images/power-phplist.png" title="powered by phpList version , &copy; phpList ltd" alt="powered by phpList , &copy; phpList ltd" border="0"/></a></p>',
562-
'description' => 'logo/image ndicates that emails are sent by phpList',
563-
'type' => 'string',
562+
'description' => 'logo/image indicates that emails are sent by phpList',
563+
'type' => 'textarea',
564564
'allowempty' => false,
565565
'category' => 'general',
566566
],
567567
'PoweredByText' => [
568568
'value' => '<div style="clear: both; font-family: arial, verdana, sans-serif; font-size: 8px; font-variant: small-caps; font-weight: normal; padding: 2px; padding-left:10px;padding-top:20px;">powered by <a href="https://www.phplist.com/poweredby?utm_source=download&amp;utm_medium=poweredtxt&amp;utm_campaign=phpList" target="_blank" title="powered by phpList version, &copy; phpList ltd">phpList</a></div>',
569569
'description' => 'text indicates that emails are sent by phpList',
570-
'type' => 'string',
570+
'type' => 'textarea',
571571
'allowempty' => false,
572572
'category' => 'general',
573573
],

src/Domain/Messaging/Service/Manager/TemplateImageManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function delete(TemplateImage $templateImage): void
9696
$this->templateImageRepository->remove($templateImage);
9797
}
9898

99-
public function parseLogoPlaceholders($content)
99+
public function parseLogoPlaceholders(string $content): string
100100
{
101101
//# replace Logo placeholders
102102
preg_match_all('/\[LOGO\:?(\d+)?\]/', $content, $logoInstances);

src/Domain/Messaging/Service/MessageDataLoader.php

Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
class MessageDataLoader
1414
{
15+
private const AS_FORMAT_FIELDS = ['astext', 'ashtml', 'astextandhtml', 'aspdf', 'astextandpdf'];
16+
private const SCHEDULE_FIELDS = ['embargo', 'repeatuntil', 'requeueuntil'];
17+
1518
public function __construct(
1619
private readonly ConfigProvider $configProvider,
1720
private readonly MessageDataRepository $messageDataRepository,
@@ -28,63 +31,39 @@ public function __invoke(Message $message): array
2831
$finishSending = time() + $this->defaultMessageAge;
2932

3033
$messageData = [
31-
'template' => $this->configProvider->getValue(ConfigOption::DefaultMessageTemplate),
32-
'sendformat' => 'HTML',
33-
'message' => '',
34+
'template' => $this->configProvider->getValue(ConfigOption::DefaultMessageTemplate),
35+
'sendformat' => 'HTML',
36+
'message' => '',
3437
'forwardmessage' => '',
35-
'textmessage' => '',
36-
'rsstemplate' => '',
37-
'embargo' => [
38-
'year' => date('Y'),
39-
'month' => date('m'),
40-
'day' => date('d'),
41-
'hour' => date('H'),
42-
'minute' => date('i'),
43-
],
38+
'textmessage' => '',
39+
'rsstemplate' => '',
40+
'embargo' => $this->getDateArray(),
4441
'repeatinterval' => 0,
45-
'repeatuntil' => [
46-
'year' => date('Y'),
47-
'month' => date('m'),
48-
'day' => date('d'),
49-
'hour' => date('H'),
50-
'minute' => date('i'),
51-
],
42+
'repeatuntil' => $this->getDateArray(),
5243
'requeueinterval' => 0,
53-
'requeueuntil' => [
54-
'year' => date('Y'),
55-
'month' => date('m'),
56-
'day' => date('d'),
57-
'hour' => date('H'),
58-
'minute' => date('i'),
59-
],
60-
'finishsending' => [
61-
'year' => date('Y', $finishSending),
62-
'month' => date('m', $finishSending),
63-
'day' => date('d', $finishSending),
64-
'hour' => date('H', $finishSending),
65-
'minute' => date('i', $finishSending),
66-
],
67-
'fromfield' => '',
68-
'subject' => '',
44+
'requeueuntil' => $this->getDateArray(),
45+
'finishsending' => $this->getDateArray($finishSending),
46+
'fromfield' => '',
47+
'subject' => '',
6948
'forwardsubject' => '',
70-
'footer' => $this->configProvider->getValue(ConfigOption::MessageFooter),
71-
'forwardfooter' => $this->configProvider->getValue(ConfigOption::ForwardFooter),
72-
'status' => '',
73-
'tofield' => '',
74-
'replyto' => '',
75-
'targetlist' => [],
49+
'footer' => $this->configProvider->getValue(ConfigOption::MessageFooter),
50+
'forwardfooter' => $this->configProvider->getValue(ConfigOption::ForwardFooter),
51+
'status' => '',
52+
'tofield' => '',
53+
'replyto' => '',
54+
'targetlist' => [],
7655
'criteria_match' => '',
77-
'sendurl' => '',
78-
'sendmethod' => 'inputhere',
79-
'testtarget' => '',
80-
'notify_start' => $this->configProvider->getValue(ConfigOption::NotifyStartDefault),
81-
'notify_end' => $this->configProvider->getValue(ConfigOption::NotifyEndDefault),
82-
'google_track' => filter_var(
56+
'sendurl' => '',
57+
'sendmethod' => 'inputhere',
58+
'testtarget' => '',
59+
'notify_start' => $this->configProvider->getValue(ConfigOption::NotifyStartDefault),
60+
'notify_end' => $this->configProvider->getValue(ConfigOption::NotifyEndDefault),
61+
'google_track' => filter_var(
8362
value: $this->configProvider->getValue(ConfigOption::AlwaysAddGoogleTracking),
8463
filter: FILTER_VALIDATE_BOOL
8564
),
86-
'excludelist' => [],
87-
'sentastest' => 0,
65+
'excludelist' => [],
66+
'sentastest' => 0,
8867
];
8968

9069
$nonEmptyFields = $this->messageRepository->getNonEmptyFields($message->getId());
@@ -98,26 +77,23 @@ public function __invoke(Message $message): array
9877
foreach ($storedMessageData as $storedMessageDatum) {
9978
if (str_starts_with($storedMessageDatum->getData(), 'SER:')) {
10079
$unserialized = unserialize(substr($storedMessageDatum->getData(), 4));
101-
$data = array_walk_recursive($unserialized, 'stripslashes');
80+
array_walk_recursive($unserialized, function (&$val) {
81+
$val = stripslashes($val);
82+
});
83+
84+
$data = $unserialized;
10285
} else {
10386
$data = stripslashes($storedMessageDatum->getData());
10487
}
105-
if (!in_array($storedMessageDatum->getName(), ['astext', 'ashtml', 'astextandhtml', 'aspdf', 'astextandpdf']))
106-
{
88+
if (!in_array($storedMessageDatum->getName(), self::AS_FORMAT_FIELDS)) {
10789
//# don't overwrite counters in the message table from the data table
10890
$messageData[stripslashes($storedMessageDatum->getName())] = $data;
10991
}
11092
}
11193

112-
foreach (['embargo', 'repeatuntil', 'requeueuntil'] as $dateField) {
94+
foreach (self::SCHEDULE_FIELDS as $dateField) {
11395
if (!is_array($messageData[$dateField])) {
114-
$messageData[$dateField] = [
115-
'year' => date('Y'),
116-
'month' => date('m'),
117-
'day' => date('d'),
118-
'hour' => date('H'),
119-
'minute' => date('i'),
120-
];
96+
$messageData[$dateField] = $this->getDateArray();
12197
}
12298
}
12399

@@ -150,7 +126,6 @@ public function __invoke(Message $message): array
150126
} elseif (strpos($messageData['fromfield'], ' ')) {
151127
// if there is a space, we need to add the email
152128
$messageData['fromname'] = $messageData['fromfield'];
153-
// $cached[$messageid]["fromemail"] = "listmaster@$domain";
154129
$messageData['fromemail'] = $defaultFrom;
155130
} else {
156131
$messageData['fromemail'] = $defaultFrom;
@@ -197,4 +172,15 @@ public function __invoke(Message $message): array
197172

198173
return $messageData;
199174
}
175+
176+
private function getDateArray(?int $timestamp = null): array
177+
{
178+
return [
179+
'year' => date('Y', $timestamp),
180+
'month' => date('m', $timestamp),
181+
'day' => date('d', $timestamp),
182+
'hour' => date('H', $timestamp),
183+
'minute' => date('i', $timestamp),
184+
];
185+
}
200186
}

src/Domain/Messaging/Service/MessagePrecacheService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function precacheMessage(Message $campaign, $loadedMessageData, ?bool $fo
6464
$messagePrecacheDto->replyToEmail = $replyToEmail;
6565
// make sure there are no quotes around the name
6666
$messagePrecacheDto->replyToName = str_replace('"', '', ltrim(rtrim($loadedMessageData['replyto'])));
67-
} elseif (strpos($loadedMessageData['replyto'], ' ')) {
67+
} elseif (str_contains($loadedMessageData['replyto'], ' ')) {
6868
// if there is a space, we need to add the email
6969
$messagePrecacheDto->replyToName = $loadedMessageData['replyto'];
7070
$messagePrecacheDto->replyToEmail = "listmaster@$domain";

0 commit comments

Comments
 (0)