Skip to content
Snippets Groups Projects
Commit 88a9f3d5 authored by Alex Barth's avatar Alex Barth
Browse files

Clean up FeedsNodeProcessor::clear().

parent daa1d928
No related branches found
No related tags found
No related merge requests found
......@@ -82,33 +82,48 @@ class FeedsNodeProcessor extends FeedsProcessor {
*/
public function clear(FeedsSource $source) {
$state = $source->state(FEEDS_PROCESS_CLEAR);
if (empty($state->total)) {
$state->total = db_query("SELECT COUNT(n.nid) FROM {node} n JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id WHERE fi.id = :id AND fi.feed_nid = :nid", array(':id' => $source->id, ':nid' => $source->feed_nid))->fetchField();
// Build base select statement.
$select = db_select('node', 'n');
$select->addField('n', 'nid');
$select->join('feeds_item', 'fi', "n.nid = fi.entity_id AND fi.entity_type = 'node'");
$select->condition('fi.id', $this->id);
$select->condition('fi.feed_nid', $source->feed_nid);
// If there is no total, query it.
if (!$state->total) {
$state->total = $select->countQuery()
->execute()
->fetchField();
}
$count = $this->getLimit();
// Delete a batch of items.
$nodes = $select->range(0, $this->getLimit())->execute();
$nids = array();
$nodes = db_query_range("SELECT n.nid FROM {node} n JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id WHERE fi.id = :id AND fi.feed_nid = :nid", 0, $count, array(':id' => $source->id, ':nid' => $source->feed_nid));
foreach ($nodes as $node) {
$nids[$node->nid] = $node->nid;
$state->deleted++;
}
node_delete_multiple($nids);
if (db_query_range("SELECT 1 FROM {node} n JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id WHERE fi.id = :id AND fi.feed_nid = :nid", 0, 1, array(':id' => $source->id, ':nid' => $source->feed_nid))->fetchField()) {
$state->progress($state->total, $state->deleted);
return;
}
// Set message.
drupal_get_messages('status');
if ($state->deleted) {
drupal_set_message(format_plural($state->deleted, 'Deleted @number node.', 'Deleted @number nodes.', array('@number' => $state->deleted)));
// Report progress, take into account that we may not have deleted as
// many items as we have counted at first.
if (count($nids)) {
$state->deleted += count($nids);
$state->progress($state->total, $state->deleted);
}
else {
drupal_set_message(t('There is no content to be deleted.'));
$state->progress($state->total, $state->total);
}
// Report results when done.
if ($source->progressClearing() == FEEDS_BATCH_COMPLETE) {
if ($state->deleted) {
drupal_set_message(format_plural($state->deleted, 'Deleted @number node.', 'Deleted @number nodes.', array('@number' => $state->deleted)));
}
else {
drupal_set_message(t('There is no content to be deleted.'));
}
}
// Make sure we are finished, there may be a discrepancy between total and
// deleted if other processes have deleted nodes in the meantime.
$state->progress = FEEDS_BATCH_COMPLETE;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment