I'm working on sitenews module which among other functions has to remove nodes after certain period (hook_cron).

It is possible to issue 'DELETE FROM {...} WHERE ...' queries to remove everything from node, node_revisions, url_alias, sitenews, and maybe other tables. The problem is that I'm not sure if I know all the tables, which should be cleaned. Say, one day I'll decide to allow attachements to sitenews nodes and then I should check attachements table too.

It is not possible to use node_delete() since it checks privileges and cron.php is ran without any.

The questions are:

  • If I have to use separate queries to remove all the data attached to certain nid, how can I be sure that I cleaned everything?
  • Are there any other possibilities?

Comments

Andrei Toutoukine’s picture

For now I decided to reimplement node_delete function, dropping permissions check. Module specific table is cleared with node_invoke($node, 'delete');, other superstructures with node_invoke_nodeapi($node, 'delete');,
See the description at http://api.drupal.org/api/4.7/function/node_delete