sonata-project / SonataUserBundle

Symfony SonataUserBundle
https://docs.sonata-project.org/projects/SonataUserBundle
MIT License
341 stars 487 forks source link

Compatibility with doctrine dbal 4 #1680

Closed RobinDev closed 7 months ago

RobinDev commented 7 months ago

Compatibility with doctrine dbal 4

Just switching the deprecated array type to json - cf Upgrade Guide

I am targeting this branch, because change cannot be done without a BC-break.

Changelog

### Changed
- roles mapped type (orm) from `array` to `json`

Upgrade

A migration must be done, example :

<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version1709056840 extends AbstractMigration
{
    public function up(Schema $schema): void
    { 
        $rows = $this->connection->fetchAllAssociative('SELECT id,roles FROM user');

        /** @var array{'id': scalar, 'roles': string}[] $rows */
        foreach ($rows as $row) {
            $id = $row['id'];
            $roles = json_encode(unserialize($row['roles']));
            $this->connection->executeQuery('UPDATE user SET roles = :roles WHERE id = :id', ['roles' => $roles, 'id' => $id]);
        }
    }
}