Feature #47951

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

Added by Alex no-lastname-given over 8 years ago. Updated over 8 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Persistence
Target version:
-
Start date:
2013-05-05
Due date:
% Done:

0%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

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 ExceptionResolved2013-08-30

Actions
#1

Updated by Bastian Waidelich over 8 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:

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

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

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

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 over 8 years ago

  • Target version set to 2.1
#3

Updated by Robert Lemke over 8 years ago

  • Target version deleted (2.1)

Also available in: Atom PDF