/** * @param array $payload Payload containing the source id * * @return boolean */ public function execute(array $payload) { list($sourceId) = $payload; if (null === ($source = $this->findSource($sourceId))) { $this->getLogger()->info(sprintf('Could not find source with id %d', $sourceId)); return false; } if ($source->isBlocked()) { $this->getLogger()->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', $sourceId, $e->getMessage())); } catch (SourceProcessException $e) { $this->setMessage($source, 'process', sprintf('Error while processing source (%d): %s', $sourceId, $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 AbstractQuery $query * * @return integer * * @throws \LogicException */ 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; }
/** * @inheritdoc */ public function flush(SourceInterface $source = null) { $this->sourceManager->flush($source); }