/** * @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; }
/** * @param AbstractQuery $query * * @throws \LogicException * @return int * */ public function cleanByQuery(AbstractQuery $query) { $numCleaned = 0; /** @var SourceInterface $source */ foreach ($query->iterate() as list($source)) { if (!$source instanceof SourceInterface) { throw new \LogicException(sprintf('Invalid iterator given, encountered %s instead of SourceInterface', is_object($source) ? get_class($source) : gettype($source))); } $this->eventDispatcher->dispatch(IoEvents::PRE_CLEAN_SOURCE, new SourceEvent($source)); $this->sourceManager->remove($source); $this->eventDispatcher->dispatch(IoEvents::POST_CLEAN_SOURCE, new SourceEvent($source)); ++$numCleaned; if ($numCleaned % 50 === 0) { $this->sourceManager->flush(); $this->sourceManager->clear(); } } if ($numCleaned > 0) { $this->sourceManager->flush(); $this->sourceManager->clear(); } return $numCleaned; }
/** * @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; }
/** * @param SourceInterface $source */ protected function removeSource(SourceInterface $source) { $this->sourceManager->remove($source); $this->sourceManager->flush($source); }
/** * @inheritdoc */ public function flush(SourceInterface $source = null) { $this->sourceManager->flush($source); }