Skip to content

Commit be721ad

Browse files
committed
Fixing a bug that caused all data to be copied twice.
1 parent 9cd5e81 commit be721ad

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/EventListener/BackendEventListener.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\ManipulateWidgetEvent;
2727
use ContaoCommunityAlliance\DcGeneral\Event\PostDuplicateModelEvent;
2828
use ContaoCommunityAlliance\DcGeneral\Event\PostPasteModelEvent;
29+
use Doctrine\DBAL\ArrayParameterType;
2930
use Doctrine\DBAL\Connection;
3031
use MetaModels\DcGeneral\Data\Driver;
3132
use MetaModels\DcGeneral\Data\Model;
33+
use MetaModels\IFactory;
3234

3335
/**
3436
* Handles event operations on tl_metamodel_dcasetting.
@@ -51,13 +53,20 @@ class BackendEventListener
5153
*/
5254
private Connection $connection;
5355

56+
/**
57+
* @var IFactory
58+
*/
59+
private IFactory $factory;
60+
5461
/**
5562
* The ArticleContent constructor.
5663
*
5764
* @param Connection|null $connection The connection.
5865
*/
59-
public function __construct(Connection $connection = null)
60-
{
66+
public function __construct(
67+
IFactory $factory,
68+
Connection $connection = null,
69+
) {
6170
if (null === $connection) {
6271
// @codingStandardsIgnoreStart
6372
@trigger_error(
@@ -69,6 +78,7 @@ public function __construct(Connection $connection = null)
6978
assert($connection instanceof Connection);
7079
}
7180
$this->connection = $connection;
81+
$this->factory = $factory;
7282
}
7383

7484
/**
@@ -131,14 +141,33 @@ public function handlePostPasteModel(PostPasteModelEvent $event)
131141
*/
132142
private function duplicateContentEntries($strTable, $intSourceId, $intDestinationId)
133143
{
144+
$metaModel = $this->factory->getMetaModel($strTable);
145+
if ($metaModel === null) {
146+
return;
147+
}
148+
149+
$colNamesToCopy = [];
150+
$attributes = $metaModel->getAttributes();
151+
foreach ($attributes as $attribute) {
152+
if ($attribute->get('type') === 'translatedcontentarticle') {
153+
$colNamesToCopy[] = $attribute->getColName();
154+
}
155+
}
156+
157+
if (empty($colNamesToCopy)) {
158+
return;
159+
}
160+
134161
$objContent = $this->connection
135162
->createQueryBuilder()
136163
->select('*')
137164
->from('tl_content', 't')
138165
->where('t.pid=:id')
139166
->andWhere('t.ptable=:ptable')
167+
->andWhere('t.mm_slot IN (:slots)')
140168
->setParameter('id', $intSourceId)
141169
->setParameter('ptable', $strTable)
170+
->setParameter('slots', $colNamesToCopy, ArrayParameterType::STRING)
142171
->executeQuery();
143172

144173
while ($row = $objContent->fetchAssociative()) {

src/Resources/config/listeners.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ services:
22
MetaModels\AttributeTranslatedContentArticleBundle\EventListener\BackendEventListener:
33
public: false
44
arguments:
5+
- '@metamodels.factory'
56
- '@database_connection'
67
tags:
78
- name: kernel.event_listener,

0 commit comments

Comments
 (0)