From 5875c5c098c1a3cb920d4172908c527be89b196e Mon Sep 17 00:00:00 2001 From: Stefan Heimes Date: Fri, 30 Jan 2026 13:03:54 +0100 Subject: [PATCH 1/2] Fixing a bug that caused all data to be copied twice. --- src/EventListener/BackendEventListener.php | 33 ++++++++++++++++++++-- src/Resources/config/listeners.yml | 1 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/EventListener/BackendEventListener.php b/src/EventListener/BackendEventListener.php index 6fea4ba..55f4b87 100644 --- a/src/EventListener/BackendEventListener.php +++ b/src/EventListener/BackendEventListener.php @@ -26,8 +26,10 @@ use Contao\System; use ContaoCommunityAlliance\DcGeneral\Event\PostDuplicateModelEvent; use ContaoCommunityAlliance\DcGeneral\Event\PostPasteModelEvent; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use MetaModels\DcGeneral\Data\Model; +use MetaModels\IFactory; /** * Handles event operations on tl_metamodel_dcasetting @@ -50,13 +52,20 @@ class BackendEventListener */ private Connection $connection; + /** + * @var IFactory + */ + private IFactory $factory; + /** * The ArticleContent constructor. * * @param Connection $connection The database connection. */ - public function __construct(Connection $connection = null) - { + public function __construct( + IFactory $factory, + Connection $connection = null, + ) { if (null === $connection) { // @codingStandardsIgnoreStart @trigger_error( @@ -68,6 +77,7 @@ public function __construct(Connection $connection = null) assert($connection instanceof Connection); } $this->connection = $connection; + $this->factory = $factory; } /** @@ -130,14 +140,33 @@ public function handlePostPasteModel(PostPasteModelEvent $event) */ private function duplicateContentEntries(string $strTable, int $intSourceId, int $intDestinationId): void { + $metaModel = $this->factory->getMetaModel($strTable); + if($metaModel === null){ + return; + } + + $colNamesToCopy = []; + $attributes = $metaModel->getAttributes(); + foreach ($attributes as $attribute) { + if ($attribute->get('type') === 'contentarticle') { + $colNamesToCopy[] = $attribute->getColName(); + } + } + + if (empty($colNamesToCopy)) { + return; + } + $objContent = $this->connection ->createQueryBuilder() ->select('*') ->from('tl_content', 't') ->where('t.pid=:id') ->andWhere('t.ptable=:ptable') + ->andWhere('t.mm_slot IN (:slots)') ->setParameter('id', $intSourceId) ->setParameter('ptable', $strTable) + ->setParameter('slots', $colNamesToCopy, ArrayParameterType::STRING) ->executeQuery(); while ($row = $objContent->fetchAssociative()) { diff --git a/src/Resources/config/listeners.yml b/src/Resources/config/listeners.yml index d100ac7..adc05c0 100644 --- a/src/Resources/config/listeners.yml +++ b/src/Resources/config/listeners.yml @@ -2,6 +2,7 @@ services: MetaModels\AttributeContentArticleBundle\EventListener\BackendEventListener: public: false arguments: + - '@metamodels.factory' - '@database_connection' tags: - name: kernel.event_listener From 23430cefb70811442ed68c6a191bfb7fc89959fa Mon Sep 17 00:00:00 2001 From: Stefan Heimes Date: Fri, 30 Jan 2026 13:07:15 +0100 Subject: [PATCH 2/2] Make phpcq happy. --- src/EventListener/BackendEventListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EventListener/BackendEventListener.php b/src/EventListener/BackendEventListener.php index 55f4b87..6b712c5 100644 --- a/src/EventListener/BackendEventListener.php +++ b/src/EventListener/BackendEventListener.php @@ -141,7 +141,7 @@ public function handlePostPasteModel(PostPasteModelEvent $event) private function duplicateContentEntries(string $strTable, int $intSourceId, int $intDestinationId): void { $metaModel = $this->factory->getMetaModel($strTable); - if($metaModel === null){ + if ($metaModel === null) { return; }