Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/services/mappers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ services:
PhpList\Core\Domain\Subscription\Service\CsvToDtoImporter:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Messaging\Service\Mapper\DefaultTemplateMapper:
autowire: true
autoconfigure: true
6 changes: 5 additions & 1 deletion config/services/messenger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ services:
resource: '../../src/Domain/Subscription/MessageHandler'
tags: [ 'messenger.message_handler' ]

PhpList\Core\Domain\Messaging\MessageHandler\CampaignProcessorMessageHandler:
PhpList\Core\Domain\Messaging\MessageHandler\CampaignProcessor\CampaignProcessorMessageHandler:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Messaging\MessageHandler\CampaignProcessor\TestCampaignProcessorMessageHandler:
autowire: true
autoconfigure: true
37 changes: 14 additions & 23 deletions config/services/resolvers.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
services:
_defaults:
autowire: true
autoconfigure: true

_instanceof:
PhpList\Core\Domain\Configuration\Service\Placeholder\PlaceholderValueResolverInterface:
tags: ['phplist.placeholder_resolver']
PhpList\Core\Domain\Configuration\Service\Placeholder\PatternValueResolverInterface:
tags: ['phplist.pattern_resolver']
PhpList\Core\Domain\Configuration\Service\Placeholder\SupportingPlaceholderResolverInterface:
tags: ['phplist.supporting_placeholder_resolver']

PhpList\Core\Domain\Subscription\Service\Resolver\AttributeValueResolver:
arguments:
$providers:
Expand All @@ -14,26 +26,5 @@ services:
arguments:
- !tagged_iterator { tag: 'phplist.bounce_action_handler' }

PhpList\Core\Domain\Configuration\Service\Placeholder\UnsubscribeUrlValueResolver:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Configuration\Service\Placeholder\ConfirmationUrlValueResolver:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Configuration\Service\Placeholder\PreferencesUrlValueResolver:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Configuration\Service\Placeholder\SubscribeUrlValueResolver:
autowire: true
autoconfigure: true

_instanceof:
PhpList\Core\Domain\Configuration\Service\Placeholder\PlaceholderValueResolverInterface:
tags: ['phplist.placeholder_resolver']
PhpList\Core\Domain\Configuration\Service\Placeholder\PatternValueResolverInterface:
tags: [ 'phplist.pattern_resolver' ]
PhpList\Core\Domain\Configuration\Service\Placeholder\SupportingPlaceholderResolverInterface:
tags: [ 'phplist.supporting_placeholder_resolver' ]
PhpList\Core\Domain\Configuration\Service\Placeholder\:
resource: '../../src/Domain/Configuration/Service/Placeholder/*'
8 changes: 4 additions & 4 deletions public/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
DirectoryIndex index.php

# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
Expand Down Expand Up @@ -46,23 +46,23 @@ DirectoryIndex app.php
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Rewrite all other queries to the front controller.
RewriteRule ^ %{ENV:BASE}/app.php [L]
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
RedirectMatch 302 ^/$ /index.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
20 changes: 20 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use PhpList\Core\Core\Bootstrap;
use PhpList\Core\Core\Environment;

require dirname(__DIR__) . '/vendor/autoload.php';

$environment = $_ENV['APP_ENV'] ?? $_SERVER['APP_ENV'] ?? getenv('APP_ENV') ?: Environment::PRODUCTION;

$bootstrap = Bootstrap::getInstance();
if ($environment !== Environment::PRODUCTION) {
$bootstrap->ensureDevelopmentOrTestingEnvironment();
}

$bootstrap
->setEnvironment($environment)
->configure()
->dispatch();
26 changes: 9 additions & 17 deletions src/Bounce/Service/Manager/BounceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,13 @@

class BounceManager
{
private BounceRepository $bounceRepository;
private UserMessageBounceRepository $userMessageBounceRepo;
private EntityManagerInterface $entityManager;
private LoggerInterface $logger;
private TranslatorInterface $translator;

public function __construct(
BounceRepository $bounceRepository,
UserMessageBounceRepository $userMessageBounceRepo,
EntityManagerInterface $entityManager,
LoggerInterface $logger,
TranslatorInterface $translator,
private readonly BounceRepository $bounceRepository,
private readonly UserMessageBounceRepository $userMessageBounceRepo,
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger,
private readonly TranslatorInterface $translator,
) {
$this->bounceRepository = $bounceRepository;
$this->userMessageBounceRepo = $userMessageBounceRepo;
$this->entityManager = $entityManager;
$this->logger = $logger;
$this->translator = $translator;
}

public function create(
Expand Down Expand Up @@ -93,7 +82,10 @@ public function linkUserMessageBounce(
int $subscriberId,
?int $messageId = -1
): UserMessageBounce {
$userMessageBounce = new UserMessageBounce($bounce->getId(), new DateTime($date->format('Y-m-d H:i:s')));
$userMessageBounce = new UserMessageBounce(
bounceId: $bounce->getId(),
createdAt: new DateTime($date->format('Y-m-d H:i:s'))
);
$userMessageBounce->setUserId($subscriberId);
$userMessageBounce->setMessageId($messageId);

Expand Down
16 changes: 15 additions & 1 deletion src/DependencyInjection/PhpListCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@

class PhpListCoreExtension extends Extension
{
private array $configFiles = [
'builders.yml',
'commands.yml',
'managers.yml',
'mappers.yml',
'messengers.yml',
'processors.yml',
'providers.yml',
'repositories.yml',
'resolvers.yml',
'services.yml',
'validators.yml',
];

public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config/services'));

// Load core service definitions if present (keep optional to avoid breaking consumers)
foreach (['services.yml', 'builders.yml', 'managers.yml'] as $file) {
foreach ($this->configFiles as $file) {
$path = __DIR__ . '/../../config/services/' . $file;
if (is_file($path) && is_readable($path)) {
$loader->load($file);
Expand Down
16 changes: 8 additions & 8 deletions src/Domain/Analytics/Service/LinkTrackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpList\Core\Domain\Analytics\Service;

use Doctrine\ORM\EntityManagerInterface;
use PhpList\Core\Core\ParameterProvider;
use PhpList\Core\Domain\Analytics\Exception\MissingMessageIdException;
use PhpList\Core\Domain\Analytics\Model\LinkTrack;
Expand All @@ -12,13 +13,11 @@

class LinkTrackService
{
private LinkTrackRepository $linkTrackRepository;
private ParameterProvider $paramProvider;

public function __construct(LinkTrackRepository $linkTrackRepository, ParameterProvider $paramProvider)
{
$this->linkTrackRepository = $linkTrackRepository;
$this->paramProvider = $paramProvider;
public function __construct(
private readonly LinkTrackRepository $linkTrackRepository,
private readonly ParameterProvider $paramProvider,
private readonly EntityManagerInterface $entityManager,
) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

public function getUrlById(int $id): ?string
Expand Down Expand Up @@ -58,7 +57,6 @@ public function extractAndSaveLinks(MessagePrecacheDto $content, int $userId, ?i
$links = array_unique($links);

$savedLinks = [];

foreach ($links as $url) {
$existingLinkTrack = $this->linkTrackRepository->findByUrlUserIdAndMessageId($url, $userId, $messageId);
if ($existingLinkTrack !== null) {
Expand All @@ -74,6 +72,8 @@ public function extractAndSaveLinks(MessagePrecacheDto $content, int $userId, ?i
$savedLinks[] = $linkTrack;
}

$this->entityManager->flush();

return $savedLinks;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Domain/Common/RemotePageFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ public function __invoke(string $url, array $userData): string

if (!empty($content)) {
$content = $this->htmlUrlRewriter->addAbsoluteResources($content, $url);
$this->eventLogManager->log(page: 'unknown page', entry:'Fetching '.$url.' success');
$this->eventLogManager->log(page: 'unknown page', entry: 'Fetching ' . $url . ' success');

$caches = $this->urlCacheRepository->getByUrl($url);
foreach ($caches as $cache) {
$this->entityManager->remove($cache);
}
$urlCache = (new UrlCache())->setUrl($url)->setContent($content)->setLastModified($lastModified);
$urlCache = (new UrlCache())
->setUrl($url)
->setContent($content)
->setLastModified($lastModified);
$this->urlCacheRepository->persist($urlCache);

$this->cache->set($cacheKey, [
Expand Down
59 changes: 55 additions & 4 deletions src/Domain/Configuration/Service/MessagePlaceholderProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ public function process(
name: 'ORGANIZATION_NAME',
resolver: fn(PlaceholderContext $ctx) => $this->config->getValue(ConfigOption::OrganisationName) ?? ''
);

foreach ($this->placeholderResolvers as $placeholderResolver) {
$resolver->register($placeholderResolver->name(), $placeholderResolver);
}

$this->registerNestedResolvers($resolver);

foreach ($this->patternResolvers as $patternResolver) {
$resolver->registerPattern($patternResolver->pattern(), $patternResolver);
Expand Down Expand Up @@ -136,4 +134,57 @@ private function registerAttributeResolvers(
);
}
}

private function maskFooterPlaceholders(string $value, array &$placeholderMap): string
{
$placeholderMap = [];
$index = 0;

return preg_replace_callback(
'/\[FOOTER(?:%%[^\]]+)?\]/i',
function (array $matches) use (&$placeholderMap, &$index): string {
$token = sprintf('__PHPLIST_FOOTER_TOKEN_%d__', $index++);
$placeholderMap[$token] = $matches[0];

return $token;
},
$value
) ?? $value;
}

/** @param array<string, string> $placeholderMap */
private function restoreFooterPlaceholders(string $value, array $placeholderMap): string
{
if ($placeholderMap === []) {
return $value;
}

return strtr($value, $placeholderMap);
}

private function registerNestedResolvers(PlaceholderResolver $resolver): void
{
foreach ($this->placeholderResolvers as $placeholderResolver) {
if (strtoupper($placeholderResolver->name()) !== 'FOOTER') {
$resolver->register($placeholderResolver->name(), $placeholderResolver);
continue;
}

$resolver->register(
$placeholderResolver->name(),
function (PlaceholderContext $ctx) use ($placeholderResolver, $resolver): string {
$footer = (string) $placeholderResolver($ctx);
if (!str_contains($footer, '[')) {
return $footer;
}

$placeholderMap = [];
$maskedFooter = $this->maskFooterPlaceholders($footer, $placeholderMap);
$resolvedFooter = $resolver->resolve($maskedFooter, $ctx);

return $this->restoreFooterPlaceholders($resolvedFooter, $placeholderMap);
}
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use PhpList\Core\Domain\Configuration\Model\ConfigOption;
use PhpList\Core\Domain\Configuration\Service\Provider\ConfigProvider;
use PhpList\Core\Domain\Configuration\Model\Dto\PlaceholderContext;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

final class FooterValueResolver implements PlaceholderValueResolverInterface
{
public function __construct(
private readonly ConfigProvider $config,
private readonly bool $forwardAlternativeContent,
#[Autowire('%messaging.forward_alternative_content%')] private readonly bool $forwardAlternativeContent,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use PhpList\Core\Domain\Configuration\Model\Dto\PlaceholderContext;
use PhpList\Core\Domain\Subscription\Repository\SubscriberListRepository;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Contracts\Translation\TranslatorInterface;

final class ListsValueResolver implements PlaceholderValueResolverInterface
{
public function __construct(
private readonly SubscriberListRepository $subscriberListRepository,
private readonly TranslatorInterface $translator,
private readonly bool $showPrivateLists = false,
#[Autowire('%app.preference_page_show_private_lists%')] private readonly bool $showPrivateLists = false,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use PhpList\Core\Domain\Configuration\Model\ConfigOption;
use PhpList\Core\Domain\Configuration\Service\Provider\ConfigProvider;
use PhpList\Core\Domain\Configuration\Model\Dto\PlaceholderContext;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

final class SignatureValueResolver implements PlaceholderValueResolverInterface
{
public function __construct(
private readonly ConfigProvider $config,
private readonly bool $emailTextCredits = false,
#[Autowire('%messaging.email_text_credits%')] private readonly bool $emailTextCredits = false,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Domain/Identity/Model/AdminAttributeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class AdminAttributeValue implements DomainModel
{
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: AdminAttributeDefinition::class)]
#[ORM\JoinColumn(name: 'adminattributeid', referencedColumnName: 'id', nullable: false)]
#[ORM\JoinColumn(name: 'adminattributeid', referencedColumnName: 'id')]
private AdminAttributeDefinition $attributeDefinition;

#[ORM\Id]
#[ORM\ManyToOne(targetEntity: Administrator::class)]
#[ORM\JoinColumn(name: 'adminid', referencedColumnName: 'id', nullable: false)]
#[ORM\JoinColumn(name: 'adminid', referencedColumnName: 'id')]
private Administrator $administrator;

#[ORM\Column(name: 'value', type: 'string', length: 255, nullable: true)]
Expand Down
Loading
Loading