Neos\Flow\Persistence\Generic\PersistenceManager::persistAll PHP Method

persistAll() public method

Commits new objects and changes to objects in the current persistence session into the backend
public persistAll ( boolean $onlyWhitelistedObjects = false ) : void
$onlyWhitelistedObjects boolean
return void
    public function persistAll($onlyWhitelistedObjects = false)
    {
        if ($onlyWhitelistedObjects) {
            foreach ($this->changedObjects as $object) {
                $this->throwExceptionIfObjectIsNotWhitelisted($object);
            }
            foreach ($this->removedObjects as $object) {
                $this->throwExceptionIfObjectIsNotWhitelisted($object);
            }
            foreach ($this->addedObjects as $object) {
                $this->throwExceptionIfObjectIsNotWhitelisted($object);
            }
        }
        // hand in only aggregate roots, leaving handling of subobjects to
        // the underlying storage layer
        // reconstituted entities must be fetched from the session and checked
        // for changes by the underlying backend as well!
        $this->backend->setAggregateRootObjects($this->addedObjects);
        $this->backend->setChangedEntities($this->changedObjects);
        $this->backend->setDeletedEntities($this->removedObjects);
        $this->backend->commit();
        $this->addedObjects = new \SplObjectStorage();
        $this->removedObjects = new \SplObjectStorage();
        $this->changedObjects = new \SplObjectStorage();
        $this->emitAllObjectsPersisted();
        $this->hasUnpersistedChanges = false;
    }

Usage Example

 /**
  * @test
  */
 public function persistAllPassesRemovedObjectsToBackend()
 {
     $entity2 = new Fixture\Model\Entity2();
     $objectStorage = new \SplObjectStorage();
     $objectStorage->attach($entity2);
     $mockBackend = $this->createMock(Generic\Backend\BackendInterface::class);
     $mockBackend->expects($this->once())->method('setDeletedEntities')->with($objectStorage);
     $manager = new Generic\PersistenceManager();
     $manager->injectBackend($mockBackend);
     $manager->remove($entity2);
     $manager->persistAll();
 }