Skip to content

Commit

Permalink
Fix compatibility with older doctrine versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Aug 17, 2021
1 parent cdde35c commit cb4e438
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/Migration/SliderPermissionsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
Expand Down Expand Up @@ -70,22 +71,39 @@ public function shouldRun(): bool
public function run(): MigrationResult
{
$defaultPermissions = serialize(['create', 'delete']);
$defaultSliders = serialize(array_values(array_map(function ($row) {
return $row['id'];
}, $this->connection->fetchAllAssociative("SELECT id FROM tl_rocksolid_slider"))));

if (method_exists($this->connection, 'fetchFirstColumn')) {
$defaultSliders = serialize(array_values($this->connection->fetchFirstColumn("SELECT id FROM tl_rocksolid_slider")));
}
else {
$defaultSliders = serialize(array_values($this->connection->executeQuery("SELECT id FROM tl_rocksolid_slider")->fetchAll(FetchMode::COLUMN)));
}

foreach (['tl_user', 'tl_user_group'] as $table) {
foreach ([
"ALTER TABLE $table ADD rsts_permissions BLOB DEFAULT NULL",
"ALTER TABLE $table ADD rsts_sliders BLOB DEFAULT NULL",
] as $query) {
$this->connection->executeStatement($query);
if (method_exists($this->connection, 'executeStatement')) {
$this->connection->executeStatement($query);
}
else {
$this->connection->query($query);
}
}
if (method_exists($this->connection, 'executeStatement')) {
$this->connection->executeStatement(
"UPDATE $table SET rsts_permissions = ?, rsts_sliders = ?",
[$defaultPermissions, $defaultSliders],
[Types::BLOB, Types::BLOB]
);
}
else {
$this->connection
->prepare("UPDATE $table SET rsts_permissions = ?, rsts_sliders = ?")
->execute([$defaultPermissions, $defaultSliders])
;
}
$this->connection->executeStatement(
"UPDATE $table SET rsts_permissions = ?, rsts_sliders = ?",
[$defaultPermissions, $defaultSliders],
[Types::BLOB, Types::BLOB]
);
}

return $this->createResult(true);
Expand Down

0 comments on commit cb4e438

Please sign in to comment.