Skip to content

Commit 12b8e90

Browse files
committed
Merge branch 'release/40.0.0'
2 parents 69f9ccd + 76b8121 commit 12b8e90

14 files changed

Lines changed: 246 additions & 151 deletions

File tree

‎Classes/Domain/Model/Company.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ public function getCountryCodeUpper(): string
133133
public function getCountry(): string
134134
{
135135
$countryService = GeneralUtility::makeInstance(CountryService::class);
136-
return $countryService->getPropertyByAlpha2($this->getCountryCode());
136+
if (strlen($this->getCountryCode()) === 2) {
137+
return $countryService->getPropertyByAlpha2($this->getCountryCode());
138+
}
139+
return '';
137140
}
138141

139142
public function setCountryCode(string $countryCode): self

‎Classes/Domain/Repository/LinklistenerRepository.php‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,20 @@ protected function extendLogicalAndWithFilterConstraintsForCrdate(
4141
QueryInterface $query,
4242
array $logicalAnd
4343
): array {
44-
$logicalAnd[] = $query->greaterThan('linkclicks.crdate', $filter->getStartTimeForFilter());
45-
$logicalAnd[] = $query->lessThan('linkclicks.crdate', $filter->getEndTimeForFilter());
44+
$or = [
45+
$query->logicalAnd(
46+
$query->greaterThan('linkclicks.crdate', $filter->getStartTimeForFilter()),
47+
$query->lessThan('linkclicks.crdate', $filter->getEndTimeForFilter()),
48+
)
49+
];
50+
if ($filter->isTimeFromOrTimeToSet() === false) { // add unused linklisteners (without clicks) per default
51+
$or[] = $query->logicalAnd(
52+
$query->equals('linkclicks.uid', null),
53+
$query->greaterThan('crdate', $filter->getStartTimeForFilter()),
54+
$query->lessThan('crdate', $filter->getEndTimeForFilter())
55+
);
56+
}
57+
$logicalAnd[] = $query->logicalOr(...$or);
4658
return $logicalAnd;
4759
}
4860

@@ -74,7 +86,11 @@ protected function extendWithExtendedFilterQuery(
7486
if ($filter->isCategoryScoringSet()) {
7587
$logicalAnd[] = $query->equals('category', $filter->getCategoryScoring());
7688
}
77-
$logicalAnd[] = $query->in('linkclicks.site', $filter->getSitesForFilter());
89+
90+
$logicalAnd[] = $query->logicalOr(
91+
$query->equals('linkclicks', 0),
92+
$query->in('linkclicks.site', $filter->getSitesForFilter())
93+
);
7894
return $logicalAnd;
7995
}
8096
}

‎Classes/Domain/Service/CountryService.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,10 @@ public function extendAlpha2ArrayWithCountryNames(array $countries): array
13071307
{
13081308
$names = [];
13091309
foreach (array_keys($countries) as $alpha2) {
1310+
if (strlen($alpha2) !== 2) {
1311+
continue;
1312+
}
1313+
$alpha2 = strtoupper($alpha2);
13101314
$names[$alpha2] = $this->getPropertyByAlpha2($alpha2);
13111315
}
13121316
return $names;

‎Classes/Domain/Service/Email/SendAssetEmail4LinkService.php‎

Lines changed: 35 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
use In2code\Lux\Utility\StringUtility;
1313
use In2code\Lux\Utility\UrlUtility;
1414
use Psr\EventDispatcher\EventDispatcherInterface;
15-
use TYPO3\CMS\Core\Mail\MailMessage;
15+
use Symfony\Component\Mime\Address;
16+
use TYPO3\CMS\Core\Http\ServerRequest;
17+
use TYPO3\CMS\Core\Mail\FluidEmail;
18+
use TYPO3\CMS\Core\Mail\MailerInterface;
1619
use TYPO3\CMS\Core\Resource\File;
1720
use TYPO3\CMS\Core\Resource\Security\FileNameValidator;
1821
use TYPO3\CMS\Core\Resource\StorageRepository;
1922
use TYPO3\CMS\Core\Utility\GeneralUtility;
2023
use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
21-
use TYPO3\CMS\Fluid\View\StandaloneView;
2224

2325
class SendAssetEmail4LinkService
2426
{
@@ -44,57 +46,46 @@ public function __construct(Visitor $visitor, array $settings)
4446
$this->eventDispatcher = GeneralUtility::makeInstance(EventDispatcherInterface::class);
4547
}
4648

47-
/**
48-
* @param string $href
49-
* @param File|null $file
50-
* @return void
51-
* @throws InvalidConfigurationTypeException
52-
*/
5349
public function sendMail(string $href, ?File $file): void
5450
{
5551
$this->href = $href;
5652
$this->file = $file;
5753
if ($this->visitor->isNotBlacklisted()) {
5854
if ($this->isActivatedAndAllowed()) {
5955
$this->send();
60-
$this->eventDispatcher->dispatch(
61-
GeneralUtility::makeInstance(LogEmail4linkSendEmailEvent::class, $this->visitor, $this->href)
62-
);
56+
$this->eventDispatcher->dispatch(new LogEmail4linkSendEmailEvent($this->visitor, $this->href));
6357
} else {
64-
$this->eventDispatcher->dispatch(
65-
GeneralUtility::makeInstance(LogEmail4linkSendEmailFailedEvent::class, $this->visitor, $this->href)
66-
);
58+
$this->eventDispatcher->dispatch(new LogEmail4linkSendEmailFailedEvent($this->visitor, $this->href));
6759
}
6860
}
6961
}
7062

71-
/**
72-
* @return void
73-
* @throws InvalidConfigurationTypeException
74-
*/
7563
protected function send(): void
7664
{
77-
$message = GeneralUtility::makeInstance(MailMessage::class);
78-
$message
79-
->setTo([$this->visitor->getEmail() => 'Receiver'])
80-
->setFrom($this->getSender())
81-
->setSubject($this->getSubject())
82-
->attachFromPath(GeneralUtility::getFileAbsFileName(UrlUtility::convertToRelative($this->href)))
83-
->html($this->getMailTemplate());
84-
$this->setBcc($message);
85-
$this->eventDispatcher->dispatch(
86-
GeneralUtility::makeInstance(SetAssetEmail4LinkEvent::class, $this->visitor, $message, $this->href)
65+
/** @var SetAssetEmail4LinkEvent $event */
66+
$event = $this->eventDispatcher->dispatch(
67+
new SetAssetEmail4LinkEvent($this->visitor, $this->href, $this->file)
8768
);
88-
$message->send();
69+
$mail = GeneralUtility::makeInstance(FluidEmail::class);
70+
$mail
71+
->to($this->visitor->getEmail())
72+
->from($this->getSender())
73+
->format(FluidEmail::FORMAT_BOTH)
74+
->setTemplate('Email4Link')
75+
->assignMultiple([
76+
'href' => $event->getHref(),
77+
'visitor' => $event->getVisitor(),
78+
'file' => $event->getFile(),
79+
'request' => $this->getRequest(),
80+
])
81+
->attachFromPath(GeneralUtility::getFileAbsFileName(UrlUtility::convertToRelative($event->getHref())));
82+
$this->setBcc($mail);
83+
GeneralUtility::makeInstance(MailerInterface::class)->send($mail);
8984
}
9085

91-
/**
92-
* @param MailMessage $message
93-
* @return void
94-
*/
95-
protected function setBcc(MailMessage $message): void
86+
protected function setBcc(FluidEmail $mail): void
9687
{
97-
if (!empty($this->settings['identification']['email4link']['mail']['bccEmail'])) {
88+
if (($this->settings['identification']['email4link']['mail']['bccEmail'] ?? '') !== '') {
9889
$bcc = [];
9990
$emails = GeneralUtility::trimExplode(
10091
',',
@@ -103,55 +94,19 @@ protected function setBcc(MailMessage $message): void
10394
);
10495
foreach ($emails as $email) {
10596
if (GeneralUtility::validEmail($email)) {
106-
$bcc = array_merge($bcc, [$email => 'Receiver']);
97+
$bcc[] = new Address($email);
10798
}
10899
}
109-
$message->setBcc($bcc);
100+
$mail->bcc(...$bcc);
110101
}
111102
}
112103

113-
/**
114-
* @return string
115-
* @throws InvalidConfigurationTypeException
116-
*/
117-
protected function getMailTemplate(): string
118-
{
119-
$mailTemplatePath = $this->configurationService->getTypoScriptSettingsByPath(
120-
'identification.email4link.mail.mailTemplate'
121-
);
122-
$standaloneView = GeneralUtility::makeInstance(StandaloneView::class);
123-
$standaloneView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($mailTemplatePath));
124-
$standaloneView->assignMultiple([
125-
'href' => $this->href,
126-
'visitor' => $this->visitor,
127-
'file' => $this->file,
128-
]);
129-
return $standaloneView->render();
130-
}
131-
132-
/**
133-
* @return array
134-
* @throws InvalidConfigurationTypeException
135-
*/
136-
protected function getSender(): array
104+
protected function getSender(): Address
137105
{
138106
$configuration = $this->configurationService->getTypoScriptSettingsByPath('identification.email4link.mail');
139-
return [$configuration['fromEmail'] => $configuration['fromName']];
107+
return new Address($configuration['fromEmail'], $configuration['fromName']);
140108
}
141109

142-
/**
143-
* @return string
144-
* @throws InvalidConfigurationTypeException
145-
*/
146-
protected function getSubject(): string
147-
{
148-
return $this->configurationService->getTypoScriptSettingsByPath('identification.email4link.mail.subject');
149-
}
150-
151-
/**
152-
* @return bool
153-
* @throws InvalidConfigurationTypeException
154-
*/
155110
protected function isActivatedAndAllowed(): bool
156111
{
157112
return $this->isEnabled()
@@ -162,20 +117,12 @@ protected function isActivatedAndAllowed(): bool
162117
&& $this->visitor->isIdentified();
163118
}
164119

165-
/**
166-
* @return bool
167-
* @throws InvalidConfigurationTypeException
168-
*/
169120
protected function isEnabled(): bool
170121
{
171122
$path = 'identification.email4link.mail._enable';
172123
return $this->configurationService->getTypoScriptSettingsByPath($path) === '1';
173124
}
174125

175-
/**
176-
* @return bool
177-
* @throws InvalidConfigurationTypeException
178-
*/
179126
protected function isAllowedFileExtension(): bool
180127
{
181128
$allowed = false;
@@ -221,4 +168,9 @@ protected function isFileExisting(): bool
221168
{
222169
return file_exists(GeneralUtility::getFileAbsFileName(UrlUtility::convertToRelative($this->href)));
223170
}
171+
172+
protected function getRequest(): ?ServerRequest
173+
{
174+
return $GLOBALS['TYPO3_REQUEST'] ?? null;
175+
}
224176
}

‎Classes/Events/SetAssetEmail4LinkEvent.php‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,41 @@
44
namespace In2code\Lux\Events;
55

66
use In2code\Lux\Domain\Model\Visitor;
7-
use TYPO3\CMS\Core\Mail\MailMessage;
7+
use TYPO3\CMS\Core\Resource\File;
88

99
final class SetAssetEmail4LinkEvent
1010
{
11-
protected Visitor $visitor;
12-
protected MailMessage $mailMessage;
11+
public function __construct(
12+
private readonly Visitor $visitor,
13+
private string $href,
14+
private File $file
15+
) {
16+
}
1317

14-
protected string $href = '';
18+
public function getVisitor(): Visitor
19+
{
20+
return $this->visitor;
21+
}
1522

16-
public function __construct(Visitor $visitor, MailMessage $mailMessage, string $href)
23+
public function getHref(): string
1724
{
18-
$this->visitor = $visitor;
19-
$this->mailMessage = $mailMessage;
20-
$this->href = $href;
25+
return $this->href;
2126
}
2227

23-
public function getVisitor(): Visitor
28+
public function setHref(string $href): self
2429
{
25-
return $this->visitor;
30+
$this->href = $href;
31+
return $this;
2632
}
2733

28-
public function getMailMessage(): MailMessage
34+
public function getFile(): File
2935
{
30-
return $this->mailMessage;
36+
return $this->file;
3137
}
3238

33-
public function getHref(): string
39+
public function setFile(File $file): self
3440
{
35-
return $this->href;
41+
$this->file = $file;
42+
return $this;
3643
}
3744
}

‎Configuration/TypoScript/Lux/02_IdentificationConfiguration.typoscript‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,14 @@ lib.lux.settings {
129129
# Enable/Disable
130130
_enable = 1
131131

132-
# Template file for mail with asset attachment
133-
mailTemplate = EXT:lux/Resources/Private/Templates/Mail/Email4LinkMail.html
134-
135-
# Mail subject
136-
subject = Your requested asset
137-
138132
# From name for mail to visitor
139133
fromName = {$plugin.tx_lux.settings.email.defaultSenderName}
140134

141135
# From email for mail to visitor
142136
fromEmail = {$plugin.tx_lux.settings.email.defaultSenderEmail}
143137

144138
# Send a blind copy to any receivers (can be a commaseparated email list)
145-
bccEmail =
139+
bccEmail = sandra@in2code.de
146140

147141
# Allow only files with this extensions
148142
allowedFileExtensions = pdf,txt,doc,docx,xls,xlsx,ppt,pptx,jpg,png,zip

0 commit comments

Comments
 (0)