Exemple #1
0
 /**
  * {@inheritodc}
  */
 public function clear(FeedInterface $feed, array &$context)
 {
     try {
         $this->dispatchEvent(FeedsEvents::INIT_CLEAR, new InitEvent($feed));
         $this->dispatchEvent(FeedsEvents::CLEAR, new ClearEvent($feed));
     } catch (\Exception $exception) {
         // Do nothing yet.
     }
     // Clean up.
     $context['finished'] = $feed->progressClearing();
     if (isset($exception)) {
         $context['finished'] = StateInterface::BATCH_COMPLETE;
     }
     if ($context['finished'] === StateInterface::BATCH_COMPLETE) {
         $feed->finishClear();
         $feed->save();
         $feed->unlock();
     } else {
         $feed->saveStates();
     }
     if (isset($exception)) {
         throw $exception;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function clear(FeedInterface $feed)
 {
     $state = $feed->getState(StateInterface::CLEAR);
     // Build base select statement.
     $query = $this->queryFactory->get($this->entityType())->condition('feeds_item.target_id', $feed->id());
     // If there is no total, query it.
     if (!$state->total) {
         $count_query = clone $query;
         $state->total = $count_query->count()->execute();
     }
     // Delete a batch of entities.
     $entity_ids = $query->range(0, $this->importer->getLimit())->execute();
     if ($entity_ids) {
         $this->entityDeleteMultiple($entity_ids);
         $state->deleted += count($entity_ids);
         $state->progress($state->total, $state->deleted);
     } else {
         $state->progress($state->total, $state->total);
     }
     // Report results when done.
     if ($feed->progressClearing() == StateInterface::BATCH_COMPLETE) {
         if ($state->deleted) {
             $message = format_plural($state->deleted, 'Deleted @number @entity from %title.', 'Deleted @number @entities from %title.', array('@number' => $state->deleted, '@entity' => Unicode::strtolower($this->entityLabel()), '@entities' => Unicode::strtolower($this->entityLabelPlural()), '%title' => $feed->label()));
             $feed->log('clear', $message, array(), WATCHDOG_INFO);
             drupal_set_message($message);
         } else {
             drupal_set_message($this->t('There are no @entities to delete.', array('@entities' => Unicode::strtolower($this->entityLabelPlural()))));
         }
     }
 }