From efb3532c5f358c08121b8d366ff0e104a1bcbc7f Mon Sep 17 00:00:00 2001 From: xelatt Date: Fri, 16 May 2025 22:29:05 +0300 Subject: [PATCH 1/4] bugfix, field type definitions (#648) --- src/EventListener/LogRevisionsListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EventListener/LogRevisionsListener.php b/src/EventListener/LogRevisionsListener.php index e0529830..edef21a7 100644 --- a/src/EventListener/LogRevisionsListener.php +++ b/src/EventListener/LogRevisionsListener.php @@ -133,7 +133,7 @@ public function postFlush(PostFlushEventArgs $eventArgs): void 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 */ From ca98668f45f70b06db8aef5b1c653793c2a3465b Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 16 May 2025 21:59:58 +0200 Subject: [PATCH 2/4] 1.19.0 (#649) --- CHANGELOG.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8f96024..5c6b852c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) From 4f35def927157354907833a8ce4d333097b22983 Mon Sep 17 00:00:00 2001 From: SonataCI Date: Fri, 16 May 2025 20:13:06 +0000 Subject: [PATCH 3/4] DevKit updates --- .github/workflows/lint.yaml | 4 ++-- .github/workflows/qa.yaml | 8 ++++---- .github/workflows/test-platforms.yaml | 4 ++-- .github/workflows/test.yaml | 7 ++++--- Makefile | 6 +++--- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 24503a9d..5f1dd2f2 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -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 @@ -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: diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index 6bab6bdf..c64f8997 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/test-platforms.yaml b/.github/workflows/test-platforms.yaml index d3be3bfd..bb48f27d 100644 --- a/.github/workflows/test-platforms.yaml +++ b/.github/workflows/test-platforms.yaml @@ -37,7 +37,7 @@ jobs: strategy: matrix: php-version: - - '8.3' + - '8.4' mysql-version: - '5.7' - '8.0' @@ -90,7 +90,7 @@ jobs: strategy: matrix: php-version: - - '8.3' + - '8.4' postgres-version: - '13' - '14' diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index fcb429c8..53fd06ad 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -33,6 +33,7 @@ jobs: - '8.1' - '8.2' - '8.3' + - '8.4' dependencies: [highest] allowed-to-fail: [false] symfony-require: [''] @@ -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.* diff --git a/Makefile b/Makefile index 9588e249..0371a044 100644 --- a/Makefile +++ b/Makefile @@ -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: @@ -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: From d28bfadb1280e5c87650849f77f8b9b4aa959fc4 Mon Sep 17 00:00:00 2001 From: core23 Date: Fri, 9 May 2025 08:18:24 +0200 Subject: [PATCH 4/4] Add doctrine/dbal 4 support --- composer.json | 2 +- src/AuditReader.php | 2 +- src/EventListener/CreateSchemaListener.php | 20 +++++++++++++++++++- src/EventListener/LogRevisionsListener.php | 20 +++++++++++++++----- tests/CoreTest.php | 4 ++-- tests/Types/ConvertToPHPType.php | 4 ++-- tests/Types/Issue196Type.php | 2 +- 7 files changed, 41 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index f8ff923c..80bb4b82 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/AuditReader.php b/src/AuditReader.php index 4040ec33..6d883054 100644 --- a/src/AuditReader.php +++ b/src/AuditReader.php @@ -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( diff --git a/src/EventListener/CreateSchemaListener.php b/src/EventListener/CreateSchemaListener.php index f34103ae..e105fddb 100644 --- a/src/EventListener/CreateSchemaListener.php +++ b/src/EventListener/CreateSchemaListener.php @@ -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; @@ -147,8 +148,25 @@ private function createForeignKeys(Table $relatedTable, Table $revisionsTable): $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 + [$this->config->getRevisionFieldName()], + $primaryKey->getColumns(), + [], + $revisionForeignKeyName + ); + + return; + } + $relatedTable->addForeignKeyConstraint( - $revisionsTable, + $revisionsTable->getName(), [$this->config->getRevisionFieldName()], $primaryKey->getColumns(), [], diff --git a/src/EventListener/LogRevisionsListener.php b/src/EventListener/LogRevisionsListener.php index edef21a7..e6311ade 100644 --- a/src/EventListener/LogRevisionsListener.php +++ b/src/EventListener/LogRevisionsListener.php @@ -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; @@ -383,8 +385,16 @@ private function getRevisionId(Connection $conn) ); $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 + throw new \RuntimeException('Unable to retrieve the last revision id.'); + } } $this->revisionId = $revisionId; @@ -523,7 +533,7 @@ private function saveRevisionEntityData(EntityManagerInterface $em, ClassMetadat $conn = $em->getConnection(); $params = [$this->getRevisionId($conn), $revType]; - $types = [\PDO::PARAM_INT, \PDO::PARAM_STR]; + $types = [ParameterType::INTEGER, ParameterType::STRING]; $fields = []; @@ -547,7 +557,7 @@ private function saveRevisionEntityData(EntityManagerInterface $em, ClassMetadat $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)); @@ -642,7 +652,7 @@ private function recordRevisionForManyToManyEntity( ): 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]]; diff --git a/tests/CoreTest.php b/tests/CoreTest.php index b6078d31..22c419cb 100644 --- a/tests/CoreTest.php +++ b/tests/CoreTest.php @@ -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; @@ -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) { diff --git a/tests/Types/ConvertToPHPType.php b/tests/Types/ConvertToPHPType.php index 5dc68f1b..af810241 100644 --- a/tests/Types/ConvertToPHPType.php +++ b/tests/Types/ConvertToPHPType.php @@ -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); } diff --git a/tests/Types/Issue196Type.php b/tests/Types/Issue196Type.php index 9797569f..ad72e9ae 100644 --- a/tests/Types/Issue196Type.php +++ b/tests/Types/Issue196Type.php @@ -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); }