public function FeedsProcessor::clear in Feeds 7.2
Same name and namespace in other branches
- 6 plugins/FeedsProcessor.inc \FeedsProcessor::clear()
- 7 plugins/FeedsProcessor.inc \FeedsProcessor::clear()
Removes all imported items for a source.
Parameters
FeedsSource $source: Source information for this expiry. Implementers should only delete items pertaining to this source. The preferred way of determining whether an item pertains to a certain souce is by using $source->feed_nid. It is the processor's responsibility to store the feed_nid of an imported item in the processing stage.
File
- plugins/
FeedsProcessor.inc, line 638 - Contains FeedsProcessor and related classes.
Class
- FeedsProcessor
- Abstract class, defines interface for processors.
Code
public function clear(FeedsSource $source) {
$state = $source
->state(FEEDS_PROCESS_CLEAR);
// Build base select statement.
$select = db_select('feeds_item')
->fields('feeds_item', array(
'entity_id',
))
->condition('entity_type', $this
->entityType())
->condition('id', $this->id)
->condition('feed_nid', $source->feed_nid);
// If there is no total, query it.
if (!$state->total) {
$state->total = $select
->countQuery()
->execute()
->fetchField();
}
// Delete a batch of entities.
$entity_ids = $select
->range(0, $this
->getLimit())
->execute()
->fetchCol();
$this
->entityDeleteMultiple($entity_ids);
// Report progress, take into account that we may not have deleted as many
// items as we have counted at first.
if ($deleted_count = count($entity_ids)) {
$state->deleted += $deleted_count;
$state
->progress($state->total, $state->deleted);
}
else {
$state
->progress($state->total, $state->total);
}
// Report results when done.
if ($source
->progressClearing() == FEEDS_BATCH_COMPLETE) {
$info = $this
->entityInfo();
if ($state->deleted) {
$message = format_plural($state->deleted, 'Deleted @number @entity', 'Deleted @number @entities', array(
'@number' => $state->deleted,
'@entity' => strtolower($info['label']),
'@entities' => strtolower($info['label plural']),
));
$source
->log('clear', $message, array(), WATCHDOG_INFO);
drupal_set_message($message);
}
else {
drupal_set_message(t('There are no @entities to be deleted.', array(
'@entities' => $info['label plural'],
)));
}
}
}