Example #1
0
 /**
  * @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.');
 }
Example #2
0
 /**
  * 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);
     }
 }
Example #3
0
 /**
  * Maps a single row on an object of the given class
  *
  * @param string $className The name of the target class
  * @param array $row A single array with field_name => value pairs
  * @return object An object of the given class
  */
 protected function mapSingleRow($className, array $row)
 {
     if ($this->identityMap->hasIdentifier($row['uid'], $className)) {
         $object = $this->identityMap->getObjectByIdentifier($row['uid'], $className);
     } else {
         $object = $this->createEmptyObject($className);
         $this->identityMap->registerObject($object, $row['uid']);
         $this->thawProperties($object, $row);
         $object->_memorizeCleanState();
         $this->persistenceSession->registerReconstitutedObject($object);
     }
     return $object;
 }