/**
  * set validation results
  * 
  * @param \TYPO3\Flow\Error\Result $results
  */
 public function setValidationResults(\TYPO3\Flow\Error\Result $results)
 {
     foreach ($results->getFlattenedErrors() as $property => $errors) {
         $this->errors[$property] = array();
         foreach ($errors as $error) {
             $this->errors[$property][] = array('code' => $error->getCode(), 'message' => $error->getMessage());
         }
     }
 }
Esempio n. 2
0
File: View.php Progetto: neos/extjs
 /**
  * Assigns errors to the view and converts them to a format that Ext JS
  * understands.
  *
  * @param \TYPO3\Flow\Error\Result $result Errors e.g. from mapping results
  */
 public function assignErrors(\TYPO3\Flow\Error\Result $result)
 {
     $errors = $result->getFlattenedErrors();
     $output = array();
     foreach ($errors as $propertyPath => $propertyErrors) {
         $message = '';
         foreach ($propertyErrors as $propertyError) {
             $message .= $propertyError->getMessage();
         }
         $output[$propertyPath] = $message;
     }
     $this->assign('value', array('errors' => $output, 'success' => FALSE));
 }
 /**
  * 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);
             }
         }
     }
 }