/** * Commits new objects and changes to objects in the current persistence * session into the backend * * @return void * @api */ public function persistAll() { $aggregateRootObjects = new Tx_Extbase_Persistence_ObjectStorage(); $removedObjects = new Tx_Extbase_Persistence_ObjectStorage(); // fetch and inspect objects from all known repositories foreach ($this->repositoryClassNames as $repositoryClassName) { $repository = $this->objectManager->get($repositoryClassName); $aggregateRootObjects->addAll($repository->getAddedObjects()); $removedObjects->addAll($repository->getRemovedObjects()); } foreach ($this->session->getReconstitutedObjects() as $reconstitutedObject) { if (class_exists(str_replace('_Model_', '_Repository_', get_class($reconstitutedObject)) . 'Repository')) { $aggregateRootObjects->attach($reconstitutedObject); } } // hand in only aggregate roots, leaving handling of subobjects to // the underlying storage layer $this->backend->setAggregateRootObjects($aggregateRootObjects); $this->backend->setDeletedObjects($removedObjects); $this->backend->commit(); // this needs to unregister more than just those, as at least some of // the subobjects are supposed to go away as well... // OTOH those do no harm, changes to the unused ones should not happen, // so all they do is eat some memory. foreach ($removedObjects as $removedObject) { $this->session->unregisterReconstitutedObject($removedObject); } }
/** * @test */ public function objectCanBeUnregisteredAsReconstituted() { $persistenceSession = new Tx_Extbase_Persistence_Session(); $entity = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity'); $persistenceSession->registerReconstitutedObject($entity); $persistenceSession->unregisterReconstitutedObject($entity); $reconstitutedObjects = $persistenceSession->getReconstitutedObjects(); $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.'); }