Skip to content

Commit 3f2a9c3

Browse files
committed
fix for Contao 5.6
1 parent 70ecf85 commit 3f2a9c3

File tree

4 files changed

+32
-34
lines changed

4 files changed

+32
-34
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"contao/core-bundle": "^4.13 || ^5.0",
14-
"doctrine/dbal": "^3.3",
14+
"doctrine/dbal": "^3.6 || ^4.3",
1515
"psr/log": "^1.1 || 2.0 || ^3.0",
1616
"symfony/config": "^5.4 || ^6.4 || ^7.0",
1717
"symfony/console": "^5.4 || ^6.4 || ^7.0",

src/EventListener/DataContainer/ModuleListener.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,20 @@ public function getTags( DataContainer $dc ): array {
138138
$result = null;
139139
if( $ptable ) {
140140

141-
$result = $this->connection
142-
->prepare(
143-
"SELECT DISTINCT tag.id, tag.tag
144-
FROM $tTag AS tag
145-
JOIN $tRel AS rel ON (rel.tag_id=tag.id AND rel.ptable=:ptable AND rel.field=:field)
146-
ORDER BY tag.tag ASC")
147-
->executeQuery(['ptable'=>$ptable, 'field'=>'tags'])
148-
;
141+
$result = $this->connection->executeQuery(
142+
"SELECT DISTINCT tag.id, tag.tag
143+
FROM $tTag AS tag
144+
JOIN $tRel AS rel ON (rel.tag_id=tag.id AND rel.ptable=:ptable AND rel.field=:field)
145+
ORDER BY tag.tag ASC"
146+
, ['ptable'=>$ptable, 'field'=>'tags']
147+
);
149148
}
150149

151150
$tags = [];
152151

153152
if( $result && $result->rowCount() ) {
154153

155-
$rows = $result->fetchAll();
154+
$rows = $result->fetchAllAssociative();
156155

157156
foreach( $rows as $row ) {
158157
$tags[$row['id']] = $row['tag'];

src/EventListener/DataContainer/TagsListener.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ public function saveTags( $varValue, DataContainer $dc ): ?string {
170170
$tRel = TagsRelModel::getTable();
171171

172172
// remove all tag relations for this element
173-
$this->connection
174-
->prepare("DELETE FROM $tRel WHERE pid=? AND ptable=? AND field=?")
175-
->executeStatement([$dc->activeRecord->id, $dc->table, $dc->field])
176-
;
173+
$this->connection->executeStatement(
174+
"DELETE FROM $tRel WHERE pid=? AND ptable=? AND field=?"
175+
, [$dc->activeRecord->id, $dc->table, $dc->field]
176+
);
177177

178178
if( !empty($varValue) ) {
179179

@@ -182,10 +182,10 @@ public function saveTags( $varValue, DataContainer $dc ): ?string {
182182
// add tag relations for this element
183183
foreach( $tags as $i => $id ) {
184184

185-
$this->connection
186-
->prepare("INSERT INTO $tRel (tag_id, pid, ptable, field) VALUES (?,?,?,?)")
187-
->executeStatement([$id, $dc->activeRecord->id, $dc->table, $dc->field])
188-
;
185+
$this->connection->executeStatement(
186+
"INSERT INTO $tRel (tag_id, pid, ptable, field) VALUES (?,?,?,?)"
187+
, [$id, $dc->activeRecord->id, $dc->table, $dc->field]
188+
);
189189

190190
// explicitly cast the id into a string, otherwise the filter options in the backend won't work
191191
$tags[$i] = (string)$id;
@@ -267,21 +267,21 @@ public function mergeTagSelectButton( $buttons, DataContainer $dc ): array {
267267

268268
if( $rel['tag_id'] != $newId ) {
269269

270-
$this->connection
271-
->prepare("INSERT INTO $tRel (tag_id, pid, ptable, field) VALUES (?,?,?,?)")
272-
->executeStatement([$newId, $rel['pid'], $rel['ptable'], $rel['field']])
273-
;
270+
$this->connection->executeStatement(
271+
"INSERT INTO $tRel (tag_id, pid, ptable, field) VALUES (?,?,?,?)"
272+
, [$newId, $rel['pid'], $rel['ptable'], $rel['field']]
273+
);
274274
}
275275
}
276276
}
277277

278278
// delete rel for other tags
279279
foreach( $rowsProcessed as $hash => $rel ) {
280280

281-
$this->connection
282-
->prepare("DELETE FROM $tRel WHERE tag_id!=? AND pid=? AND ptable=? AND field=?")
283-
->executeStatement([$newId, $rel['pid'], $rel['ptable'], $rel['field']])
284-
;
281+
$this->connection->executeStatement(
282+
"DELETE FROM $tRel WHERE tag_id!=? AND pid=? AND ptable=? AND field=?"
283+
, [$newId, $rel['pid'], $rel['ptable'], $rel['field']]
284+
);
285285
}
286286

287287
// delete tag for other tags

src/Migration/Version007Update.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Benny Born <benny.born@numero2.de>
77
* @author Michael Bösherz <michael.boesherz@numero2.de>
88
* @license LGPL-3.0-or-later
9-
* @copyright Copyright (c) 2023, numero2 - Agentur für digitales Marketing GbR
9+
* @copyright Copyright (c) 2025, numero2 - Agentur für digitales Marketing GbR
1010
*/
1111

1212

@@ -40,14 +40,14 @@ public function __construct( ContaoFramework $framework, Connection $connection
4040

4141
$this->framework = $framework;
4242
$this->framework->initialize();
43-
43+
4444
$this->connection = $connection;
4545
}
4646

4747

4848
public function shouldRun(): bool {
4949

50-
$schemaManager = $this->connection->getSchemaManager();
50+
$schemaManager = $this->connection->createSchemaManager();
5151

5252
$t = TagsModel::getTable();
5353

@@ -71,7 +71,7 @@ public function shouldRun(): bool {
7171
if( !array_key_exists($dca,$this->fields) ) {
7272
$this->fields[$dca] = [];
7373
}
74-
74+
7575
if( in_array($field,$this->fields[$dca]) === false ) {
7676
$this->fields[$dca][] = $field;
7777
}
@@ -94,7 +94,7 @@ public function shouldRun(): bool {
9494
if( in_array($field, $columns) ) {
9595

9696
$res = $this->connection->prepare("SELECT 1 FROM $dca WHERE $field IS NOT NULL AND $field NOT LIKE '%:\"%'; ")->executeQuery();
97-
97+
9898
// return as soon as we found our first value in the wrong format
9999
if( $res && $res->rowCount() ) {
100100
return true;
@@ -123,15 +123,14 @@ public function run(): MigrationResult {
123123
$value = StringUtil::deserialize($row[$field]);
124124

125125
if( !empty($value) ) {
126-
126+
127127
// cast each id explicitly into a string
128128
$value = array_map(fn($v): string => (string)$v, $value);
129129

130130
$row[$field] = serialize($value);
131131

132132
// update the row
133-
$updateStmt = $this->connection->prepare("UPDATE $dca SET $field = :$field WHERE id = :id");
134-
$updateStmt->execute($row);
133+
$updateStmt = $this->connection->executeStatement("UPDATE $dca SET $field = :$field WHERE id = :id", $row);
135134
}
136135
}
137136
}

0 commit comments

Comments
 (0)