You are here

public function FeedsTermProcessor::clear in Feeds 7

Same name and namespace in other branches
  1. 6 plugins/FeedsTermProcessor.inc \FeedsTermProcessor::clear()

Implements FeedsProcessor::clear().

Overrides FeedsProcessor::clear

File

plugins/FeedsTermProcessor.inc, line 89
FeedsTermProcessor class.

Class

FeedsTermProcessor
Feeds processor plugin. Create taxonomy terms from feed items.

Code

public function clear(FeedsBatch $batch, FeedsSource $source) {
  $deleted = 0;
  $vocabulary = $this
    ->vocabulary();
  $terms = db_query("SELECT td.tid\n                        FROM {taxonomy_term_data} td\n                        JOIN {feeds_term_item} ft ON td.tid = ft.tid\n                        WHERE td.vid = :vid\n                        AND ft.id = :id\n                        AND ft.feed_nid = :feed_nid", array(
    ':vid' => $vocabulary->vid,
    ':id' => $this->id,
    ':feed_nid' => $source->feed_nid,
  ));
  foreach ($terms as $term) {
    if (taxonomy_term_delete($term->tid) == SAVED_DELETED) {
      $deleted++;
    }
  }

  // Set messages.
  if ($deleted) {
    drupal_set_message(format_plural($deleted, 'Deleted @number term from !vocabulary.', 'Deleted @number terms from !vocabulary.', array(
      '@number' => $deleted,
      '!vocabulary' => $vocabulary->name,
    )));
  }
  else {
    drupal_set_message(t('No terms to be deleted.'));
  }
}