Skip to content

Commit b2c163c

Browse files
committed
BUGFIX: Prevent premature connection to database before PersistenceManager::persistAllowedObjects
For every simple GET request `persistAllowedObjects` is called via the Package.php in flow. This results in building a db connection, even if there is nothing to do. So if neither the persistentManger nor the entityManager has been created by the object manager instantiating one and thus the other which leads to "work". For the check if the `entityManager` `isOpen` we activate the lazy dependency. Now in this retrieval process - even though doctrines connection is lazy itself - the connection will be made forcefully see `\Neos\Flow\Persistence\Doctrine\EntityManagerFactory::create` line 120 (https://github.com/neos/flow-development-collection/blob/11e2348125dd8286ff9ccc088e5d187dc9143bf5/Neos.Flow/Classes/Persistence/Doctrine/EntityManagerFactory.php#L120) or https://github.com/neos/flow-development-collection/blob/d93b6b09ca2071c87812a9ef4bc120201c44608a/Neos.Flow/Classes/Persistence/Doctrine/EntityManagerConfiguration.php#L229 This is ironic because if there is no connection - or no entity manager and persistence manager in the first place, the current process cannot have made any changes to the transaction. Reason for this is that the Package.php has a wrong check which looks for if the PersistenceManager _exists_ as php class at all rather than if we have an active instance loaded. This is an old regression from: 163e204
1 parent c4d1b64 commit b2c163c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Neos.Flow/Classes/Package.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ public function boot(Core\Bootstrap $bootstrap)
7171
$dispatcher = $bootstrap->getSignalSlotDispatcher();
7272

7373
$dispatcher->connect(Mvc\Dispatcher::class, 'afterControllerInvocation', function ($request) use ($bootstrap) {
74-
// No auto-persistence if there is no PersistenceManager registered
74+
// No auto-persistence if there is no PersistenceManager loaded
7575
// This signal will not be fired at compile time, as it's only emitted for web requests which happen at runtime.
7676
if (
77-
$bootstrap->getObjectManager()->has(Persistence\PersistenceManagerInterface::class)
77+
/** @phpstan-ignore-next-line the object manager interface doesn't specify this method */
78+
$bootstrap->getObjectManager()->hasInstance(Persistence\PersistenceManagerInterface::class)
7879
) {
7980
if (SecurityHelper::hasSafeMethod($request->getHttpRequest()) !== true) {
8081
$bootstrap->getObjectManager()->get(Persistence\PersistenceManagerInterface::class)->persistAll();
@@ -86,9 +87,10 @@ public function boot(Core\Bootstrap $bootstrap)
8687
});
8788

8889
$dispatcher->connect(Cli\Dispatcher::class, 'afterControllerInvocation', function () use ($bootstrap) {
89-
// No auto-persistence if there is no PersistenceManager registered or during compile time
90+
// No auto-persistence if there is no PersistenceManager loaded or during compile time
9091
if (
91-
$bootstrap->getObjectManager()->has(Persistence\PersistenceManagerInterface::class)
92+
/** @phpstan-ignore-next-line the object manager interface doesn't specify this method */
93+
$bootstrap->getObjectManager()->hasInstance(Persistence\PersistenceManagerInterface::class)
9294
&& !($bootstrap->getObjectManager() instanceof CompileTimeObjectManager)
9395
) {
9496
$bootstrap->getObjectManager()->get(Persistence\PersistenceManagerInterface::class)->persistAll();

0 commit comments

Comments
 (0)