コード例 #1
0
 /**
  * @param array $source
  * @param boolean $enableSideLoading
  * @return string
  */
 public function serialize(array $source, $enableSideLoading = TRUE)
 {
     $data = array();
     foreach ($source as $variableName => $valueToRender) {
         if (class_exists($variableName)) {
             $variableName = EmberDataUtility::uncamelizeClassName($variableName);
         }
         $data[$variableName] = $this->transformValue($valueToRender, isset($this->configuration[$variableName]) ? $this->configuration[$variableName] : array(), FALSE, $enableSideLoading);
     }
     if (!empty($this->objectsToSideload)) {
         foreach ($this->objectsToSideload as $objectType => $objectUuids) {
             if (empty($objectUuids)) {
                 continue;
             }
             if (!isset($data[$objectType])) {
                 $data[$objectType] = array();
             }
             foreach ($objectUuids as $objectUuid) {
                 $object = $this->persistenceManager->getObjectByIdentifier($objectUuid, EmberDataUtility::camelizeClassName($objectType));
                 $data[$objectType][] = $this->transformValue($object, isset($this->configuration[$objectType]) ? $this->configuration[$objectType] : array(), FALSE, FALSE);
             }
         }
     }
     foreach ($data as $objectType => $sideLoadedCollection) {
         foreach ($sideLoadedCollection as $objectIndex => $sideLoadedObject) {
             if (isset($sideLoadedObject['links'])) {
                 foreach ($sideLoadedObject['links'] as $propertyName => $links) {
                     $data[$objectType][$objectIndex]['links'][$propertyName] = $this->getUrl($propertyName) . implode(',', $links);
                 }
             }
         }
     }
     return json_encode((object) $data);
 }
コード例 #2
0
 /**
  * @param string $identifier
  * @param LoggerInterface $logger
  * @param boolean $dryRun
  * @return \Lightwerk\SurfRunner\Domain\Model\Deployment
  * @throws \Lightwerk\SurfRunner\Exception\NoAvailableDeploymentException
  * @throws \Lightwerk\SurfRunner\Factory\Exception
  * @throws \TYPO3\Surf\Exception
  */
 public function deployByIdentifier($identifier, LoggerInterface $logger, $dryRun)
 {
     /** @var SurfCaptainDeployment $surfCaptainDeployment */
     $surfCaptainDeployment = $this->persistenceManager->getObjectByIdentifier($identifier, 'Lightwerk\\SurfCaptain\\Domain\\Model\\Deployment');
     if ($surfCaptainDeployment instanceof SurfCaptainDeployment === FALSE) {
         throw new NoAvailableDeploymentException('deployment with identifier ' . $identifier . ' not found', 1428685495);
     }
     if (!$dryRun) {
         $this->setStatusBeforeDeployment($surfCaptainDeployment);
     }
     $logger->addBackend(new DatabaseBackend(array('deployment' => $surfCaptainDeployment, 'severityThreshold' => LOG_DEBUG)));
     try {
         $deployment = $this->deploymentFactory->getDeploymentByDeploymentRecord($surfCaptainDeployment, $logger);
     } catch (\Lightwerk\SurfRunner\Factory\Exception $e) {
         $this->setStatusAfterDeployment($surfCaptainDeployment, Deployment::STATUS_FAILED);
         throw new NoAvailableDeploymentException('cannot create deployment with DeploymentFactoryException ' . $e->getMessage() . ' - ' . $e->getCode(), 1428769117);
     }
     $deployment->initialize();
     if (!$dryRun) {
         $this->emitDeploymentStarted($deployment, $surfCaptainDeployment);
         try {
             $deployment->deploy();
         } catch (\TYPO3\Surf\Exception\InvalidConfigurationException $e) {
             $this->setStatusAfterDeployment($surfCaptainDeployment, Deployment::STATUS_FAILED);
             throw new NoAvailableDeploymentException('cannot deploy with InvalidConfigurationException' . $e->getMessage() . ' - ' . $e->getCode(), 1428769119);
         }
         $this->setStatusAfterDeployment($surfCaptainDeployment, $deployment->getStatus());
         $this->emitDeploymentFinished($deployment, $surfCaptainDeployment);
     } else {
         $deployment->simulate();
     }
     return $deployment;
 }
コード例 #3
0
 /**
  * Loads the objects this LazySplObjectStorage is supposed to hold.
  *
  * @return void
  */
 protected function initialize()
 {
     if (is_array($this->objectIdentifiers)) {
         foreach ($this->objectIdentifiers as $identifier) {
             try {
                 parent::attach($this->persistenceManager->getObjectByIdentifier($identifier));
             } catch (\TYPO3\Flow\Persistence\Generic\Exception\InvalidObjectDataException $exception) {
                 // when security query rewriting holds back an object here, we skip it...
             }
         }
         $this->objectIdentifiers = null;
     }
 }
コード例 #4
0
 /**
  * Returns the real object this proxy stands for
  *
  * @return object The "content object" as it was originally passed to the constructor
  */
 public function getObject()
 {
     if ($this->contentObject === null) {
         $this->contentObject = $this->persistenceManager->getObjectByIdentifier($this->targetId, $this->targetType);
     }
     return $this->contentObject;
 }
コード例 #5
0
 /**
  * Generates a unique string for the given identifier according to $this->uriPattern.
  * If no UriPattern is set, the path segment is equal to the (URL-encoded) $identifier - otherwise a matching
  * ObjectPathMapping is fetched from persistence.
  * If no ObjectPathMapping exists for the given identifier, a new ObjectPathMapping is created.
  *
  * @param string $identifier the technical identifier of the object
  * @return string|integer the resolved path segment(s)
  * @throws InfiniteLoopException if no unique path segment could be found after 100 iterations
  */
 protected function getPathSegmentByIdentifier($identifier)
 {
     if ($this->getUriPattern() === '') {
         return rawurlencode($identifier);
     }
     $objectPathMapping = $this->objectPathMappingRepository->findOneByObjectTypeUriPatternAndIdentifier($this->objectType, $this->getUriPattern(), $identifier);
     if ($objectPathMapping !== null) {
         return $this->lowerCase ? strtolower($objectPathMapping->getPathSegment()) : $objectPathMapping->getPathSegment();
     }
     $object = $this->persistenceManager->getObjectByIdentifier($identifier, $this->objectType);
     $pathSegment = $uniquePathSegment = $this->createPathSegmentForObject($object);
     $pathSegmentLoopCount = 0;
     do {
         if ($pathSegmentLoopCount++ > 99) {
             throw new InfiniteLoopException('No unique path segment could be found after ' . ($pathSegmentLoopCount - 1) . ' iterations.', 1316441798);
         }
         if ($uniquePathSegment !== '') {
             $objectPathMapping = $this->objectPathMappingRepository->findOneByObjectTypeUriPatternAndPathSegment($this->objectType, $this->getUriPattern(), $uniquePathSegment, !$this->lowerCase);
             if ($objectPathMapping === null) {
                 $this->storeObjectPathMapping($uniquePathSegment, $identifier);
                 break;
             }
         }
         $uniquePathSegment = sprintf('%s-%d', $pathSegment, $pathSegmentLoopCount);
     } while (true);
     return $this->lowerCase ? strtolower($uniquePathSegment) : $uniquePathSegment;
 }
コード例 #6
0
 /**
  * Unserialize an array
  *
  * @param string $string
  *
  * @return array|FALSE if error appends
  */
 protected function unserializeArray($string)
 {
     $array = unserialize($string);
     if (is_array($array)) {
         foreach ($array as &$val) {
             if (is_string($val)) {
                 switch (substr($val, 0, 6)) {
                     case 'ARR->|':
                         $val = $this->unserializeArray(substr($val, 6));
                         if ($val === false) {
                             return false;
                         }
                         break;
                     case 'DAT->|':
                         $val = unserialize(substr($val, 6));
                         break;
                     case 'OBJ->|':
                         list($className, $reference) = explode('|', substr($val, 6));
                         if (strlen($className) > 0 && strlen($reference) > 0) {
                             $val = $this->persistenceManager->getObjectByIdentifier($reference, $className);
                             if ($val === false) {
                                 return false;
                             }
                         }
                         break;
                 }
             }
         }
         return $array;
     }
     return false;
 }
コード例 #7
0
 /**
  * Helper function which creates or fetches a resource pointer object for a given hash.
  *
  * If a ResourcePointer with the given hash exists, this one is used. Else, a new one
  * is created. This is a workaround for missing ValueObject support in Doctrine.
  *
  * @param string $hash
  * @return \TYPO3\Flow\Resource\ResourcePointer
  */
 public function getResourcePointerForHash($hash)
 {
     $resourcePointer = $this->persistenceManager->getObjectByIdentifier($hash, 'TYPO3\\Flow\\Resource\\ResourcePointer');
     if (!$resourcePointer) {
         $resourcePointer = new \TYPO3\Flow\Resource\ResourcePointer($hash);
         $this->persistenceManager->add($resourcePointer);
     }
     return $resourcePointer;
 }
コード例 #8
0
    /**
     * Import resources to asset management
     *
     * This command detects Flow "Resource" objects which are not yet available as "Asset" objects and thus don't appear
     * in the asset management. The type of the imported asset is determined by the file extension provided by the
     * Resource object.
     *
     * @param boolean $simulate If set, this command will only tell what it would do instead of doing it right away
     * @return void
     */
    public function importResourcesCommand($simulate = false)
    {
        $this->initializeConnection();
        $sql = '
			SELECT
				r.persistence_object_identifier, r.filename, r.mediatype
			FROM typo3_flow_resource_resource r
			LEFT JOIN typo3_media_domain_model_asset a
			ON a.resource = r.persistence_object_identifier
			LEFT JOIN typo3_media_domain_model_thumbnail t
			ON t.resource = r.persistence_object_identifier
			WHERE a.persistence_object_identifier IS NULL AND t.persistence_object_identifier IS NULL
		';
        $statement = $this->dbalConnection->prepare($sql);
        $statement->execute();
        $resourceInfos = $statement->fetchAll();
        if ($resourceInfos === array()) {
            $this->outputLine('Found no resources which need to be imported.');
            $this->quit();
        }
        foreach ($resourceInfos as $resourceInfo) {
            $mediaType = $resourceInfo['mediatype'];
            if (substr($mediaType, 0, 6) === 'image/') {
                $resource = $this->persistenceManager->getObjectByIdentifier($resourceInfo['persistence_object_identifier'], 'TYPO3\\Flow\\Resource\\Resource');
                if ($resource === null) {
                    $this->outputLine('Warning: Resource for file "%s" seems to be corrupt. No resource object with identifier %s could be retrieved from the Persistence Manager.', array($resourceInfo['filename'], $resourceInfo['persistence_object_identifier']));
                    continue;
                }
                if (!$resource->getStream()) {
                    $this->outputLine('Warning: Resource for file "%s" seems to be corrupt. The actual data of resource %s could not be found in the resource storage.', array($resourceInfo['filename'], $resourceInfo['persistence_object_identifier']));
                    continue;
                }
                $image = new Image($resource);
                if ($simulate) {
                    $this->outputLine('Simulate: Adding new image "%s" (%sx%s px)', array($image->getResource()->getFilename(), $image->getWidth(), $image->getHeight()));
                } else {
                    $this->assetRepository->add($image);
                    $this->outputLine('Adding new image "%s" (%sx%s px)', array($image->getResource()->getFilename(), $image->getWidth(), $image->getHeight()));
                }
            }
        }
    }
 /**
  * Fetch an object from persistence layer.
  *
  * @param mixed $identity
  * @param string $targetType
  * @return object
  * @throws TargetNotFoundException
  * @throws InvalidSourceException
  */
 protected function fetchObjectFromPersistence($identity, $targetType)
 {
     if ($targetType === Thumbnail::class) {
         $object = $this->persistenceManager->getObjectByIdentifier($identity, $targetType);
     } elseif (is_string($identity)) {
         $object = $this->assetRepository->findByIdentifier($identity);
     } else {
         throw new InvalidSourceException('The identity property "' . $identity . '" is not a string.', 1415817618);
     }
     return $object;
 }
コード例 #10
0
 /**
  * Fetch an object from persistence layer.
  *
  * @param mixed $identity
  * @param string $targetType
  * @return object
  * @throws \TYPO3\Flow\Property\Exception\TargetNotFoundException
  * @throws \TYPO3\Flow\Property\Exception\InvalidSourceException
  */
 protected function fetchObjectFromPersistence($identity, $targetType)
 {
     if (is_string($identity)) {
         $object = $this->persistenceManager->getObjectByIdentifier($identity, $targetType);
     } elseif (is_array($identity)) {
         $object = $this->findObjectByIdentityProperties($identity, $targetType);
     } else {
         throw new \TYPO3\Flow\Property\Exception\InvalidSourceException('The identity property "' . $identity . '" is neither a string nor an array.', 1297931020);
     }
     return $object;
 }
コード例 #11
0
 /**
  * Fetch an object from persistence layer.
  *
  * @param mixed $identity
  * @param string $targetType
  * @return object
  * @throws TargetNotFoundException
  * @throws InvalidSourceException
  */
 protected function fetchObjectFromPersistence($identity, $targetType)
 {
     if (is_string($identity)) {
         $object = $this->persistenceManager->getObjectByIdentifier($identity, $targetType);
     } elseif (is_array($identity)) {
         $object = $this->findObjectByIdentityProperties($identity, $targetType);
     } else {
         throw new InvalidSourceException(sprintf('The identity property is neither a string nor an array but of type "%s".', gettype($identity)), 1297931020);
     }
     return $object;
 }
コード例 #12
0
 /**
  * Fetch an object from persistence layer.
  *
  * @param mixed $identity
  * @param string $targetType
  * @return object
  * @throws \TYPO3\Flow\Property\Exception\TargetNotFoundException
  * @throws \TYPO3\Flow\Property\Exception\InvalidSourceException
  */
 protected function fetchObjectFromPersistence($identity, $targetType)
 {
     if ($targetType === 'TYPO3\\Media\\Domain\\Model\\Thumbnail') {
         $object = $this->persistenceManager->getObjectByIdentifier($identity, $targetType);
     } elseif (is_string($identity)) {
         $object = $this->assetRepository->findByIdentifier($identity);
     } else {
         throw new \TYPO3\Flow\Property\Exception\InvalidSourceException('The identity property "' . $identity . '" is not a string.', 1415817618);
     }
     return $object;
 }
コード例 #13
0
 /**
  * Traverses the $array and replaces known persisted objects (tuples of
  * type and identifier) with actual instances.
  *
  * @param array $array
  * @return void
  */
 protected function decodeObjectReferences(array &$array)
 {
     foreach ($array as &$value) {
         if (!is_array($value)) {
             continue;
         }
         if (isset($value['__flow_object_type'])) {
             $value = $this->persistenceManager->getObjectByIdentifier($value['__identifier'], $value['__flow_object_type']);
         }
     }
 }
コード例 #14
0
 /**
  * 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)
 {
     $object = $this->persistenceManager->getObjectByIdentifier($identifier, $this->entityClassName);
     if ($object === null) {
         foreach ($this->addedResources as $addedResource) {
             if ($this->persistenceManager->getIdentifierByObject($addedResource) === $identifier) {
                 $object = $addedResource;
                 break;
             }
         }
     }
     return $object;
 }
コード例 #15
0
 /**
  * Converts the given string or array to a ResourcePointer object.
  *
  * If the input format is an array, this method assumes the resource to be a
  * fresh file upload and imports the temporary upload file through the
  * resource manager.
  *
  * @param array $source The upload info (expected keys: error, name, tmp_name)
  * @param string $targetType
  * @param array $convertedChildProperties
  * @param \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration
  * @return \TYPO3\Flow\Resource\Resource|TYPO3\Flow\Error\Error if the input format is not supported or could not be converted for other reasons
  */
 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration = NULL)
 {
     if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) {
         if (isset($source['submittedFile']) && isset($source['submittedFile']['filename']) && isset($source['submittedFile']['resourcePointer'])) {
             $resourcePointer = $this->persistenceManager->getObjectByIdentifier($source['submittedFile']['resourcePointer'], 'TYPO3\\Flow\\Resource\\ResourcePointer');
             if ($resourcePointer) {
                 $resource = new Resource();
                 $resource->setFilename($source['submittedFile']['filename']);
                 $resource->setResourcePointer($resourcePointer);
                 return $resource;
             }
         }
         return NULL;
     }
     if ($source['error'] !== \UPLOAD_ERR_OK) {
         switch ($source['error']) {
             case \UPLOAD_ERR_INI_SIZE:
             case \UPLOAD_ERR_FORM_SIZE:
             case \UPLOAD_ERR_PARTIAL:
                 return new \TYPO3\Flow\Error\Error(\TYPO3\Flow\Utility\Files::getUploadErrorMessage($source['error']), 1264440823);
             default:
                 $this->systemLogger->log(sprintf('A server error occurred while converting an uploaded resource: "%s"', \TYPO3\Flow\Utility\Files::getUploadErrorMessage($source['error'])), LOG_ERR);
                 return new \TYPO3\Flow\Error\Error('An error occurred while uploading. Please try again or contact the administrator if the problem remains', 1340193849);
         }
     }
     if (isset($this->convertedResources[$source['tmp_name']])) {
         return $this->convertedResources[$source['tmp_name']];
     }
     $resource = $this->resourceManager->importUploadedResource($source);
     if ($resource === FALSE) {
         return new \TYPO3\Flow\Error\Error('The resource manager could not create a Resource instance.', 1264517906);
     } else {
         $this->convertedResources[$source['tmp_name']] = $resource;
         return $resource;
     }
 }
コード例 #16
0
 /**
  * @param array $source
  * @param PropertyMappingConfigurationInterface $configuration
  * @return Resource|Error
  */
 protected function handleHashAndData(array $source, PropertyMappingConfigurationInterface $configuration = NULL)
 {
     $hash = NULL;
     $resource = FALSE;
     $givenResourceIdentity = NULL;
     if (isset($source['__identity'])) {
         $givenResourceIdentity = $source['__identity'];
         unset($source['__identity']);
         $resource = $this->persistenceManager->getObjectByIdentifier($givenResourceIdentity, 'TYPO3\\Flow\\Resource\\Resource');
         if ($resource instanceof \TYPO3\Flow\Resource\Resource) {
             return $resource;
         }
         if ($configuration->getConfigurationValue('TYPO3\\Flow\\Resource\\ResourceTypeConverter', self::CONFIGURATION_IDENTITY_CREATION_ALLOWED) !== TRUE) {
             throw new \TYPO3\Flow\Property\Exception\InvalidPropertyMappingConfigurationException('Creation of resource objects with identity not allowed. To enable this, you need to set the PropertyMappingConfiguration Value "CONFIGURATION_IDENTITY_CREATION_ALLOWED" to TRUE');
         }
     }
     if (isset($source['hash']) && preg_match('/[0-9a-f]{40}/', $source['hash'])) {
         $hash = $source['hash'];
     }
     if ($hash !== NULL) {
         $resourcePointer = $this->persistenceManager->getObjectByIdentifier($hash, 'TYPO3\\Flow\\Resource\\ResourcePointer');
         if ($resourcePointer) {
             $resource = new Resource();
             $resource->setFilename($source['filename']);
             $resource->setResourcePointer($resourcePointer);
         }
     }
     if ($resource === NULL) {
         if (isset($source['data'])) {
             $resource = $this->resourceManager->createResourceFromContent($source['data'], $source['filename']);
         } elseif ($hash !== NULL) {
             $resource = $this->resourceManager->importResource($configuration->getConfigurationValue('TYPO3\\Flow\\Resource\\ResourceTypeConverter', self::CONFIGURATION_RESOURCE_LOAD_PATH) . '/' . $hash);
             if (is_array($source) && isset($source['filename'])) {
                 $resource->setFilename($source['filename']);
             }
         }
     }
     if ($resource instanceof \TYPO3\Flow\Resource\Resource) {
         if ($givenResourceIdentity !== NULL) {
             $this->setIdentity($resource, $givenResourceIdentity);
         }
         return $resource;
     } else {
         return new Error('The resource manager could not create a Resource instance.', 1404312901);
     }
 }
コード例 #17
0
 /**
  * Update progression on playback, updated by trackerId.
  *
  */
 public function updateTrackerAction()
 {
     $trackerId = $this->request->getArgument('trackerId');
     $tracker = $this->persistenceManager->getObjectByIdentifier($trackerId, '\\_OurBrand_\\Quiz\\Domain\\Model\\TrackStudentAudioPlayback');
     if (is_a($tracker, '\\_OurBrand_\\Quiz\\Domain\\Model\\TrackStudentAudioPlayback')) {
         $elapsedTime = $this->request->getArgument('elapsedTime');
         $status = $this->request->getArgument('status');
         $tmpTime = $tracker->getTimeElapsed();
         // only update if new time is larger then the old one...
         if (intval($elapsedTime) > $tmpTime) {
             $tracker->setTimeElapsed($elapsedTime);
         }
         $tracker->setStatus($status);
         $this->trackStudentAudioPlaybackRepository->update($tracker);
         $this->persistenceManager->persistAll();
         return json_encode(array('elapsedTime' => $tracker->getTimeElapsed(), 'status' => $tracker->getStatus(), 'trackerId' => $this->persistenceManager->getIdentifierByObject($tracker)));
     }
 }
コード例 #18
0
 /**
  * Converts the given $objectXml to an AssetInterface instance and returns it
  *
  * @param \SimpleXMLElement $objectXml
  * @param string $className the concrete class name of the AssetInterface to create
  * @return AssetInterface
  * @throws NeosException
  */
 protected function importAsset(\SimpleXMLElement $objectXml, $className)
 {
     if (isset($objectXml['__identifier'])) {
         $asset = $this->assetRepository->findByIdentifier((string) $objectXml['__identifier']);
         if (is_object($asset)) {
             return $asset;
         }
     }
     $resourceHash = (string) $objectXml->resource->hash;
     $resourceData = trim((string) $objectXml->resource->content);
     if ((string) $objectXml->resource['__identifier'] !== '') {
         $resource = $this->persistenceManager->getObjectByIdentifier((string) $objectXml->resource['__identifier'], 'TYPO3\\Flow\\Resource\\Resource');
     }
     if (!isset($resource) || $resource === null) {
         $resource = $this->importResource((string) $objectXml->resource->filename, $resourceHash !== '' ? $resourceHash : null, !empty($resourceData) ? $resourceData : null, (string) $objectXml->resource['__identifier'] !== '' ? (string) $objectXml->resource['__identifier'] : null);
     }
     $asset = $this->objectManager->get($className);
     $asset->setResource($resource);
     $this->assetRepository->add($asset);
     return $asset;
 }
コード例 #19
0
 /**
  * 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)
 {
     return $this->persistenceManager->getObjectByIdentifier($identifier, $this->entityClassName);
 }
コード例 #20
0
 /**
  * Returns the workspace owner.
  *
  * @return UserInterface
  * @api
  */
 public function getOwner()
 {
     if ($this->owner === null) {
         return null;
     }
     return $this->persistenceManager->getObjectByIdentifier($this->owner, $this->reflectionService->getDefaultImplementationClassNameForInterface(UserInterface::class));
 }
コード例 #21
0
 /**
  * Shows the status of the current mapping
  *
  * @param string $object Class name of a domain object. If given, will only work on this single object
  * @param boolean $conductUpdate Set to TRUE to conduct the required corrections
  * @param string $clientName The client name to use
  */
 public function statusCommand($object = null, $conductUpdate = false, $clientName = null)
 {
     $result = new ErrorResult();
     $client = $this->clientFactory->create($clientName);
     $classesAndAnnotations = $this->indexInformer->getClassesAndAnnotations();
     if ($object !== null) {
         if (!isset($classesAndAnnotations[$object])) {
             $this->outputFormatted("Error: Object '<b>%s</b>' is not configured correctly, check the Indexable annotation.", array($object));
             $this->quit(1);
         }
         $classesAndAnnotations = array($object => $classesAndAnnotations[$object]);
     }
     array_walk($classesAndAnnotations, function (Indexable $annotation, $className) use($result, $client, $conductUpdate) {
         $this->outputFormatted("Object %s", array($className), 4);
         $this->outputFormatted("Index <b>%s</b> Type <b>%s</b>", array($annotation->indexName, $annotation->typeName), 8);
         $count = $client->findIndex($annotation->indexName)->findType($annotation->typeName)->count();
         if ($count === null) {
             $result->forProperty($className)->addError(new Error('ElasticSearch was unable to retrieve a count for the type "%s" at index "%s". Probably these don\' exist.', 1340289921, array($annotation->typeName, $annotation->indexName)));
         }
         $this->outputFormatted("Documents in Search: <b>%s</b>", array($count !== null ? $count : "Error"), 8);
         try {
             $count = $this->persistenceManager->createQueryForType($className)->count();
         } catch (\Exception $exception) {
             $count = null;
             $result->forProperty($className)->addError(new Error('The persistence backend was unable to retrieve a count for the type "%s". The exception message was "%s".', 1340290088, array($className, $exception->getMessage())));
         }
         $this->outputFormatted("Documents in Persistence: <b>%s</b>", array($count !== null ? $count : "Error"), 8);
         if (!$result->forProperty($className)->hasErrors()) {
             $states = $this->getModificationsNeededStatesAndIdentifiers($client, $className);
             if ($conductUpdate) {
                 $inserted = 0;
                 $updated = 0;
                 foreach ($states[ObjectIndexer::ACTION_TYPE_CREATE] as $identifier) {
                     try {
                         $this->objectIndexer->indexObject($this->persistenceManager->getObjectByIdentifier($identifier, $className));
                         $inserted++;
                     } catch (\Exception $exception) {
                         $result->forProperty($className)->addError(new Error('An error occurred while trying to add an object to the ElasticSearch backend. The exception message was "%s".', 1340356330, array($exception->getMessage())));
                     }
                 }
                 foreach ($states[ObjectIndexer::ACTION_TYPE_UPDATE] as $identifier) {
                     try {
                         $this->objectIndexer->indexObject($this->persistenceManager->getObjectByIdentifier($identifier, $className));
                         $updated++;
                     } catch (\Exception $exception) {
                         $result->forProperty($className)->addError(new Error('An error occurred while trying to update an object to the ElasticSearch backend. The exception message was "%s".', 1340358590, array($exception->getMessage())));
                     }
                 }
                 $this->outputFormatted("Objects inserted: <b>%s</b>", array($inserted), 8);
                 $this->outputFormatted("Objects updated: <b>%s</b>", array($updated), 8);
             } else {
                 $this->outputFormatted("Modifications needed: <b>create</b> %d, <b>update</b> %d", array(count($states[ObjectIndexer::ACTION_TYPE_CREATE]), count($states[ObjectIndexer::ACTION_TYPE_UPDATE])), 8);
             }
         }
     });
     if ($result->hasErrors()) {
         $this->outputLine();
         $this->outputLine('The following errors occurred:');
         /** @var $error \TYPO3\Flow\Error\Error */
         foreach ($result->getFlattenedErrors() as $className => $errors) {
             foreach ($errors as $error) {
                 $this->outputLine();
                 $this->outputFormatted("<b>Error</b> for %s:", array($className), 8);
                 $this->outputFormatted((string) $error, array(), 4);
             }
         }
     }
 }
コード例 #22
0
 /**
  * @param array $source
  * @param PropertyMappingConfigurationInterface $configuration
  * @return Resource|Error
  * @throws Exception
  */
 protected function handleFileUploads(array $source, PropertyMappingConfigurationInterface $configuration = null)
 {
     if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) {
         if (isset($source['originallySubmittedResource']) && isset($source['originallySubmittedResource']['__identity'])) {
             return $this->persistenceManager->getObjectByIdentifier($source['originallySubmittedResource']['__identity'], \TYPO3\Flow\Resource\Resource::class);
         }
         return null;
     }
     if ($source['error'] !== \UPLOAD_ERR_OK) {
         switch ($source['error']) {
             case \UPLOAD_ERR_INI_SIZE:
             case \UPLOAD_ERR_FORM_SIZE:
             case \UPLOAD_ERR_PARTIAL:
                 return new Error(Files::getUploadErrorMessage($source['error']), 1264440823);
             default:
                 $this->systemLogger->log(sprintf('A server error occurred while converting an uploaded resource: "%s"', Files::getUploadErrorMessage($source['error'])), LOG_ERR);
                 return new Error('An error occurred while uploading. Please try again or contact the administrator if the problem remains', 1340193849);
         }
     }
     if (isset($this->convertedResources[$source['tmp_name']])) {
         return $this->convertedResources[$source['tmp_name']];
     }
     $resource = $this->resourceManager->importUploadedResource($source, $this->getCollectionName($source, $configuration));
     if ($resource === false) {
         return new Error('The Resource Manager could not create a Resource instance for an uploaded file. See log for more details.', 1264517906);
     } else {
         $this->convertedResources[$source['tmp_name']] = $resource;
         return $resource;
     }
 }
コード例 #23
0
 /**
  * Reconstitutes a persistence object (entity or valueobject) identified by the given UUID.
  *
  * @param string $className The class name of the object to retrieve
  * @param string $uuid The UUID of the object
  * @return object The reconstituted persistence object, NULL if none was found
  */
 protected function reconstitutePersistenceObject($className, $uuid)
 {
     return $this->persistenceManager->getObjectByIdentifier($uuid, $className);
 }