Neos\Flow\ResourceManagement\Publishing\MessageCollector::flush PHP Method

flush() public method

public flush ( callable $callback = null ) : void
$callback callable a callback function to process every notification
return void
    public function flush(callable $callback = null)
    {
        foreach ($this->messages as $message) {
            /** @var Message $message */
            $this->messages->detach($message);
            $this->systemLogger->log('ResourcePublishingMessage: ' . $message->getMessage(), $message->getSeverity());
            if ($callback !== null) {
                $callback($message);
            }
        }
    }

Usage Example

Example #1
0
 /**
  * Publish resources
  *
  * This command publishes the resources of the given or - if none was specified, all - resource collections
  * to their respective configured publishing targets.
  *
  * @param string $collection If specified, only resources of this collection are published. Example: 'persistent'
  * @return void
  */
 public function publishCommand($collection = null)
 {
     try {
         if ($collection === null) {
             $collections = $this->resourceManager->getCollections();
         } else {
             $collections = [];
             $collections[$collection] = $this->resourceManager->getCollection($collection);
             if ($collections[$collection] === null) {
                 $this->outputLine('Collection "%s" does not exist.', [$collection]);
                 $this->quit(1);
             }
         }
         foreach ($collections as $collection) {
             /** @var CollectionInterface $collection */
             $this->outputLine('Publishing resources of collection "%s"', [$collection->getName()]);
             $target = $collection->getTarget();
             $target->publishCollection($collection, function ($iteration) {
                 $this->clearState($iteration);
             });
         }
         if ($this->messageCollector->hasMessages()) {
             $this->outputLine();
             $this->outputLine('The resources were published, but a few inconsistencies were detected. You can check and probably fix the integrity of the resource registry by using the resource:clean command.');
             $this->messageCollector->flush(function (Message $notification) {
                 $this->outputLine($notification->getSeverity() . ': ' . $notification->getMessage());
             });
         }
     } catch (Exception $exception) {
         $this->outputLine();
         $this->outputLine('An error occurred while publishing resources (see full description below). You can check and probably fix the integrity of the resource registry by using the resource:clean command.');
         $this->outputLine('%s (Exception code: %s)', [get_class($exception), $exception->getCode()]);
         $this->outputLine($exception->getMessage());
         $this->quit(1);
     }
 }