Skip to content
Merged
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
13 changes: 6 additions & 7 deletions .github/workflows/sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ jobs:
- 8.2
- 8.3
sylius:
- 1.12.0
- 1.13.0
- 1.14.0
- 2.0.0
symfony:
- 6.4
- 7.2
node:
- 14.x
- 20.x
env:
APP_ENV: test
package-name: synolia/sylius-gdpr-plugin
Expand All @@ -45,14 +44,14 @@ jobs:
with:
node-version: '${{ matrix.node }}'
-
uses: actions/checkout@v3
uses: actions/checkout@v4
-
name: 'Composer - Get Cache Directory'
id: composer-cache
run: 'echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT'
-
name: 'Composer - Set cache'
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-composer
with:
path: '${{ steps.composer-cache.outputs.dir }}'
Expand All @@ -71,7 +70,7 @@ jobs:
run: 'echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT'
-
name: 'Yarn - Set Cache'
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: '${{ steps.yarn-cache.outputs.dir }}'
key: 'node-${{ matrix.node }}-yarn-${{ hashFiles(''**/package.json **/yarn.lock'') }}'
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CONSOLE=cd ${TEST_DIRECTORY} && php bin/console -e test
COMPOSER=cd ${TEST_DIRECTORY} && composer
YARN=cd ${TEST_DIRECTORY} && yarn

SYLIUS_VERSION=1.14.0
SYLIUS_VERSION=2.0.0
SYMFONY_VERSION=6.4
PHP_VERSION=8.2
PLUGIN_NAME=synolia/sylius-gdpr-plugin
Expand Down Expand Up @@ -44,6 +44,10 @@ sylius-standard:
update-dependencies:
${COMPOSER} config extra.symfony.require "~${SYMFONY_VERSION}"
${COMPOSER} require symfony/asset:~${SYMFONY_VERSION} --no-scripts --no-update
ifeq ($(SYLIUS_VERSION)$(SYMFONY_VERSION), 2.0.06.4)
${COMPOSER} update --no-progress -n --no-scripts
test -f ${TEST_DIRECTORY}/config/packages/csrf.yaml && rm ${TEST_DIRECTORY}/config/packages/csrf.yaml || true
endif
${COMPOSER} update --no-progress -n

install-plugin:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
| | Version |
|:-------|:--------|
| PHP | ^8.2 |
| Sylius | ^1.12 |
| Sylius | ^2.0 |

## Installation

Expand Down
5 changes: 5 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# UPGRADE FROM `v1.X` TO `v2.0`

* For each implementation of `Synolia\SyliusGDPRPlugin\Loader\LoaderInterface`, add the `getDefaultPriority` static function.
* Use attribute instead of annotation.
* The service tag `anonymization_loader` has been removed. Use `Synolia\SyliusGDPRPlugin\Loader\LoaderInterface` instead.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"php": "^8.2",
"php-http/message-factory": "^1.1",
"phpdocumentor/reflection-docblock": "^5.3",
"sylius/sylius": "^1.12",
"symfony/property-info": "^6.4"
"sylius/sylius": "^2.0",
"symfony/property-info": "^6.4|^7.0"
},
"require-dev": {
"j13k/yaml-lint": "^1.1",
Expand Down Expand Up @@ -45,7 +45,8 @@
"dealerdirect/phpcodesniffer-composer-installer": true,
"symfony/thanks": true,
"phpro/grumphp": true,
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"php-http/discovery": true
}
},
"autoload": {
Expand Down
20 changes: 7 additions & 13 deletions src/Annotation/Anonymize.php → src/Attribute/Anonymize.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@

declare(strict_types=1);

namespace Synolia\SyliusGDPRPlugin\Annotation;
namespace Synolia\SyliusGDPRPlugin\Attribute;

use Doctrine\ORM\Mapping\MappingAttribute;
use Synolia\SyliusGDPRPlugin\Validator\FakerOptionsValidator;

/**
* @Annotation
*
* @Target({"PROPERTY","ANNOTATION"})
*/
#[\Attribute(\Attribute::TARGET_PROPERTY)]
final class Anonymize implements MappingAttribute
{
public ?string $faker;
public readonly ?string $faker;

public array $args = [];
public readonly array $args;

public bool $unique = false;
public readonly bool $unique;

/** @var string|int|null */
public $prefix = '';
public readonly string|int|null $prefix;

/** @var string|int|array|bool|null */
public $value;
public readonly string|int|array|bool|null $value;

public function __construct(array $options = [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,23 @@

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Synolia\SyliusGDPRPlugin\Loader\ArrayLoader;
use Synolia\SyliusGDPRPlugin\Loader\LoaderChain;

final class RegisterAnonymizationLoader implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
$services = $container->findTaggedServiceIds('anonymization_loader');
$chainLoader = $container->getDefinition(LoaderChain::class);

foreach (\array_keys($services) as $id) {
$definition = $container->getDefinition($id);
if (ArrayLoader::class === $definition->getClass()) {
$definition->setArgument(
0,
$container->getParameter('synolia_anonymization_mapping'),
);
}
$chainLoader->addMethodCall('addLoader', [new Reference($id)]);
if (!$container->has(LoaderChain::class)) {
return;
}

$arrayLoader = $container->getDefinition(ArrayLoader::class);
$arrayLoader->setArgument(
0,
$container->getParameter('synolia_anonymization_mapping'),
);

$container->getParameterBag()->remove('synolia_anonymization_mapping');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('anonymize_customers_not_logged_before_date', DateType::class, [
'label' => false,
'widget' => 'single_text',
'row_attr' => ['class' => 'ui field'],
'row_attr' => ['class' => ''],
])
->add('anonymize_customers_not_logged_submit', SubmitType::class, [
'label' => 'sylius.ui.execute',
'attr' => ['class' => 'ui blue button'],
'attr' => ['class' => 'btn btn-warning mb-3'],
])
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('anonymize_customer_without_any_orders_before_date', DateType::class, [
'label' => false,
'widget' => 'single_text',
'row_attr' => ['class' => 'ui field'],
'row_attr' => ['class' => ''],
])
->add('anonymize_customer_without_any_orders_submit', SubmitType::class, [
'label' => 'sylius.ui.execute',
'attr' => ['class' => 'ui blue button'],
'attr' => ['class' => 'btn btn-warning mb-3'],
])
;
}
Expand Down
7 changes: 7 additions & 0 deletions src/Loader/ArrayLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

final readonly class ArrayLoader implements LoaderInterface
{
private const PRIORITY = -1024;

public function __construct(private array $mappings = [])
{
}
Expand Down Expand Up @@ -72,4 +74,9 @@ private function assignAttributeMetaDataCollection(

return $attributeMetaDataCollection;
}

public static function getDefaultPriority(): int
{
return self::PRIORITY;
}
}
30 changes: 17 additions & 13 deletions src/Loader/AnnotationLoader.php → src/Loader/AttributeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@

namespace Synolia\SyliusGDPRPlugin\Loader;

use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Util\ClassUtils;
use Synolia\SyliusGDPRPlugin\Annotation\Anonymize;
use Synolia\SyliusGDPRPlugin\Attribute\Anonymize;
use Synolia\SyliusGDPRPlugin\Loader\Mapping\AttributeMetaData;
use Synolia\SyliusGDPRPlugin\Loader\Mapping\AttributeMetadataCollection;

final readonly class AnnotationLoader implements LoaderInterface
final readonly class AttributeLoader implements LoaderInterface
{
public function __construct(private Reader $annotationReader)
{
}
private const PRIORITY = 1024;

/** @throws \ReflectionException */
public function loadClassMetadata(string $className): AttributeMetadataCollection
Expand All @@ -23,20 +20,27 @@ public function loadClassMetadata(string $className): AttributeMetadataCollectio
$properties = $reflectionClass->getProperties();
$attributeMetaDataCollection = new AttributeMetadataCollection();
foreach ($properties as $property) {
$annotation = $this->annotationReader->getPropertyAnnotation(
$property,
Anonymize::class,
);
$attributes = $property->getAttributes(Anonymize::class, \ReflectionAttribute::IS_INSTANCEOF);

if (!$annotation instanceof Anonymize) {
if (\count($attributes) === 0) {
continue;
}

$attributeMetaData = new AttributeMetaData($annotation->faker, $annotation->args, $annotation->unique, $annotation->prefix, $annotation->value);
$attributesInstances = [];
foreach ($attributes as $attribute) {
$attributesInstances[] = $attribute->newInstance();
}
/** @var Anonymize $attribute */
$attribute = $attributesInstances[0];
$attributeMetaData = new AttributeMetaData($attribute->faker, $attribute->args, $attribute->unique, $attribute->prefix, $attribute->value);

$attributeMetaDataCollection->add($property->name, $attributeMetaData);
}

return $attributeMetaDataCollection;
}

public static function getDefaultPriority(): int
{
return self::PRIORITY;
}
}
18 changes: 18 additions & 0 deletions src/Loader/LoaderChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@

namespace Synolia\SyliusGDPRPlugin\Loader;

use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use Synolia\SyliusGDPRPlugin\Loader\Mapping\AttributeMetadataCollection;

final class LoaderChain implements LoaderInterface
{
/** @var LoaderInterface[] */
private array $loaders = [];

public function __construct(
#[AutowireIterator(LoaderInterface::class, defaultPriorityMethod: 'getDefaultPriority', exclude: [self::class])]
iterable $loaders,
) {
foreach ($loaders as $loader) {
if (!$loader instanceof LoaderInterface) {
throw new \LogicException('Not an anonymization loader');
}
$this->addLoader($loader);
}
}

public function addLoader(LoaderInterface $loader): void
{
if ($loader instanceof self) {
Expand All @@ -33,4 +46,9 @@ public function loadClassMetadata(string $className): AttributeMetadataCollectio

return $fullCollect;
}

public static function getDefaultPriority(): int
{
return 0;
}
}
4 changes: 4 additions & 0 deletions src/Loader/LoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

namespace Synolia\SyliusGDPRPlugin\Loader;

use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use Synolia\SyliusGDPRPlugin\Loader\Mapping\AttributeMetadataCollection;

#[AutoconfigureTag]
interface LoaderInterface
{
public function loadClassMetadata(string $className): AttributeMetadataCollection;

public static function getDefaultPriority(): int;
}
2 changes: 2 additions & 0 deletions src/Menu/AdminMenuListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public function addAdminMenuItems(MenuBuilderEvent $event): void
$menu = $event->getMenu();

$gdprMenu = $menu->addChild('gdpr');
$gdprMenu->setLabel('sylius.ui.admin.synolia_gdpr.customer.gdpr_title');
$gdprMenu->setLabelAttribute('icon', 'tabler:database-star');
$gdprMenu
->addChild('sylius.ui.admin.synolia_gdpr.advanced_actions.title', [
'route' => 'synolia_sylius_gdpr_admin_advanced_actions',
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/app/config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
imports:
- { resource: "@SynoliaSyliusGDPRPlugin/Resources/config/packages/ui.yaml" }
- { resource: "@SynoliaSyliusGDPRPlugin/Resources/config/packages/twig_hooks.yaml" }
5 changes: 0 additions & 5 deletions src/Resources/config/mappings/ShopUser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ Sylius\Component\Core\Model\ShopUser:
faker: dateTime
verifiedAt:
faker: dateTime
locked:
faker: boolean
args: [100]
credentialsExpireAt:
faker: dateTime
email:
faker: email
unique: true
Expand Down
Loading
Loading