Skip to content

Commit

Permalink
Merge pull request #9833 from greg0ire/deprecate-sequence-based-ig
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Jun 10, 2022
2 parents 9efeefb + 3f84304 commit d99e64c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Upgrade to 2.13

## Deprecated using the `IDENTITY` identifier strategy on platform that do not support identity columns

If identity columns are emulated with sequences on the platform you are using,
you should switch to the `SEQUENCE` strategy.

## Deprecated passing `null` to `Doctrine\ORM\Query::setFirstResult()`

`$query->setFirstResult(null);` is equivalent to `$query->setFirstResult(0)`.
Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/ORM/Id/BigIntegerIdentityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ORM\Id;

use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;

/**
Expand All @@ -27,6 +28,15 @@ class BigIntegerIdentityGenerator extends AbstractIdGenerator
*/
public function __construct($sequenceName = null)
{
if ($sequenceName !== null) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/8850',
'Passing a sequence name to the IdentityGenerator is deprecated in favor of using %s. $sequenceName will be removed in ORM 3.0',
SequenceGenerator::class
);
}

$this->sequenceName = $sequenceName;
}

Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/ORM/Id/IdentityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ORM\Id;

use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;

/**
Expand All @@ -27,6 +28,15 @@ class IdentityGenerator extends AbstractIdGenerator
*/
public function __construct($sequenceName = null)
{
if ($sequenceName !== null) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/8850',
'Passing a sequence name to the IdentityGenerator is deprecated in favor of using %s. $sequenceName will be removed in ORM 3.0',
SequenceGenerator::class
);
}

$this->sequenceName = $sequenceName;
}

Expand Down
13 changes: 13 additions & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use function count;
use function end;
use function explode;
use function get_class;
use function in_array;
use function is_subclass_of;
use function str_contains;
Expand Down Expand Up @@ -558,6 +559,18 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void

// Platforms that do not have native IDENTITY support need a sequence to emulate this behaviour.
if ($this->getTargetPlatform()->usesSequenceEmulatedIdentityColumns()) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/8850',
<<<'DEPRECATION'
Context: Loading metadata for class %s
Problem: Using the IDENTITY generator strategy with platform "%s" is deprecated and will not be possible in Doctrine ORM 3.0.
Solution: Use the SEQUENCE generator strategy instead.
DEPRECATION
,
$class->name,
get_class($this->getTargetPlatform())
);
$columnName = $class->getSingleIdentifierColumnName();
$quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']);
$sequencePrefix = $class->getSequencePrefix($this->getTargetPlatform());
Expand Down
21 changes: 21 additions & 0 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@ public function testGetMetadataForSingleClass(): void
self::assertTrue($cmMap1->hasField('name'));
}

public function testUsingIdentityWithAPlatformThatDoesNotSupportIdentityColumnsIsDeprecated(): void
{
$cm = $this->createValidClassMetadata();
$cm->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
$cmf = new ClassMetadataFactoryTestSubject();
$driver = $this->createMock(Driver::class);
$platform = $this->createStub(AbstractPlatform::class);
$platform->method('usesSequenceEmulatedIdentityColumns')->willReturn(true);
$platform->method('getIdentitySequenceName')->willReturn('whatever');
$driver->method('getDatabasePlatform')->willReturn($platform);
$entityManager = $this->createEntityManager(
new MetadataDriverMock(),
new Connection([], $driver)
);
$cmf->setEntityManager($entityManager);
$cmf->setMetadataForClass($cm->name, $cm);

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8850');
$cmf->getMetadataFor($cm->name);
}

public function testItThrowsWhenUsingAutoWithIncompatiblePlatform(): void
{
$cm1 = $this->createValidClassMetadata();
Expand Down

0 comments on commit d99e64c

Please sign in to comment.