Project

General

Profile

Actions

Bug #76876

closed

Extbase Repository->update() does not work

Added by Wolfram Eberius almost 8 years ago. Updated about 4 years ago.

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

0%

Estimated time:
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...

Actions #1

Updated by Wouter Wolters almost 8 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.

Actions #2

Updated by Wolfram Eberius almost 8 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');
}
}
Actions #3

Updated by Wouter Wolters almost 8 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.

Actions #4

Updated by Wolfram Eberius almost 8 years ago

That is the exact problem (see description).

Actions #5

Updated by Wouter Wolters almost 8 years ago

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

Actions #6

Updated by Wolfram Eberius almost 8 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).

Actions #7

Updated by Wouter Wolters almost 8 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.

Actions #8

Updated by Wolfram Eberius almost 8 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)?

Actions #9

Updated by Wouter Wolters almost 8 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?

Actions #10

Updated by Wolfram Eberius almost 8 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.

Actions #11

Updated by Anonymous over 7 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.

Actions #12

Updated by Alexander Opitz over 7 years ago

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

Updated by Susanne Moog about 4 years ago

  • Status changed from New to Closed

see https://github.com/TYPO3-Documentation/TYPO3CMS-Book-ExtbaseFluid/pull/336 - the example is a shortened example, the full example is available in the example extension.

Actions #14

Updated by Sybille Peters about 4 years ago

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.

Actions

Also available in: Atom PDF