/** * 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 addAllAddsAllObjectsFromAnotherStorage() { $object1 = new StdClass(); $object2 = new StdClass(); $objectStorageA = new Tx_Extbase_Persistence_ObjectStorage(); // It might be better to mock this $objectStorageA->attach($object1, 'foo'); $objectStorageB = new Tx_Extbase_Persistence_ObjectStorage(); $objectStorageB->attach($object2, 'baz'); $this->assertEquals($objectStorageB->offsetExists($object1), FALSE); $objectStorageB->addAll($objectStorageA); $this->assertEquals($objectStorageB[$object1], 'foo'); $this->assertEquals($objectStorageB[$object2], 'baz'); }
/** * @see Tx_Extbase_Persistence_ObjectStorage::addAll */ public function addAll($storage) { $this->initialize(); parent::addAll($storage); }