-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1534 from dpfaffenbauer/issues/deep-copy
[ResourceBundle] add Pimcore DeepCopy Subscriber to fix doctrine collections clone problem
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/CoreShop/Bundle/ResourceBundle/EventListener/DeepCopySubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters