2626use ContaoCommunityAlliance \DcGeneral \Contao \View \Contao2BackendView \Event \ManipulateWidgetEvent ;
2727use ContaoCommunityAlliance \DcGeneral \Event \PostDuplicateModelEvent ;
2828use ContaoCommunityAlliance \DcGeneral \Event \PostPasteModelEvent ;
29+ use Doctrine \DBAL \ArrayParameterType ;
2930use Doctrine \DBAL \Connection ;
3031use MetaModels \DcGeneral \Data \Driver ;
3132use 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 ()) {
0 commit comments