Skip to content
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
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 @@ -292,7 +292,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(strval($allDiscrValues[$subclassName]));
}

$whereSQL .= \sprintf(
Expand Down
19 changes: 18 additions & 1 deletion src/EventListener/CreateSchemaListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,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(\Composer\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 154 in src/EventListener/CreateSchemaListener.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/EventListener/CreateSchemaListener.php:154: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
19 changes: 14 additions & 5 deletions src/EventListener/LogRevisionsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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 @@ -195,7 +196,7 @@
$sql .= ' AND '.$columnName.' = ?';
}

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

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

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/EventListener/LogRevisionsListener.php:199: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 @@ -380,8 +381,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(\Composer\InstalledVersions::getVersion('doctrine/dbal') ?? '', '4.0.0', '<')) {
if (false === $revisionId) { // @phpstan-ignore-line doctrine/dbal 3 lastInsertId() can return false

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

View workflow job for this annotation

GitHub Actions / Psalm

TypeDoesNotContainType

src/EventListener/LogRevisionsListener.php:391: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 @@ -520,7 +529,7 @@
$conn = $em->getConnection();

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

$fields = [];

Expand All @@ -544,7 +553,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 @@ -619,7 +628,7 @@
}
}

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

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

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

src/EventListener/LogRevisionsListener.php:631: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 @@ -639,7 +648,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