/** * Schedules periodic or background import tasks. * * This is also used as a callback for job_scheduler integration. * * @param \Drupal\feeds\FeedInterface $feed * The feed to schedule. */ public function scheduleImport(FeedInterface $feed) { if (!$this->jobController) { return; } // Check whether any fetcher is overriding the import period. $period = $this->importer->getImportPeriod(); // Schedule as soon as possible if a batch is active. $period = $feed->progressImporting() === StateInterface::BATCH_COMPLETE ? $period : 0; $job = array('name' => 'feeds_feed_import', 'type' => $feed->bundle(), 'id' => $feed->id(), 'period' => $period, 'periodic' => TRUE); if ($period == SchedulerInterface::SCHEDULE_NEVER) { $this->jobController->remove($job); } else { $this->jobController->set($job); } }
/** * Handles a push import. * * @param \Drupal\feeds\FeedInterface $feed * The feed receiving the push. * @param string $payload * The feed contents. * * @todo Move this to a queue. */ public function pushImport(FeedInterface $feed, $payload) { $feed->lock(); $fetcher_result = new RawFetcherResult($payload); try { do { foreach ($this->doParse($feed, $fetcher_result) as $item) { $this->doProcess($feed, $item); } } while ($feed->progressImporting() !== StateInterface::BATCH_COMPLETE); } catch (EmptyFeedException $e) { // Not an error. } catch (\Exception $exception) { // Do nothing. Will throw later. } $feed->finishImport(); if (isset($exception)) { throw $exception; } }