Skip to content
Open

Dev #384

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/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ parameters:
env(REST_API_BASE_URL): 'http://api.phplist.local/api/v2'
app.frontend_base_url: '%%env(FRONT_END_BASE_URL)%%'
env(FRONT_END_BASE_URL): 'http://frontend.phplist.local'
parallel_use_with_phplist3: '%%env(parallel_use_with_phplist3)%%'
env(parallel_use_with_phplist3): '0'

# Email configuration
app.mailer_from: '%%env(MAILER_FROM)%%'
Expand All @@ -49,6 +51,8 @@ parameters:
env(SUBSCRIPTION_CONFIRMATION_URL): 'http://api.phplist.local/api/v2/subscription/confirm/'
app.password_reset_url: '%%env(PASSWORD_RESET_URL)%%'
env(PASSWORD_RESET_URL): 'https://example.com/reset/'
app.show_unsubscribe_link: '%%env(SHOW_UNSUBSCRIBELINK)%%'
env(SHOW_UNSUBSCRIBELINK): '1'

# bounce email settings
imap_bounce.email: '%%env(BOUNCE_EMAIL)%%'
Expand Down
2 changes: 2 additions & 0 deletions config/services/processor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ services:
PhpList\Core\Bounce\Service\Processor\UnidentifiedBounceReprocessor: ~

PhpList\Core\Bounce\Service\Processor\BounceDataProcessor: ~

PhpList\Core\Domain\Subscription\Service\SubscribePagePlaceholderProcessor: ~
8 changes: 8 additions & 0 deletions config/services/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ services:
autoconfigure: true
public: true

PhpList\Core\Domain\Subscription\Service\SubscribePageConfigMigrationService:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Subscription\Service\Manager\SubscribePageManager:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Messaging\Service\MessageProcessingPreparator:
autowire: true
autoconfigure: true
Expand Down
Binary file added public/power-phplist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/Domain/Configuration/Model/Dto/CreateConfigDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace PhpList\Core\Domain\Configuration\Model\Dto;

class CreateConfigDto
{
public function __construct(
public readonly string $key,
public readonly string $value,
public readonly bool $editable,
public readonly ?string $type = null,
) {
}
}
10 changes: 10 additions & 0 deletions src/Domain/Configuration/Repository/ConfigRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@
namespace PhpList\Core\Domain\Configuration\Repository;

use PhpList\Core\Domain\Common\Repository\AbstractRepository;
use PhpList\Core\Domain\Configuration\Model\Config;

class ConfigRepository extends AbstractRepository
{
public function findValueByItem(string $name): ?string
{
return $this->findOneBy(['key' => $name])?->getValue();
}

public function findByKey(string $key): ?Config
{
return $this->createQueryBuilder('c')
->where('c.key = :key')
->setParameter('key', $key)
->getQuery()
->getOneOrNullResult();
}
}
57 changes: 42 additions & 15 deletions src/Domain/Configuration/Service/Manager/ConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,84 @@
namespace PhpList\Core\Domain\Configuration\Service\Manager;

use PhpList\Core\Domain\Configuration\Model\Config;
use PhpList\Core\Domain\Configuration\Model\Dto\CreateConfigDto;
use PhpList\Core\Domain\Configuration\Repository\ConfigRepository;
use PhpList\Core\Domain\Configuration\Exception\ConfigNotEditableException;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

class ConfigManager
{
private ConfigRepository $configRepository;

public function __construct(ConfigRepository $configRepository)
{
$this->configRepository = $configRepository;
public function __construct(
private readonly ConfigRepository $configRepository,
#[Autowire('%parallel_use_with_phplist3%')]
private readonly bool $parallelUseWithPhpList3,
) {
}

/**
* Get a configuration item by its key
*/
public function getByItem(string $item): ?Config
public function findByKey(string $item): ?Config
{
return $this->configRepository->findOneBy(['item' => $item]);
return $this->configRepository->findByKey($item);
}

/**
* Get all configuration items
*
* @return Config[]
*/
public function getAll(): array
public function getAllEditable(): array
{
return $this->configRepository->findAll();
$all = $this->configRepository->findAll();

if ($this->parallelUseWithPhpList3) {
$filtered = [];
foreach ($all as $config) {
$key = trim($config->getKey());
if ($key === '' || $config->isEditable() === false) {
continue;
}
// filter legacy config items (WithNamespaces)
if (str_contains($key, ':') === true) {
continue;
}
if (str_starts_with($key, 'lastlanguageupdate-') === true) {
continue;
}
$filtered[] = $config;
}
$all = $filtered;
}

return $all;
}

/**
* Update a configuration item
* @throws ConfigNotEditableException
*/
public function update(Config $config, string $value): void
public function update(Config $config, string $value): Config
{
if (!$config->isEditable()) {
throw new ConfigNotEditableException($config->getKey());
}
$config->setValue($value);

return $config;
}

public function create(string $key, string $value, bool $editable, ?string $type = null): void
public function create(CreateConfigDto $configRequestDto): Config
{
$config = (new Config())
->setKey($key)
->setValue($value)
->setEditable($editable)
->setType($type);
->setKey($configRequestDto->key)
->setValue($configRequestDto->value)
->setEditable($configRequestDto->editable)
->setType($configRequestDto->type);

$this->configRepository->persist($config);

return $config;
}

public function delete(Config $config): void
Expand Down
27 changes: 22 additions & 5 deletions src/Domain/Configuration/Service/Provider/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpList\Core\Domain\Configuration\Model\ConfigOption;
use PhpList\Core\Domain\Configuration\Repository\ConfigRepository;
use Psr\SimpleCache\CacheInterface;
use ValueError;

class ConfigProvider
{
Expand Down Expand Up @@ -71,16 +72,32 @@ public function getValue(ConfigOption $key): ?string
return $this->defaultConfigs->has($key) ? (string) $this->defaultConfigs->get($key)['value'] : null;
}

public function getValueWithNamespace(ConfigOption $key): ?string
public function getValueWithNamespace(ConfigOption|string $key): ?string
{
$full = $this->getValue($key);
if ($key instanceof ConfigOption) {
$full = $this->getValue($key);
$keyValue = $key->value;
} else {
$keyValue = $key;
$cacheKey = 'cfg:' . $keyValue;
$full = $this->cache->get($cacheKey);
if ($full === null) {
$full = $this->configRepository->findValueByItem($keyValue);
$this->cache->set($cacheKey, $full, $this->ttlSeconds);
}
}

if ($full !== null && $full !== '') {
return $full;
}

if (str_contains($key->value, ':')) {
[$parent] = explode(':', $key->value, 2);
$parentKey = ConfigOption::from($parent);
if (str_contains($keyValue, ':')) {
[$parent] = explode(':', $keyValue, 2);
try {
$parentKey = ConfigOption::from($parent);
} catch (ValueError) {
return null;
}

return $this->getValue($parentKey);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Expand Down
11 changes: 7 additions & 4 deletions src/Domain/Messaging/Service/TemplateImageEmbedder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpList\Core\Domain\Common\ExternalImageService;
use PhpList\Core\Domain\Common\Model\ContentTransferEncoding;
use PhpList\Core\Domain\Configuration\Model\ConfigOption;
use PhpList\Core\Domain\Configuration\Model\Dto\CreateConfigDto;
use PhpList\Core\Domain\Configuration\Service\Manager\ConfigManager;
use PhpList\Core\Domain\Configuration\Service\Provider\ConfigProvider;
use PhpList\Core\Domain\Messaging\Model\TemplateImage;
Expand Down Expand Up @@ -133,10 +134,12 @@ private function getFilesystemImage(string $filename): string
if (is_file($candidate['path'])) {
if ($candidate['config'] !== null) {
$this->configManager->create(
ConfigOption::UploadImageRoot->value,
$candidate['config'],
false,
'string'
configRequestDto: new CreateConfigDto(
key: ConfigOption::UploadImageRoot->value,
value: $candidate['config'],
editable: false,
type: 'string'
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#[AsMessageHandler]
class DynamicTableMessageHandler
{

public function __construct(private readonly AbstractSchemaManager $schemaManager)
{
}
Expand Down
16 changes: 16 additions & 0 deletions src/Domain/Subscription/Model/SubscribePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class SubscribePage implements DomainModel, Identity, OwnableInterface
#[ORM\JoinColumn(name: 'owner', referencedColumnName: 'id', nullable: true)]
private ?Administrator $owner = null;

/** @var SubscribePageData[] */
private array $data = [];

public function getId(): ?int
{
return $this->id;
Expand All @@ -50,6 +53,12 @@ public function getOwner(): ?Administrator
return $this->owner;
}

/** @return SubscribePageData[] */
public function getData(): array
{
return $this->data;
}

public function setTitle(string $title): self
{
$this->title = $title;
Expand All @@ -67,4 +76,11 @@ public function setOwner(?Administrator $owner): self
$this->owner = $owner;
return $this;
}

/** @param SubscribePageData[] $data */
public function setData(array $data): self
{
$this->data = $data;
return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private function hydrateOptionsForAll(array $defs): array
foreach ($defs as $def) {
$this->hydrateOptions($def);
}

return $defs;
}

Expand Down Expand Up @@ -81,9 +82,17 @@ public function findOneByName(string $name): ?SubscriberAttributeDefinition
if ($def instanceof SubscriberAttributeDefinition) {
$this->hydrateOptions($def);
}

return $def;
}

public function getByIds(array $ids): array
{
$defs = $this->findBy(['id' => $ids]);

return $this->hydrateOptionsForAll($defs);
}

public function existsByTableName(string $tableName): bool
{
return (bool) $this->createQueryBuilder('s')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ public function getListIdsByMessage(Message $message): array
->getSingleColumnResult();
}

public function getAllActive(): array
/** @return SubscriberList[] */
public function getPublicByIds(array $ids): array
{
return $this->createQueryBuilder('l')
->where('l.active = true')
->where('l.public = true')
->andWhere('l.id IN (:ids)')
->setParameter('ids', $ids)
->getQuery()
->getResult();
}
Expand Down
Loading
Loading