Beispiel #1
0
 /**
  * {@inheritodc}
  */
 public function startBatchClear(FeedInterface $feed)
 {
     $feed->lock();
     $feed->clearStates();
     $batch = ['title' => $this->t('Deleting items from: %title', ['%title' => $feed->label()]), 'init_message' => $this->t('Deleting items from: %title', ['%title' => $feed->label()]), 'operations' => [[[$this, 'clear'], [$feed]]], 'progress_message' => $this->t('Deleting items from: %title', ['%title' => $feed->label()]), 'error_message' => $this->t('An error occored while clearing %title.', ['%title' => $feed->label()])];
     batch_set($batch);
 }
Beispiel #2
0
 /**
  * {@inheritodc}
  */
 public function startBatchExpire(FeedInterface $feed)
 {
     try {
         $feed->lock();
     } catch (LockException $e) {
         drupal_set_message(t('The feed became locked before the expiring could begin.'), 'warning');
         return;
     }
     $feed->clearStates();
     $ids = $feed->getType()->getProcessor()->getExpiredIds($feed);
     if (!$ids) {
         $feed->unlock();
         return;
     }
     $batch = ['title' => $this->t('Expiring: %title', ['%title' => $feed->label()]), 'init_message' => $this->t('Expiring: %title', ['%title' => $feed->label()]), 'progress_message' => $this->t('Expiring: %title', ['%title' => $feed->label()]), 'error_message' => $this->t('An error occored while expiring %title.', ['%title' => $feed->label()])];
     foreach ($ids as $id) {
         $batch['operations'][] = [[$this, 'expireItem'], [$feed, $id]];
     }
     $batch['operations'][] = [[$this, 'postExpire'], [$feed]];
     batch_set($batch);
 }
Beispiel #3
0
 /**
  * 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;
     }
 }