Bug #76876
closed
Extbase Repository->update() does not work
Added by Wolfram Eberius over 8 years ago.
Updated over 4 years ago.
Description
The update() function of an Extbase repository does not work as mentioned in https://docs.typo3.org/typo3cms/ExtbaseFluidBook/3-BlogExample/4-and-action.html. If one tries to update an existing record, TYPO3 returns an Exception, telling the object to be updated is new. One can find the reason in the TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager's isNewObject() function, where the object to be updated can not be found in it's $persistenceSession (where it should be?).
TYPO3 6.2.25
Extbase 6.2
PHP 5.3.19
Exception: The modified object given to update() was not of the type...
- Status changed from New to Needs Feedback
Without example code we cannot help you any further with your problem. Please provide example code.
Sorry, just edited the docs so far (https://docs.typo3.org/typo3cms/ExtbaseFluidBook/3-BlogExample/4-and-action.html).
Not working:
class BlogController extends ActionController {
public function updateAction(Blog $blog) {
$this->blogRepository->update($blog);
$this->redirect('index');
}
}
Working:
class BlogController extends ActionController {
public function updateAction(Blog $blog) {
$this->blogRepository->add($blog);
$this->redirect('index');
}
}
When creating a new blogpost you need to use add()
When editing a blogpost you need to use update()
Looking at your code you use the same action for both actions.
You need to make separate functions to have correct working code.
That is the exact problem (see description).
I don't get what problem than should be in the core?
The problem is that the base update function of the repository class does not work as documented. If one tries to update an existing object, e.g. via a Frontend plugin, Extbase's persistence system would tell the object does not yet exist (since it's spl-object-hash is not stored in the session).
You first need to fetch the object and with this action the object is known in the persistence session. I never experienced an issue with the update function and I wrote alot of extension using extbase.
Ok, my point was just that id did not work as given in the documentation. And shouldn't it be an issue of the framework to fetch the object before the update action is executed (so that in the end it would work as documented)?
The example code is missing the phpDoc above the method. It should auto fetch the object when calling the updateAction. Can you try to add the correct phpDoc above the method?
Hey Wouter, I can not test it now, I stick with the workaround for now. I could try next time I come around that issue.
Anyway, if that is the solution then it should be part of the documentation, shouldn't it? That is my point, a documentation documenting the way it will work. Thanks again.
@Wolfram: using lazy loading by any chance? I ran into this bug when trying to update an object that has been loaded with lazy loading in is thereby apparently of class \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy which is clearly not of type <MyModel> and thus causing the exception.
- Status changed from Needs Feedback to New
- Target version set to Candidate for patchlevel
- Status changed from New to Closed
The documentation was updated: https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/3-BlogExample/4-and-action.html (for version 10). The change was backported to older versions 9.5 and 8.7.
You are using TYPO3 6.2. This version is no longer supported as LTS (long term support). ELTS (extended long term support, which must be bought via https://typo3.com) ends on April 4, 2020, see https://get.typo3.org/
The earliest version that is still supported as LTS is TYPO3 8.7 but LTS runs out this year at end of March (https://get.typo3.org), followed by ELTS period until 2023.
The documentation page you mentioned is not available for 6.2 - The earliest version that is online and supported is for TYPO3 8.7. You may find that there are some differences between TYPO3 versions which may make it difficult if following documentation for later TYPO3 versions than you are currently using.
Also available in: Atom
PDF