You are here

function _feedapi_node_purge in FeedAPI 6

Delete all nodes associated with a feed.

File

feedapi_node/feedapi_node.module, line 405
Handle how the feed items are represented as a content Handle the processing of the feed items

Code

function _feedapi_node_purge($feed) {
  $total = db_result(db_query('SELECT COUNT(*) FROM {feedapi_node_item_feed} WHERE feed_nid = %d', $feed->nid));
  $deleted = 0;
  $max_execution_time = ini_get('max_execution_time');
  while ($deleted < $total) {

    // Take hundred items at a time.
    $result = db_query_range('SELECT feed_item_nid as nid FROM {feedapi_node_item_feed} WHERE feed_nid = %d', $feed->nid, 0, 100);
    while ($node = db_fetch_object($result)) {
      node_delete($node->nid);
      $deleted++;

      // Stop 5 seconds before script time out.
      if ($max_execution_time - 5 < round(timer_read('page') / 1000)) {

        // Don't show all the node delete messages.
        drupal_get_messages();
        drupal_set_message(t('!deleted feed items of !total could be deleted before script time out - click <em>Remove items</em> again to delete more.', array(
          '!deleted' => $deleted,
          '!total' => $total,
        )));
        return;
      }
    }
  }
  if ($deleted) {

    // Don't show all the node delete messages.
    drupal_get_messages();
    drupal_set_message(t('!count feed items have been deleted.', array(
      '!count' => $deleted,
    )));
  }
  else {
    drupal_set_message(t('There were no feed items to delete'));
  }
}