/**
  * 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);
 }
 public function importHasErrors(Import $import)
 {
     return $this->importManager->importHasErrors($import);
 }