2626use Contao \System ;
2727use ContaoCommunityAlliance \DcGeneral \Event \PostDuplicateModelEvent ;
2828use ContaoCommunityAlliance \DcGeneral \Event \PostPasteModelEvent ;
29+ use Doctrine \DBAL \ArrayParameterType ;
2930use Doctrine \DBAL \Connection ;
3031use MetaModels \DcGeneral \Data \Model ;
32+ use MetaModels \IFactory ;
3133
3234/**
3335 * Handles event operations on tl_metamodel_dcasetting
@@ -50,13 +52,20 @@ class BackendEventListener
5052 */
5153 private Connection $ connection ;
5254
55+ /**
56+ * @var IFactory
57+ */
58+ private IFactory $ factory ;
59+
5360 /**
5461 * The ArticleContent constructor.
5562 *
5663 * @param Connection $connection The database connection.
5764 */
58- public function __construct (Connection $ connection = null )
59- {
65+ public function __construct (
66+ IFactory $ factory ,
67+ Connection $ connection = null ,
68+ ) {
6069 if (null === $ connection ) {
6170 // @codingStandardsIgnoreStart
6271 @trigger_error (
@@ -68,6 +77,7 @@ public function __construct(Connection $connection = null)
6877 assert ($ connection instanceof Connection);
6978 }
7079 $ this ->connection = $ connection ;
80+ $ this ->factory = $ factory ;
7181 }
7282
7383 /**
@@ -130,14 +140,33 @@ public function handlePostPasteModel(PostPasteModelEvent $event)
130140 */
131141 private function duplicateContentEntries (string $ strTable , int $ intSourceId , int $ intDestinationId ): void
132142 {
143+ $ metaModel = $ this ->factory ->getMetaModel ($ strTable );
144+ if ($ metaModel === null ) {
145+ return ;
146+ }
147+
148+ $ colNamesToCopy = [];
149+ $ attributes = $ metaModel ->getAttributes ();
150+ foreach ($ attributes as $ attribute ) {
151+ if ($ attribute ->get ('type ' ) === 'contentarticle ' ) {
152+ $ colNamesToCopy [] = $ attribute ->getColName ();
153+ }
154+ }
155+
156+ if (empty ($ colNamesToCopy )) {
157+ return ;
158+ }
159+
133160 $ objContent = $ this ->connection
134161 ->createQueryBuilder ()
135162 ->select ('* ' )
136163 ->from ('tl_content ' , 't ' )
137164 ->where ('t.pid=:id ' )
138165 ->andWhere ('t.ptable=:ptable ' )
166+ ->andWhere ('t.mm_slot IN (:slots) ' )
139167 ->setParameter ('id ' , $ intSourceId )
140168 ->setParameter ('ptable ' , $ strTable )
169+ ->setParameter ('slots ' , $ colNamesToCopy , ArrayParameterType::STRING )
141170 ->executeQuery ();
142171
143172 while ($ row = $ objContent ->fetchAssociative ()) {
0 commit comments