Bug #76876

Extbase Repository->update() does not work

Added by Wolfram Eberius about 3 years ago. Updated almost 3 years ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
Extbase
Start date:
2016-06-30
Due date:
% Done:

0%

TYPO3 Version:
6.2
PHP Version:
5.3
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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...

History

#1 Updated by Wouter Wolters about 3 years ago

  • Status changed from New to Needs Feedback

Without example code we cannot help you any further with your problem. Please provide example code.

#2 Updated by Wolfram Eberius about 3 years ago

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');
}
}

#3 Updated by Wouter Wolters about 3 years ago

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.

#4 Updated by Wolfram Eberius about 3 years ago

That is the exact problem (see description).

#5 Updated by Wouter Wolters about 3 years ago

I don't get what problem than should be in the core?

#6 Updated by Wolfram Eberius about 3 years ago

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).

#7 Updated by Wouter Wolters about 3 years ago

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.

#8 Updated by Wolfram Eberius about 3 years ago

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)?

#9 Updated by Wouter Wolters about 3 years ago

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?

#10 Updated by Wolfram Eberius about 3 years ago

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.

#11 Updated by Philipp Kitzberger about 3 years ago

@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.

#12 Updated by Alexander Opitz almost 3 years ago

  • Status changed from Needs Feedback to New
  • Target version set to Candidate for patchlevel

Also available in: Atom PDF