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);
     }
 }
 /**
  * Handle missing data notification
  *
  * @param CollectionInterface $collection
  * @param ResourceMetaDataInterface $resource
  */
 protected function handleMissingData(ResourceMetaDataInterface $resource, CollectionInterface $collection)
 {
     $message = sprintf('Could not publish resource %s with SHA1 hash %s of collection %s because there seems to be no corresponding data in the storage.', $resource->getFilename(), $resource->getSha1(), $collection->getName());
     $this->messageCollector->append($message);
 }