Feature #47951

Warn if persistence stack is not empty at the end of a get-request

Added by Alex no-lastname-given about 2 years ago. Updated about 2 years ago.

Status:New Start date:2013-05-05
Priority:Should have Due date:
Assigned To:- % Done:

0%

Category:Persistence
Target version:-
PHP Version: Complexity:
Has patch:No

Description

Because the flow framework follows a rfc-standard, persistanceManager::persistAll() is not executed automatically for a get request. The framework should at least throws an exception if the persistance stack is not empty at the end of a get request.


Related issues

related to TYPO3.Flow - Feature #51570: Unpersisted changes in Safe Requests should throw an Exce... Resolved 2013-08-30

History

#1 Updated by Bastian Waidelich about 2 years ago

Hi Alex no-lastname-given, ;)

interesting idea (at least for development context).

The code that is currently responsible for this behavior is in the Package.php file of Flow:

1$dispatcher->connect('TYPO3\Flow\Mvc\Dispatcher', 'afterControllerInvocation', function($request) use($bootstrap) {
2    if (!$request instanceof \TYPO3\Flow\Mvc\ActionRequest || $request->getHttpRequest()->isMethodSafe() !== TRUE) {
3        $bootstrap->getObjectManager()->get('TYPO3\Flow\Persistence\PersistenceManagerInterface')->persistAll();
4    }
5});

Technically this could probably be changed to s.th. like this:

 1$dispatcher->connect('TYPO3\Flow\Mvc\Dispatcher', 'afterControllerInvocation', function($request) use($bootstrap) {
 2    if ($request instanceof \TYPO3\Flow\Mvc\ActionRequest) {
 3        return;
 4    }
 5    $persistenceManager = $bootstrap->getObjectManager()->get('TYPO3\Flow\Persistence\PersistenceManagerInterface');
 6    if ($request->getHttpRequest()->isMethodSafe() !== TRUE) {
 7        $persistenceManager->persistAll();
 8    } elseif ($bootstrap->getContext()->isDevelopment() && $persistenceManager->hasChanges()) {
 9        // log exception
10    }
11});

Three things to keep in mind:

  1. There is no "PersistenceManager::hasChanges()" method. Doctrine allows you to detect modifications AFAIK but we'd have to add this to our API
  1. We can't throw an exception in the "afterControllerInvocation" slot because that's executed too late – it could be thrown before maybe or the exception could be logged instead
  1. We currently only omit the "persistAll()" call for safe requests but the plan is not to load the fully fledged persistence layer for safe requests at some point (for performance reasons). But probably we need to be able to initialize it "lazily" anyways in order to allow people to call persistAll() manually

#2 Updated by Robert Lemke about 2 years ago

  • Target version set to 2.1

#3 Updated by Robert Lemke about 2 years ago

  • Target version deleted (2.1)

Also available in: Atom PDF