0

I am trying to make a custom module which delete all nodes of a content type and then import new nodes of this type from a .txt (maybe I will use feeds import for this).

In the first step of my module, I had found this code to delete nodes:

function nodes_import_delete() {
  // Gather all the pivot content that might have been created while this
  // module was enabled.  Simple selects still use db_query().
  // http://api.drupal.org/api/function/db_query/7
  $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
  $result = db_query($sql, array(':type' => 'apunte'));
  $nids = array();
  foreach ($result as $row) {
    $nids[] = $row->nid;
  }

  // Delete all the nodes at once
  // http://api.drupal.org/api/function/node_delete_multiple/7
  node_delete_multiple($nids);
}

My problem is this function never finish when is executed and I don't know why.

apunte is my content type which I want to delete all nodes.

0

May be the server execution is taking long time to delete nodes.Try to increase your server execution time or change the code to batch process or pass limited nids to the delete function.

  • Agree with Narsing. I think because count(nids) have a big number so its never finish – visabhishek Apr 11 '16 at 11:09
  • Thank you for your help. My problem is when I try to store $nids[] in foreach ($result as $row) { $nids[] = $row->nid; } – Alvaro Arjona Apr 12 '16 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.