0

I'm trying to delete a node knowing it's nid.

I've implemented hook_cron in order to do this:

function my_module_cron() {
  node_delete(5446);
  print "deleting node 5446";
}

The print message it's shown when executing the hook_cron, so I assume it also executes node_delete.

But the node it's still there in the website and also in the DB.

Other alternative would be manually deleting the node from the DB using the queries that appear in the node_delete code

Would this be enough?

Could it broke something doing this manually instead of using node_delete?

I call the hook_cron using drush:

drush --uri="www.myurl.com" php-eval 'my_module_cron();'
1
  • Have you configured cron jobs properly ? Can you add a watchdog statement in cron with a timestamp and make sure that its being run ? – GoodSp33d Jul 25 '12 at 10:28
2

How is cron being called? (drush, wget, manually run).

node_delete requires the permission delete to actually execute the delete queries.

Depending on how you run cron will depend on the result, for example if cron is run from wget then it's run as an anonymous user therefore nothing will happen as hopefully anonymous user can't delete content.

If you try calling cron from status report while logged in as uid 1 then it should delete fine.

1
  • Running cron with status report worked fine as you correctly pointed out. Thanks! – rfc1484 Jul 25 '12 at 10:30

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.