/**
  * Returns a unique hash for a feed.
  *
  * @param Feed $feed
  *
  * @return string
  */
 protected function getFeedHash(Feed $feed)
 {
     return md5('feed' . $feed->getId());
 }
Пример #2
0
 /**
  * @return string
  */
 public function __toString()
 {
     return sprintf('%s:%s', $this->feed->getOrigin()->getName(), $this->originalId);
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 public function getOrigin()
 {
     return $this->feed->getOrigin();
 }
Пример #4
0
 /**
  * @param FeedEntity               $feed
  * @param ReaderInterface          $reader
  * @param EventDispatcherInterface $dispatcher
  * @param array                    $options
  *
  * @return Feed
  */
 protected function createFeed(FeedEntity $feed, ReaderInterface $reader, EventDispatcherInterface $dispatcher, array $options = [])
 {
     $builder = new FeedBuilder($dispatcher);
     $type = $this->importRegistry->getFeedType($feed->getType());
     $options = array_merge($options, $feed->getOptions());
     return $builder->build($type, $reader, $options);
 }
Пример #5
0
 /**
  * @inheritdoc
  */
 public function findSourceByFeed(Feed $feed, $originalId)
 {
     // look for mapping
     $params = ['feed' => $feed->getId(), 'originalId' => $originalId];
     return $this->getRepository()->findOneBy($params);
 }
Пример #6
0
 /**
  * Returns the last date after which the given feed has had a full import.
  *
  * @param Feed $feed
  *
  * @return \DateTime
  */
 public function getLastFullImportDate(Feed $feed)
 {
     // we can only have a full import when the feed is not partial
     if ($feed->isPartial()) {
         return null;
     }
     $imports = $this->getImportRepository()->findCompletedByFeed($feed);
     // find the import dates for this feed, but only non-partial imports
     $dates = [];
     foreach ($imports as $import) {
         // don't count imports with errors
         if ($import->hasErrors()) {
             continue;
         }
         // don't count partial imports
         if ($import->isPartial()) {
             continue;
         }
         // imports without any items are excluded also
         if ($import->getTotalNumberOfItems() === 0) {
             continue;
         }
         $dates[] = $import->getDatetimeStarted();
     }
     // if we have no date for this feed, we can't consider it to be fully imported
     if (empty($dates)) {
         return null;
     }
     // return the latest of the dates
     return max($dates);
 }
Пример #7
0
 /**
  * Checks feed for unfinished imports and gives the user an option to close them first.
  *
  * @param Feed            $feed
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @throws \Exception
  */
 protected function checkForUnfinishedImports(Feed $feed, InputInterface $input, OutputInterface $output)
 {
     $helper = new QuestionHelper();
     foreach ($feed->getImports() as $import) {
         if (!$import->isFinished()) {
             $msg = sprintf('Import <info>%d</info> for this feed is unfinished, close it now? [y] ', $import->getId());
             $question = new ConfirmationQuestion($msg);
             if ($helper->ask($input, $output, $question)) {
                 $command = 'io:import:close';
                 $closeImport = $this->getApplication()->find($command);
                 $input = new ArrayInput(['command' => $command, 'import' => $import->getId()]);
                 $closeImport->run($input, $output);
             }
         }
     }
 }
 /**
  * @param Feed $feed
  *
  * @return array
  */
 protected function getReaderTypeOptions(Feed $feed)
 {
     return array_merge(['partial' => $feed->isPartial(), 'forced' => true], $feed->getReaderOptions());
 }