Skip to content

Add doctrine/dbal 4 support #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '8.4'
coverage: none
tools: composer:v2

Expand All @@ -53,7 +53,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '8.4'
coverage: none
tools: composer:v2, composer-normalize:2
env:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '8.4'
coverage: none
tools: composer:v2

Expand All @@ -53,7 +53,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '8.4'
coverage: none
tools: composer:v2

Expand All @@ -63,7 +63,7 @@ jobs:
dependency-versions: highest

- name: Psalm
run: vendor/bin/psalm --no-progress --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.3
run: vendor/bin/psalm --no-progress --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.4

rector:
name: Rector
Expand All @@ -77,7 +77,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '8.4'
coverage: none
tools: composer:v2

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-platforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
matrix:
php-version:
- '8.3'
- '8.4'
mysql-version:
- '5.7'
- '8.0'
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
strategy:
matrix:
php-version:
- '8.3'
- '8.4'
postgres-version:
- '13'
- '14'
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
dependencies: [highest]
allowed-to-fail: [false]
symfony-require: ['']
Expand All @@ -42,17 +43,17 @@ jobs:
dependencies: lowest
allowed-to-fail: false
variant: normal
- php-version: '8.3'
- php-version: '8.4'
dependencies: highest
allowed-to-fail: false
symfony-require: 6.4.*
variant: symfony/symfony:"6.4.*"
- php-version: '8.3'
- php-version: '8.4'
dependencies: highest
allowed-to-fail: false
symfony-require: 7.1.*
variant: symfony/symfony:"7.1.*"
- php-version: '8.3'
- php-version: '8.4'
dependencies: highest
allowed-to-fail: false
symfony-require: 7.2.*
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [1.19.0](https://github.com/sonata-project/EntityAuditBundle/compare/1.18.0...1.19.0) - 2025-05-16
### Deprecated
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\AuditConfiguration ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\AuditManager ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\AuditReader ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\ChangedEntity ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\AuditedCollection ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\DependencyInjection\Configuration ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\DependencyInjection\SimpleThingsEntityAuditExtension ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\EventListener\CreateSchemaListener ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\EventListener\LogRevisionsListener ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\Exception\AuditedCollectionException ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\Exception\DeletedException ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\Exception\InvalidRevisionException ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\Exception\NoRevisionFoundException ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\Exception\NotAuditedException ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\Metadata\MetadataFactory ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\Revision ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\User\TokenStorageUsernameCallable ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\Utils\ArrayDiff ([@VincentLanglet](https://github.com/VincentLanglet))
- [[#647](https://github.com/sonata-project/EntityAuditBundle/pull/647)] Extending SimpleThings\EntityAudit\Utils\SimpleDiff ([@VincentLanglet](https://github.com/VincentLanglet))

### Fixed
- [[#648](https://github.com/sonata-project/EntityAuditBundle/pull/648)] Fixed an error in determining the column type ([@xelatt](https://github.com/xelatt))

## [1.18.0](https://github.com/sonata-project/EntityAuditBundle/compare/1.17.1...1.18.0) - 2024-07-14
### Added
- [[#590](https://github.com/sonata-project/EntityAuditBundle/pull/590)] Support for `doctrine/orm` 3 ([@franmomu](https://github.com/franmomu))
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ lint-xliff:
.PHONY: lint-xliff

lint-php:
vendor/bin/php-cs-fixer fix --ansi --verbose --diff --dry-run
PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --ansi --verbose --diff --dry-run
.PHONY: lint-php

cs-fix: cs-fix-php cs-fix-xml cs-fix-xliff cs-fix-composer
.PHONY: cs-fix

cs-fix-php:
vendor/bin/php-cs-fixer fix --verbose
PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --verbose
.PHONY: cs-fix-php

cs-fix-xml:
Expand Down Expand Up @@ -94,7 +94,7 @@ phpstan:
.PHONY: phpstan

psalm:
vendor/bin/psalm --php-version=8.3
vendor/bin/psalm --php-version=8.4
.PHONY: psalm

rector:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"require": {
"php": "^8.1",
"doctrine/collections": "^1.8 || ^2.0",
"doctrine/dbal": "^3.6",
"doctrine/dbal": "^3.6 || ^4.0",
"doctrine/event-manager": "^1.2 || ^2.0",
"doctrine/orm": "^2.14 || ^3.0",
"doctrine/persistence": "^3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/AuditReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function find($className, $id, $revision, array $options = [])
$allDiscrValues = array_flip($classMetadata->discriminatorMap);
$queriedDiscrValues = [$this->em->getConnection()->quote($classMetadata->discriminatorValue)];
foreach ($classMetadata->subClasses as $subclassName) {
$queriedDiscrValues[] = $this->em->getConnection()->quote($allDiscrValues[$subclassName]);
$queriedDiscrValues[] = $this->em->getConnection()->quote((string) $allDiscrValues[$subclassName]);
}

$whereSQL .= \sprintf(
Expand Down
20 changes: 19 additions & 1 deletion src/EventListener/CreateSchemaListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace SimpleThings\EntityAudit\EventListener;

use Composer\InstalledVersions;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Schema;
Expand Down Expand Up @@ -147,8 +148,25 @@
$primaryKey = $revisionsTable->getPrimaryKey();
\assert(null !== $primaryKey);

/*
* doctrine/dbal 3 support -- Table::addForeignKeyConstraint() takes a Table instead of a string
*
* NEXT_MAJOR: remove this `if` block
*/
if (version_compare(InstalledVersions::getVersion('doctrine/dbal') ?? '', '4.0.0', '<')) {
$relatedTable->addForeignKeyConstraint(
$revisionsTable, // @phpstan-ignore-line doctrine/dbal 3 support for old addForeignKeyConstraint() signature

Check failure on line 158 in src/EventListener/CreateSchemaListener.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/EventListener/CreateSchemaListener.php:158:17: InvalidArgument: Argument 1 of Doctrine\DBAL\Schema\Table::addForeignKeyConstraint expects string, but Doctrine\DBAL\Schema\Table provided (see https://psalm.dev/004)
[$this->config->getRevisionFieldName()],
$primaryKey->getColumns(),
[],
$revisionForeignKeyName
);

return;
}

$relatedTable->addForeignKeyConstraint(
$revisionsTable,
$revisionsTable->getName(),
[$this->config->getRevisionFieldName()],
$primaryKey->getColumns(),
[],
Expand Down
22 changes: 16 additions & 6 deletions src/EventListener/LogRevisionsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

namespace SimpleThings\EntityAudit\EventListener;

use Composer\InstalledVersions;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -133,7 +135,7 @@
if ($meta->hasField($fieldName)) {
/** @phpstan-var literal-string $field */
$field = $quoteStrategy->getColumnName($field, $meta, $platform);
$fieldType = $meta->getTypeOfField($field);
$fieldType = $meta->getTypeOfField($fieldName);
if (null !== $fieldType) {
$type = Type::getType($fieldType);
/** @phpstan-var literal-string $placeholder */
Expand Down Expand Up @@ -198,7 +200,7 @@
$sql .= ' AND '.$columnName.' = ?';
}

$em->getConnection()->executeQuery($sql, $params, $types);

Check failure on line 203 in src/EventListener/LogRevisionsListener.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/EventListener/LogRevisionsListener.php:203:63: InvalidArgument: Argument 3 of Doctrine\DBAL\Connection::executeQuery expects array<int<0, max>|string, Doctrine\DBAL\ArrayParameterType|Doctrine\DBAL\ParameterType|Doctrine\DBAL\Types\Type|string>, but non-empty-list<mixed|null|string> provided (see https://psalm.dev/004)
}

foreach ($this->deferredChangedManyToManyEntityRevisionsToPersist as $deferredChangedManyToManyEntityRevisionToPersist) {
Expand Down Expand Up @@ -383,8 +385,16 @@
);

$revisionId = $conn->lastInsertId();
if (false === $revisionId) {
throw new \RuntimeException('Unable to retrieve the last revision id.');
/*
* Preceding lastInsertId throws Doctrine\DBAL\Exception\DriverException on doctrine/dbal 4+, making the
* next check unnecessary.
*
* NEXT_MAJOR: Remove the following block
*/
if (version_compare(InstalledVersions::getVersion('doctrine/dbal') ?? '', '4.0.0', '<')) {
if (false === $revisionId) { // @phpstan-ignore-line doctrine/dbal 3 lastInsertId() can return false

Check failure on line 395 in src/EventListener/LogRevisionsListener.php

View workflow job for this annotation

GitHub Actions / Psalm

TypeDoesNotContainType

src/EventListener/LogRevisionsListener.php:395:21: TypeDoesNotContainType: int|string does not contain false (see https://psalm.dev/056)
throw new \RuntimeException('Unable to retrieve the last revision id.');
}
}

$this->revisionId = $revisionId;
Expand Down Expand Up @@ -523,7 +533,7 @@
$conn = $em->getConnection();

$params = [$this->getRevisionId($conn), $revType];
$types = [\PDO::PARAM_INT, \PDO::PARAM_STR];
$types = [ParameterType::INTEGER, ParameterType::STRING];

$fields = [];

Expand All @@ -547,7 +557,7 @@
$fields[$sourceColumn] = true;
if (null === $data) {
$params[] = null;
$types[] = \PDO::PARAM_STR;
$types[] = ParameterType::STRING;
} else {
$params[] = $relatedId[$targetClass->fieldNames[$targetColumn]] ?? null;
$types[] = $targetClass->getTypeOfField($targetClass->getFieldForColumn($targetColumn));
Expand Down Expand Up @@ -622,7 +632,7 @@
}
}

$conn->executeStatement($this->getInsertRevisionSQL($em, $class), $params, $types);

Check failure on line 635 in src/EventListener/LogRevisionsListener.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/EventListener/LogRevisionsListener.php:635:84: InvalidArgument: Argument 3 of Doctrine\DBAL\Connection::executeStatement expects array<int<0, max>|string, Doctrine\DBAL\ArrayParameterType|Doctrine\DBAL\ParameterType|Doctrine\DBAL\Types\Type|string>, but list{0: enum(Doctrine\DBAL\ParameterType::INTEGER)|enum(Doctrine\DBAL\ParameterType::STRING)|mixed|null|string, 1?: enum(Doctrine\DBAL\ParameterType::INTEGER)|enum(Doctrine\DBAL\ParameterType::STRING)|mixed|null|string, 2?: enum(Doctrine\DBAL\ParameterType::INTEGER)|enum(Doctrine\DBAL\ParameterType::STRING)|mixed|null|string, ...<enum(Doctrine\DBAL\ParameterType::INTEGER)|enum(Doctrine\DBAL\ParameterType::STRING)|mixed|null|string>} provided (see https://psalm.dev/004)
}

/**
Expand All @@ -642,7 +652,7 @@
): void {
$conn = $em->getConnection();
$joinTableParams = [$this->getRevisionId($conn), $revType];
$joinTableTypes = [\PDO::PARAM_INT, \PDO::PARAM_STR];
$joinTableTypes = [ParameterType::INTEGER, ParameterType::STRING];

foreach (self::getRelationToSourceKeyColumns($assoc) as $targetColumn) {
$joinTableParams[] = $entityData[$class->fieldNames[$targetColumn]];
Expand Down
4 changes: 2 additions & 2 deletions tests/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Sonata\EntityAuditBundle\Tests;

use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use SimpleThings\EntityAudit\ChangedEntity;
use SimpleThings\EntityAudit\Exception\NoRevisionFoundException;
use SimpleThings\EntityAudit\Exception\NotAuditedException;
Expand Down Expand Up @@ -485,7 +485,7 @@ public function testRevisionForeignKeys(): void
{
$em = $this->getEntityManager();

$isSqlitePlatform = $em->getConnection()->getDatabasePlatform() instanceof SqlitePlatform;
$isSqlitePlatform = $em->getConnection()->getDatabasePlatform() instanceof SQLitePlatform;
$updateForeignKeysConfig = false;

if ($isSqlitePlatform) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Types/ConvertToPHPType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public function canRequireSQLConversion(): bool
return true;
}

public function convertToPHPValueSQL($sqlExpr, $platform): string
public function convertToPHPValueSQL(string $sqlExpr, AbstractPlatform $platform): string
{
return \sprintf('UPPER(%s)', $sqlExpr);
}

public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform): string
public function convertToDatabaseValueSQL(string $sqlExpr, AbstractPlatform $platform): string
{
return \sprintf('LOWER(%s)', $sqlExpr);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Types/Issue196Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function canRequireSQLConversion(): bool
return true;
}

public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform): string
public function convertToDatabaseValueSQL(string $sqlExpr, AbstractPlatform $platform): string
{
return \sprintf('lower(%s)', $sqlExpr);
}
Expand Down
Loading