Skip to content
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

Address API removals from upstream #9885

Merged
merged 22 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0ef08c5
preUpdate: Add restriction that changed field needs to be in computed…
ThomasLandauer Jun 28, 2022
b1419dd
Migrate more usages of SchemaTool::createSchema()
greg0ire Jul 1, 2022
3295ccf
Merge pull request #9874 from greg0ire/migrate-to-csfm
greg0ire Jul 1, 2022
eea5339
Change parent classes
franmomu Jul 2, 2022
79447cb
ObjectHydrator: defer initialization of potentially empty collections
popov-a-e Jul 3, 2022
83c1ad2
Merge pull request #9870 from popov-a-e/GH-9807
greg0ire Jul 3, 2022
68405f3
Merge pull request #9876 from franmomu/extend_event_manager_args
greg0ire Jul 4, 2022
306b5f9
Fix typo in AbstractQuery
CarlSchwan Jul 6, 2022
f79ec43
Merge pull request #9880 from CarlSchwan/patch-1
greg0ire Jul 6, 2022
291765e
PHPStan 1.8.0 (#9887)
derrabus Jul 8, 2022
1538d70
Merge branch '2.12.x' into 2.13.x
derrabus Jul 8, 2022
baf6a39
Test invalid mapping file with boolean model
greg0ire Jul 10, 2022
d6dcfbd
Use ::class notation
greg0ire Jul 10, 2022
7ed0db0
Document what we test in test method name
greg0ire Jul 10, 2022
00989d6
Remove SerializationModel from generic model set
greg0ire Jul 10, 2022
ab4844b
Merge pull request #9892 from greg0ire/address-array-object-type-depr…
greg0ire Jul 10, 2022
4a62b66
Merge remote-tracking branch 'origin/2.12.x' into 2.13.x
greg0ire Jul 10, 2022
48b4f63
Merge pull request #9893 from greg0ire/2.13.x
greg0ire Jul 10, 2022
db9c43f
Merge remote-tracking branch 'origin/2.13.x' into fix-build
greg0ire Jul 12, 2022
68dc5fe
Rely on platform options
greg0ire Jul 7, 2022
1fa1e70
Address removal/deprecation of ArrayType/ObjectType
greg0ire Jul 12, 2022
1ac9d52
Ignore errors caused by nullable assets filter
greg0ire Jul 12, 2022
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
11 changes: 11 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,17 @@ Calling `AbstractQuery::setFetchMode()` with anything else than
`Doctrine\ORM\Mapping::FETCH_LAZY` being used. Relying on that behavior is
deprecated and will result in an exception in 3.0.

## Deprecated `getEntityManager()` in `Doctrine\ORM\Event\OnClearEventArgs` and `Doctrine\ORM\Event\*FlushEventArgs`

This method has been deprecated in:

* `Doctrine\ORM\Event\OnClearEventArgs`
* `Doctrine\ORM\Event\OnFlushEventArgs`
* `Doctrine\ORM\Event\PostFlushEventArgs`
* `Doctrine\ORM\Event\PreFlushEventArgs`

It will be removed in 3.0. Use `getObjectManager()` instead.

## Prepare split of output walkers and tree walkers

In 3.0, `SqlWalker` and its child classes won't implement the `TreeWalker`
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"doctrine/annotations": "^1.13",
"doctrine/coding-standard": "^9.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.7.15",
"phpstan/phpstan": "1.8.0",
"phpunit/phpunit": "^9.5",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.7.1",
Expand Down
3 changes: 3 additions & 0 deletions docs/en/reference/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,9 @@ A simple example for this event looks like:
if ($eventArgs->getEntity() instanceof User) {
if ($eventArgs->hasChangedField('name') && $eventArgs->getNewValue('name') == 'Alice') {
$eventArgs->setNewValue('name', 'Bob');
// The following will only work if `status` is already present in the computed changeset.
// Otherwise it will throw an InvalidArgumentException:
$eventArgs->setNewValue('status', 'active');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function setCacheable(bool $cacheable): static
}

/**
* @return bool TRUE if the query results are enable for second level cache, FALSE otherwise.
* @return bool TRUE if the query results are enabled for second level cache, FALSE otherwise.
*/
public function isCacheable(): bool
{
Expand Down
23 changes: 15 additions & 8 deletions lib/Doctrine/ORM/Event/OnClearEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\OnClearEventArgs as BaseOnClearEventArgs;

/**
* Provides event arguments for the onClear event.
*
* @link www.doctrine-project.org
*
* @extends BaseOnClearEventArgs<EntityManagerInterface>
*/
class OnClearEventArgs extends EventArgs
class OnClearEventArgs extends BaseOnClearEventArgs
{
public function __construct(
private EntityManagerInterface $em
) {
}

/**
* Retrieves associated EntityManager.
*
* @deprecated 2.13. Use {@see getObjectManager} instead.
*/
public function getEntityManager(): EntityManagerInterface
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}
}
26 changes: 15 additions & 11 deletions lib/Doctrine/ORM/Event/OnFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\ManagerEventArgs;

/**
* Provides event arguments for the preFlush event.
*
* @link www.doctrine-project.org
*
* @extends ManagerEventArgs<EntityManagerInterface>
*/
class OnFlushEventArgs extends EventArgs
class OnFlushEventArgs extends ManagerEventArgs
{
/** @var EntityManagerInterface */
private $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

/**
* Retrieve associated EntityManager.
*
* @deprecated 2.13. Use {@see getObjectManager} instead.
*
* @return EntityManagerInterface
*/
public function getEntityManager()
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}
}
26 changes: 15 additions & 11 deletions lib/Doctrine/ORM/Event/PostFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\ManagerEventArgs;

/**
* Provides event arguments for the postFlush event.
*
* @link www.doctrine-project.org
*
* @extends ManagerEventArgs<EntityManagerInterface>
*/
class PostFlushEventArgs extends EventArgs
class PostFlushEventArgs extends ManagerEventArgs
{
/** @var EntityManagerInterface */
private $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

/**
* Retrieves associated EntityManager.
*
* @deprecated 2.13. Use {@see getObjectManager} instead.
*
* @return EntityManagerInterface
*/
public function getEntityManager()
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}
}
26 changes: 15 additions & 11 deletions lib/Doctrine/ORM/Event/PreFlushEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@

namespace Doctrine\ORM\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\Event\ManagerEventArgs;

/**
* Provides event arguments for the preFlush event.
*
* @link www.doctrine-project.com
*
* @extends ManagerEventArgs<EntityManagerInterface>
*/
class PreFlushEventArgs extends EventArgs
class PreFlushEventArgs extends ManagerEventArgs
{
/** @var EntityManagerInterface */
private $em;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}

/**
* @deprecated 2.13. Use {@see getObjectManager} instead.
*
* @return EntityManagerInterface
*/
public function getEntityManager()
{
return $this->em;
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9875',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getObjectManager() instead.',
__METHOD__
);

return $this->getObjectManager();
}
}
31 changes: 21 additions & 10 deletions lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class ObjectHydrator extends AbstractHydrator
/** @var mixed[] */
private array $initializedCollections = [];

/** @var array<string, PersistentCollection> */
private $uninitializedCollections = [];

/** @var mixed[] */
private array $existingCollections = [];

Expand Down Expand Up @@ -105,10 +108,11 @@ protected function cleanup(): void

parent::cleanup();

$this->identifierMap =
$this->initializedCollections =
$this->existingCollections =
$this->resultPointers = [];
$this->identifierMap =
$this->initializedCollections =
$this->uninitializedCollections =
$this->existingCollections =
$this->resultPointers = [];

if ($eagerLoad) {
$this->_uow->triggerEagerLoads();
Expand All @@ -119,10 +123,11 @@ protected function cleanup(): void

protected function cleanupAfterRowIteration(): void
{
$this->identifierMap =
$this->initializedCollections =
$this->existingCollections =
$this->resultPointers = [];
$this->identifierMap =
$this->initializedCollections =
$this->uninitializedCollections =
$this->existingCollections =
$this->resultPointers = [];
}

/**
Expand All @@ -141,6 +146,12 @@ protected function hydrateAllData(): array
$coll->takeSnapshot();
}

foreach ($this->uninitializedCollections as $coll) {
if (! $coll->isInitialized()) {
$coll->setInitialized(true);
}
}

return $result;
}

Expand Down Expand Up @@ -397,8 +408,8 @@ protected function hydrateRowData(array $row, array &$result): void
}
} elseif (! $reflFieldValue) {
$this->initRelatedCollection($parentObject, $parentClass, $relationField, $parentAlias);
} elseif ($reflFieldValue instanceof PersistentCollection && $reflFieldValue->isInitialized() === false) {
$reflFieldValue->setInitialized(true);
} elseif ($reflFieldValue instanceof PersistentCollection && $reflFieldValue->isInitialized() === false && ! isset($this->uninitializedCollections[$oid . $relationField])) {
$this->uninitializedCollections[$oid . $relationField] = $reflFieldValue;
}
} else {
// PATH B: Single-valued association
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($file = 'php://output', $context = '')
*/
public function onFlush(OnFlushEventArgs $args)
{
$this->dumpIdentityMap($args->getEntityManager());
$this->dumpIdentityMap($args->getObjectManager());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ private function gatherColumnOptions(array $mapping): array
return [];
}

$options = array_intersect_key($mappingOptions, array_flip(self::KNOWN_COLUMN_OPTIONS));
$options['customSchemaOptions'] = array_diff_key($mappingOptions, $options);
$options = array_intersect_key($mappingOptions, array_flip(self::KNOWN_COLUMN_OPTIONS));
$options['platformOptions'] = array_diff_key($mappingOptions, $options);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if I should backport this as well… Column::getCustomSchemaOptions() will not return the same thing as previously, not sure how acceptable that is.

Copy link
Member

@morozov morozov Jul 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave it as is in older branches. This API is supported up until DBAL 4.0, so there's no reason to break anything prior to supporting it.


return $options;
}
Expand Down
4 changes: 4 additions & 0 deletions phpstan-dbal4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ parameters:
-
message: '~^Parameter #1 \$command of method Symfony\\Component\\Console\\Application::add\(\) expects Symfony\\Component\\Console\\Command\\Command, Doctrine\\DBAL\\Tools\\Console\\Command\\ReservedWordsCommand given\.$~'
path: lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php

-
message: '~Strict comparison using \=\=\= between callable\(\)\: mixed and null will always evaluate to false\.~'
path: lib/Doctrine/ORM/Tools/SchemaTool.php
11 changes: 11 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
</ignoreFiles>
</projectFiles>
<issueHandlers>
<DeprecatedConstant>
<errorLevel type="suppress">
<file name="lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php" />
</errorLevel>
</DeprecatedConstant>
<DeprecatedClass>
<errorLevel type="suppress">
<!-- Remove on 3.0.x -->
Expand Down Expand Up @@ -111,6 +116,12 @@
<referencedFunction name="Doctrine\DBAL\Connection::lastInsertId"/>
</errorLevel>
</TooManyArguments>
<TypeDoesNotContainNull>
<errorLevel type="suppress">
<!-- DBAL 3 compatibility -->
<file name="lib/Doctrine/ORM/Tools/SchemaTool.php"/>
</errorLevel>
</TypeDoesNotContainNull>
<TypeDoesNotContainType>
<errorLevel type="suppress">
<file name="lib/Doctrine/ORM/Internal/SQLResultCasing.php"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function onFlush(OnFlushEventArgs $args): void
{
//echo "---preFlush".PHP_EOL;

$em = $args->getEntityManager();
$em = $args->getObjectManager();
$uow = $em->getUnitOfWork();

foreach ($uow->getScheduledEntityInsertions() as $entity) {
Expand Down
11 changes: 1 addition & 10 deletions tests/Doctrine/Tests/ORM/Functional/InsertableUpdatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\ORM\Tools\ToolsException;
use Doctrine\Tests\Models\Upsertable\Insertable;
use Doctrine\Tests\Models\Upsertable\Updatable;
use Doctrine\Tests\OrmFunctionalTestCase;
Expand All @@ -15,15 +14,7 @@ protected function setUp(): void
{
parent::setUp();

try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(Updatable::class),
$this->_em->getClassMetadata(Insertable::class),
]
);
} catch (ToolsException) {
}
$this->createSchemaForModels(Updatable::class, Insertable::class);
}

public function testNotInsertableIsFetchedFromDatabase(): void
Expand Down
5 changes: 1 addition & 4 deletions tests/Doctrine/Tests/ORM/Functional/NotifyPolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ protected function setUp(): void

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8383');

$this->_schemaTool->createSchema([
$this->_em->getClassMetadata(NotifyUser::class),
$this->_em->getClassMetadata(NotifyGroup::class),
]);
$this->createSchemaForModels(NotifyUser::class, NotifyGroup::class);
}

public function testChangeTracking(): void
Expand Down
Loading