示例#1
0
 /**
  * {@inheritdoc}
  */
 public function parse(FeedInterface $feed, FetcherResultInterface $fetcher_result)
 {
     $feed_config = $feed->getConfigurationFor($this);
     $state = $feed->getState(StateInterface::PARSE);
     // Load and configure parser.
     $parser = new ParserCSV();
     $delimiter = $feed_config['delimiter'] == 'TAB' ? "\t" : $feed_config['delimiter'];
     $parser->setDelimiter($delimiter);
     $iterator = new ParserCSVIterator($fetcher_result->getFilePath());
     if (empty($feed_config['no_headers'])) {
         // Get first line and use it for column names, convert them to lower case.
         $header = $this->parseHeader($parser, $iterator);
         if (!$header) {
             return;
         }
         $parser->setColumnNames($header);
     }
     // Determine section to parse, parse.
     $start = $state->pointer ? $state->pointer : $parser->lastLinePos();
     $limit = $this->importer->getLimit();
     $rows = $this->parseItems($parser, $iterator, $start, $limit);
     // Report progress.
     $state->total = filesize($fetcher_result->getFilePath());
     $state->pointer = $parser->lastLinePos();
     $progress = $parser->lastLinePos() ? $parser->lastLinePos() : $state->total;
     $state->progress($state->total, $progress);
     // Create a result object and return it.
     return new ParserResult($rows, $feed->id());
 }
示例#2
0
 public function postExpire(FeedInterface $feed)
 {
     $state = $feed->getState(StateInterface::EXPIRE);
     if ($state->total) {
         drupal_set_message(t('Expired @count items.', ['@count' => $state->total]));
     }
     $feed->clearStates();
     $feed->save();
     $feed->unlock();
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function expire(FeedInterface $feed, $time = NULL)
 {
     $state = $feed->getState(StateInterface::EXPIRE);
     if ($time === NULL) {
         $time = $this->expiryTime();
     }
     if ($time == SchedulerInterface::EXPIRE_NEVER) {
         return;
     }
     $query = $this->queryFactory->get($this->entityType())->condition('feeds_item.target_id', $feed->id())->condition('feeds_item.imported', REQUEST_TIME - $time, '<');
     // 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.
     if ($entity_ids = $query->range(0, $this->importer->getLimit())->execute()) {
         $this->entityDeleteMultiple($entity_ids);
         $state->deleted += count($entity_ids);
         $state->progress($state->total, $state->deleted);
     } else {
         $state->progress($state->total, $state->total);
     }
 }