コード例 #1
0
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $id = $input->getArgument('id');
     if (null === ($source = $this->sourceManager->findById($id))) {
         $output->writeln(sprintf('<error>Could not find source with id %d</error>', $id));
         return 1;
     }
     $linked = $this->sourceProcessor->isLinked($source);
     if (!$linked) {
         $output->writeln('Linking source first');
         $this->sourceProcessor->link($source);
     }
     $this->sourceProcessor->process($source);
     $this->sourceManager->flush($source);
     $output->writeln(sprintf('Source <info>%d</info> has been processed', $id));
     return 0;
 }
コード例 #2
0
 /**
  * @param array $payload Payload containing the source id
  *
  * @return bool
  */
 public function execute(array $payload)
 {
     /** @var SourceInterface $source */
     list($source) = $payload;
     if ($source->isBlocked()) {
         $this->logger->debug('Source is blocked');
         $this->processor->unlink($source);
         return false;
     }
     // reset messages
     $source->setMessages([]);
     try {
         // link the source first before processing it
         $linked = $this->processor->isLinked($source);
         if (!$linked) {
             $this->logger->debug('Linking source first');
             $this->processor->link($source);
         }
         $this->processor->process($source);
         // if the source was unlinked, flush it now
         if (!$linked) {
             $this->sourceManager->flush($source);
         }
         return true;
     } catch (SourceLinkException $e) {
         $this->setMessage($source, 'link', sprintf('Could not link source (%d): %s', $source->getId(), $e->getMessage()));
     } catch (SourceProcessException $e) {
         $this->setMessage($source, 'process', sprintf('Error while processing source (%d): %s', $source->getId(), $e->getMessage()));
     }
     foreach ($source->getMessages() as $key => $messages) {
         foreach ($messages as $level => $message) {
             $this->logger->log($level, sprintf('[%s] %s', $key, $message));
         }
     }
     return false;
 }