0
votes

I want to update some Extbase Objects in a Scheduler Task. I'm calling the Repository to get all Objects. Then I set one Property of that object, and Try do Update it. That throws me this Exception

The object of type "FFPI\FfpiNodeUpdates\Domain\Model\Node" given to update must be persisted already, but is new.

vendor/typo3/cms/typo3/sysext/extbase/Classes/Persistence/Generic/PersistenceManager.php:237

the trace is:
0: TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
1: TYPO3\CMS\Extbase\Persistence\Repository
2: FFPI\FfpiNodeUpdates\Task\NotificationTask
3: FFPI\FfpiNodeUpdates\Task\NotificationTask
4: TYPO3\CMS\Scheduler\Scheduler
5: TYPO3\CMS\Scheduler\Controller\SchedulerModuleController
...

my code can be shortened to this

$nodes = $this->nodeRepository->findAll()->toArray();
foreach ($nodes as $node){
    $this->myUpdateFunction($node);
}
private function myUpdateFunction(Node $node)
{
    $node->setOnline(true);
    $this->nodeRepository->update($node); // <- Gives the exception
}

It worked fine in 7.6 but dose not work anymore in 8.7

I tried to get the Repository with
* dependency Injection (dose not work at all)
* GeneralUtility::makeInstance() (I get the repo, but have the exception)
* objectManager->get() (I get the repo, but have the exception)

Update: I have this problem also in version 9.5

1

1 Answers

0
votes

First of all you should use the makeInstance() function only to get the Object Manager, then you should use him instead of the makeInstance() to deal with your Objects.

For your main problem, I'm not sure if it helps but you may have to use PersistanceManger->persistAll(); In its code, there is a comment saying: "Commits new objects and changes to objects in the current persistence session into the backend"

I hope this helps ^^