/** * @test */ public function findByidentifierReturnsResultOfGetObjectByIdentifierCallFromBackend() { $identifier = '42'; $object = new \stdClass(); $expectedResult = $this->getMock(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface::class); $expectedResult->expects($this->once())->method('getFirst')->will($this->returnValue($object)); $this->mockQuery->expects($this->any())->method('getQuerySettings')->will($this->returnValue($this->mockQuerySettings)); $this->mockQuery->expects($this->once())->method('matching')->will($this->returnValue($this->mockQuery)); $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($expectedResult)); // skip backend, as we want to test the backend $this->mockSession->expects($this->any())->method('hasIdentifier')->will($this->returnValue(FALSE)); $this->assertSame($object, $this->repository->findByIdentifier($identifier)); }
/** * Finds an object matching the given identifier. * * @param mixed $identifier The identifier of the object to find * @return object The matching object if found, otherwise NULL * @api */ public function findByIdentifier($identifier) { /** * @todo: This method must be changed again in 6.2 + 1 * This is marked @deprecated to be found in cleanup sessions. * * The repository should directly talk to the backend which * does not respect query settings of the repository as * findByIdentifier is strictly defined by finding an * undeleted object by its identifier regardless if it * is hidden/visible or a versioning/translation overlay. * * As a consequence users will be forced to overwrite this method * and mimic this behaviour to be able to find objects by identifier * respecting their query settings from 6.1 + 1 on. */ if ($this->session->hasIdentifier($identifier, $this->objectType)) { $object = $this->session->getObjectByIdentifier($identifier, $this->objectType); } else { $query = $this->createQuery(); $query->getQuerySettings()->setRespectStoragePage(FALSE); $query->getQuerySettings()->setRespectSysLanguage(FALSE); $object = $query->matching($query->equals('uid', $identifier))->execute()->getFirst(); } return $object; }
/** * Iterate over deleted aggregate root objects and process them * * @return void */ protected function processDeletedObjects() { foreach ($this->deletedEntities as $entity) { if ($this->session->hasObject($entity)) { $this->removeEntity($entity); $this->session->unregisterReconstitutedEntity($entity); $this->session->unregisterObject($entity); } } $this->deletedEntities = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); }
/** * This is a workaround to help controller actions to find (hidden) posts. * * @param $argumentName */ protected function registerClubFromRequest($argumentName) { $argument = $this->request->getArgument($argumentName); if (is_array($argument)) { // get club from form ($_POST) $club = $this->clubRepository->findHiddenEntryByUid($argument['__identity']); } elseif (is_object($argument)) { // get club from domain model $club = $argument; } else { // get club from UID $club = $this->clubRepository->findHiddenEntryByUid($argument); } $this->session->registerObject($club, $club->getUid()); }
/** * Returns the mapped classProperty from the identiyMap or * mapResultToPropertyValue() * * If the field value is empty and the column map has no parent key field name, * the relation will be empty. If the persistence session has a registered object of * the correct type and identity (fieldValue), this function returns that object. * Otherwise, it proceeds with mapResultToPropertyValue(). * * @param DomainObjectInterface $parentObject * @param string $propertyName * @param mixed $fieldValue the raw field value * @return mixed * @see mapResultToPropertyValue() */ protected function mapObjectToClassProperty(DomainObjectInterface $parentObject, $propertyName, $fieldValue) { if ($this->propertyMapsByForeignKey($parentObject, $propertyName)) { $result = $this->fetchRelated($parentObject, $propertyName, $fieldValue); $propertyValue = $this->mapResultToPropertyValue($parentObject, $propertyName, $result); } else { if ($fieldValue === '') { $propertyValue = $this->getEmptyRelationValue($parentObject, $propertyName); } else { $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName); if ($this->persistenceSession->hasIdentifier($fieldValue, $propertyMetaData['type'])) { $propertyValue = $this->persistenceSession->getObjectByIdentifier($fieldValue, $propertyMetaData['type']); } else { $result = $this->fetchRelated($parentObject, $propertyName, $fieldValue); $propertyValue = $this->mapResultToPropertyValue($parentObject, $propertyName, $result); } } } return $propertyValue; }
/** * Checks if the given object has ever been persisted. * * @param object $object The object to check * @return bool TRUE if the object is new, FALSE if the object exists in the persistence session * @api */ public function isNewObject($object) { return $this->persistenceSession->hasObject($object) === false; }
/** * Unregister an object * * @param object $object * @return void * @deprecated since 6.1, will be removed two versions later, use the persistence session instead */ public function unregisterObject($object) { $this->persistenceSession->unregisterObject($object); }