protected function execute(InputInterface $input, OutputInterface $output)
 {
     $minutes = (int) $input->getOption('minutes');
     if ($minutes < 1) {
         throw new \InvalidArgumentException('Minutes has to be a positive number');
     }
     if ($input->getOption('all')) {
         $feeds = $this->getAllFeeds();
     } elseif ($ids = $input->getOption('feed')) {
         $feeds = $this->getFeeds($ids);
     } else {
         $feeds = $this->getScheduledFeeds($minutes);
     }
     if (empty($feeds)) {
         $output->writeln('No feeds to schedule');
         return 0;
     }
     // pipe import manager log to console
     $this->importManager->getLogger()->getLogger()->pushHandler(new ConsoleHandler($output));
     if ($output->getVerbosity() >= OutputInterface::VERBOSITY_NORMAL) {
         $this->setDownloadListeners($output, $this->importManager->getEventDispatcher());
     }
     $force = $input->getOption('force');
     return $this->scheduleImports($output, $feeds, $minutes, $force);
 }
예제 #2
0
 /**
  * Returns the last date after which all feed of the given origin have had a
  * full import.
  *
  * @param  OriginInterface $origin
  *
  * @return \DateTime
  */
 public function getLastFullImportDate(OriginInterface $origin)
 {
     $imports = $this->importManager->getImportRepository()->findCompletedByOrigin($origin);
     // find the last import dates for each feed of this origin, but only
     // non-partial imports
     $dates = [];
     foreach ($imports as $import) {
         // don't count imports with errors
         if ($this->importManager->importHasErrors($import, false)) {
             continue;
         }
         // don't count partial imports
         if ($import->isPartial()) {
             continue;
         }
         // imports without any items are excluded also
         if ($import->getTotalNumberOfItems() === 0) {
             continue;
         }
         $id = $import->getFeed()->getId();
         if (array_key_exists($id, $dates)) {
             // see which is newer
             if ($dates[$id] > $import->getDatetimeStarted()) {
                 continue;
             }
         }
         $dates[$id] = $import->getDatetimeStarted();
     }
     if (empty($dates)) {
         return null;
     }
     // check if all feeds are there
     foreach ($origin->getFeeds() as $feed) {
         if ($feed->isPartial()) {
             continue;
         }
         // if we have no date for this feed, we can't consider this origin to be fully imported
         if (!array_key_exists($feed->getId(), $dates)) {
             return null;
         }
     }
     // to return the latest date after which all feeds have imported completely,
     // we need the earliest date of all feeds
     return min($dates);
 }
예제 #3
0
 public function importHasErrors(Import $import)
 {
     return $this->importManager->importHasErrors($import);
 }
예제 #4
0
 /**
  * @param  integer    $partId
  * @return ImportPart
  */
 protected function findImportPart($partId)
 {
     return $this->importManager->findImportPartById($partId);
 }
 /**
  * @param Import $import
  */
 protected function removeFeed(Import $import)
 {
     $dir = $this->importManager->getImportDir($import);
     $this->filesystem->remove($dir);
 }