Skip to content

Commit

Permalink
feat: add shopware 6.6 compatibility (#59)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominik Mank <[email protected]>
  • Loading branch information
dominikmank and Dominik Mank authored Jan 26, 2024
1 parent 849cdc5 commit 64a5507
Show file tree
Hide file tree
Showing 23 changed files with 115 additions and 200 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- 'main'
- 'feature/6.6-compatibility'
tags-ignore:
- '*'
pull_request:
Expand All @@ -15,15 +16,14 @@ jobs:
fail-fast: false
matrix:
shopware-version:
- 'v6.5.2.0'
- 'v6.5.3.2'
- 'trunk'
- 'v6.6.0.0-rc1'
steps:
- name: Setup Shopware
uses: FriendsOfShopware/setup-shopware@main
with:
shopware-version: ${{ matrix.shopware-version }}
php-version: 8.1
php-version: 8.2
php-extensions: pcov

- name: Checkout
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ This plugin allows to store the mails in theme instead of database. This gives u

## Requirements

- Shopware 6.4.1 or newer
- PHP 7.4
- Shopware 6.6.0 or newer
- PHP 8.2

## Installation

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frosh/frosh-platform-template-mail",
"version": "2.0.2",
"version": "3.0.0",
"type": "shopware-platform-plugin",
"description": "Load mail templates from theme",
"keywords": [
Expand Down Expand Up @@ -45,6 +45,6 @@
}
},
"require": {
"shopware/core": "~6.5.0"
"shopware/core": "~6.6.0"
}
}
12 changes: 7 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="tests/TestBootstrap.php"
executionOrder="random">
<coverage>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/TestBootstraper.php"
cacheResult="false">
<source>
<include>
<directory>./src/</directory>
</include>
</coverage>
</source>
<php>
<ini name="error_reporting" value="-1"/>
<server name="KERNEL_CLASS" value="Shopware\Core\Kernel"/>
Expand Down
19 changes: 0 additions & 19 deletions src/DependencyInjection/CacheCompilerPass.php

This file was deleted.

2 changes: 2 additions & 0 deletions src/Extension/Content/MailTemplate/MailTemplateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Runtime;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[AutoconfigureTag('shopware.entity_extension')]
class MailTemplateExtension extends EntityExtension
{
public function extendFields(FieldCollection $collection): void
Expand Down
8 changes: 0 additions & 8 deletions src/FroshPlatformTemplateMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@

namespace Frosh\TemplateMail;

use Frosh\TemplateMail\DependencyInjection\CacheCompilerPass;
use Shopware\Core\Framework\Plugin;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class FroshPlatformTemplateMail extends Plugin
{
public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new CacheCompilerPass());

parent::build($container);
}
}
17 changes: 0 additions & 17 deletions src/Resources/config/loaders.xml

This file was deleted.

54 changes: 5 additions & 49 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,11 @@
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<imports>
<import resource="loaders.xml"/>
</imports>
<services>
<service id="Frosh\TemplateMail\Services\SearchPathProvider">
<argument type="service" id="language.repository"/>
</service>

<service id="Frosh\TemplateMail\Services\MailFinderService">
<argument type="service" id="twig.loader.native_filesystem"/>
<argument type="tagged" tag="frosh_template_mail.loader"/>
<argument type="service" id="language.repository"/>
<argument type="service" id="Shopware\Core\Framework\Adapter\Translation\Translator"/>
<argument type="service" id="Frosh\TemplateMail\Services\SearchPathProvider"/>
<argument type="service" id="Doctrine\DBAL\Connection"/>
</service>

<service id="Frosh\TemplateMail\Services\CachedMailFinderService"
decorates="Frosh\TemplateMail\Services\MailFinderService">
<argument type="service" id="Frosh\TemplateMail\Services\CachedMailFinderService.inner"/>
<argument type="service" id="cache.app.taggable"/>
</service>

<service id="Frosh\TemplateMail\Services\StringTemplateRenderer"
decorates="Shopware\Core\Framework\Adapter\Twig\StringTemplateRenderer">
<argument type="service" id="twig"/>
</service>

<service id="Frosh\TemplateMail\Subscriber\FlowSubscriber">
<argument type="service" id="mail_template_type.repository"/>
<argument type="service" id="Frosh\TemplateMail\Services\MailFinderService"/>
<tag name="kernel.event_subscriber"/>
</service>

<service id="Frosh\TemplateMail\Command\ExportCommand">
<argument type="service" id="Doctrine\DBAL\Connection"/>
<tag name="console.command"/>
</service>

<service id="Frosh\TemplateMail\Extension\Content\MailTemplate\MailTemplateExtension">
<tag name="shopware.entity.extension"/>
</service>

<service id="Frosh\TemplateMail\Subscriber\MailTemplateSubscriber">
<argument type="service" id="mail_template_type.repository"/>
<argument type="service" id="Frosh\TemplateMail\Services\MailFinderService"/>

<tag name="kernel.event_subscriber"/>
</service>
<defaults autoconfigure="true" autowire="true" />
<prototype namespace="Frosh\TemplateMail\" resource="../../" exclude="../../{DependencyInjection,Resources,FroshPlatformTemplateMail.php}" />
<instanceof id="Frosh\TemplateMail\Services\MailLoader\LoaderInterface">
<tag name="frosh_template_mail.loader"/>
</instanceof>
</services>
</container>
18 changes: 11 additions & 7 deletions src/Services/CachedMailFinderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@

use Frosh\TemplateMail\Services\TemplateMailContext;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\DependencyInjection\Attribute\When;
use Symfony\Contracts\Cache\CacheInterface;

class CachedMailFinderService implements MailFinderServiceInterface
#[When('prod')]
#[AsDecorator(MailFinderService::class)]
readonly class CachedMailFinderService implements MailFinderServiceInterface
{
public function __construct(
private readonly MailFinderServiceInterface $mailFinderService,
private readonly CacheInterface $cache
private MailFinderServiceInterface $mailFinderService,
private CacheInterface $cache
) {
}

public function findTemplateByTechnicalName(
string $type,
string $technicalName,
string $type,
string $technicalName,
TemplateMailContext $businessEvent,
bool $returnFolder = false
bool $returnFolder = false
): ?string {
$salesChannelId = $businessEvent->getSalesChannelId();

$cacheKey = md5(
$cacheKey = hash('xxh128',
$type
. $technicalName
. $salesChannelId
Expand Down
16 changes: 12 additions & 4 deletions src/Services/MailFinderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
use Doctrine\DBAL\Connection;
use Frosh\TemplateMail\Services\TemplateMailContext;
use Frosh\TemplateMail\Services\MailLoader\LoaderInterface;
use Shopware\Core\Framework\Adapter\Translation\AbstractTranslator;
use Shopware\Core\Framework\Adapter\Translation\Translator;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\Language\LanguageEntity;
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Twig\Loader\FilesystemLoader;

#[AsAlias]
class MailFinderService implements MailFinderServiceInterface
{
final public const TYPE_HTML = 'html.';
Expand All @@ -22,20 +27,23 @@ class MailFinderService implements MailFinderServiceInterface
* @param LoaderInterface[] $availableLoaders
*/
public function __construct(
#[Autowire(service: 'twig.loader.native_filesystem')]
private readonly FilesystemLoader $filesystemLoader,
#[TaggedIterator('frosh_template_mail.loader')]
private readonly iterable $availableLoaders,
private readonly EntityRepository $languageRepository,
private readonly Translator $translator,
#[Autowire(service: Translator::class)]
private readonly AbstractTranslator $translator,
private readonly SearchPathProvider $searchPathProvider,
private readonly Connection $connection
) {
}

public function findTemplateByTechnicalName(
string $type,
string $technicalName,
string $type,
string $technicalName,
TemplateMailContext $businessEvent,
bool $returnFolder = false
bool $returnFolder = false
): ?string {
$paths = $this->filesystemLoader->getPaths();

Expand Down
8 changes: 3 additions & 5 deletions src/Services/MailFinderServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace Frosh\TemplateMail\Services;

use Frosh\TemplateMail\Services\TemplateMailContext;

interface MailFinderServiceInterface
{
public function findTemplateByTechnicalName(
string $type,
string $technicalName,
string $type,
string $technicalName,
TemplateMailContext $businessEvent,
bool $returnFolder = false
bool $returnFolder = false
): ?string;
}
3 changes: 1 addition & 2 deletions src/Services/MailLoader/MjmlLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class MjmlLoader implements LoaderInterface

public function __construct(
private readonly LoggerInterface $logger,
private readonly Client $client = new Client(
)
private readonly Client $client = new Client()
) {
}

Expand Down
3 changes: 3 additions & 0 deletions src/Services/MailLoader/TwigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Frosh\TemplateMail\Services\MailLoader;

use Symfony\Component\DependencyInjection\Attribute\AsAlias;

#[AsAlias]
class TwigLoader implements LoaderInterface
{
public function load(string $path): ?string
Expand Down
2 changes: 2 additions & 0 deletions src/Services/StringTemplateRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use PHPUnit\Framework\Attributes\CodeCoverageIgnore;
use Shopware\Core\Framework\Adapter\Twig\Exception\StringTemplateRenderingException;
use Shopware\Core\Framework\Context;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Twig\Environment;
use Twig\Error\Error;
use Twig\Extension\CoreExtension;
use Twig\Loader\ArrayLoader;
use Twig\Loader\ChainLoader;

#[AsDecorator(\Shopware\Core\Framework\Adapter\Twig\StringTemplateRenderer::class)]
class StringTemplateRenderer extends \Shopware\Core\Framework\Adapter\Twig\StringTemplateRenderer
{
private Environment $twig;
Expand Down
6 changes: 3 additions & 3 deletions src/Services/TemplateMailContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
/**
* @codeCoverageIgnore
*/
class TemplateMailContext
readonly class TemplateMailContext
{
public function __construct(
private readonly string $salesChannelId,
private readonly Context $context
private string $salesChannelId,
private Context $context
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Subscriber/FlowSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\ParameterBag;

class FlowSubscriber implements EventSubscriberInterface
readonly class FlowSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly EntityRepository $mailTemplateTypeRepository,
private readonly MailFinderServiceInterface $mailFinderService
private EntityRepository $mailTemplateTypeRepository,
private MailFinderServiceInterface $mailFinderService
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Subscriber/MailTemplateSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
use Shopware\Core\Framework\Struct\ArrayStruct;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class MailTemplateSubscriber implements EventSubscriberInterface
readonly class MailTemplateSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly EntityRepository $mailTemplateTypeRepository,
private readonly MailFinderServiceInterface $mailFinderService
private EntityRepository $mailTemplateTypeRepository,
private MailFinderServiceInterface $mailFinderService
) {
}

Expand Down
Loading

0 comments on commit 64a5507

Please sign in to comment.