Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResourceBundle] add Pimcore DeepCopy Subscriber to fix doctrine collections clone problem #1534

Merged
merged 1 commit into from
Dec 2, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\ResourceBundle\EventListener;

use DeepCopy\DeepCopy;
use DeepCopy\Filter\Doctrine\DoctrineCollectionFilter;
use DeepCopy\Matcher\PropertyTypeMatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

class DeepCopySubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
//TODO: Change to Pimcore\Event\SystemEvents::SERVICE_PRE_GET_DEEP_COPY later
//TODO: Event has been added with 6.8.5, min requirement is 6.6 for now.
return [
'pimcore.system.service.preGetDeepCopy' => 'addDoctrineCollectionFilter',
];
}

public function addDoctrineCollectionFilter(GenericEvent $event)
{
$context = $event->getArgument('context');

//Only add if not already been added
if (!($context['defaultFilters'] ?? false)) {
/**
* @var DeepCopy $copier
*/
$copier = $event->getArgument('copier');
$copier->addFilter(new DoctrineCollectionFilter(),
new PropertyTypeMatcher('Doctrine\Common\Collections\Collection'));
$event->setArgument('copier', $copier);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ services:
decorates: 'jms_serializer.metadata.annotation_driver'
arguments:
- '@CoreShop\Bundle\ResourceBundle\Serialization\Driver\PimcoreDataObjectDriver.inner'

CoreShop\Bundle\ResourceBundle\EventListener\DeepCopySubscriber:
tags:
- { name: kernel.event_subscriber }