By thecalebrogers on
Hi,
I searched and didn't find a suitable answer. I would like to delete a node by calling the delete hook of a different module. Specifically, I have a module I wrote, called "Sport" and I would like to delete (on command) a node from the Image module. The user who issues this delete command will probably not be the same user who created the image node originally.
I want to be able to delete a node programatically, no matter who created the node. And I want to call the delete hook so that I get all the delete functionality that goes along with it.
Anyone know how to do this?
Thanks,
Caleb
Comments
just use
just use node_delete
http://api.drupal.org/api/function/node_delete/5
http://api.drupal.org/api/function/node_delete/6
----------------------------------------
German IRC-Channel: irc.freenode.net #drupal.de ... Jabber-me: dwehner@im.calug.de
You can use hook_nodeapi() on $op=='delete' case
http://api.drupal.org/api/function/hook_nodeapi/5
You can use hook_nodeapi() on $op=='delete' case
OK, that looks like it might
OK, that looks like it might work. I've never used it before because I've never had a need to. Can you point me to a working example? The api docs don't help me as much as a code example.
What I think I understand is that I pass in a node reference and the operation to the nodeapi function. So, something like this:
image_nodeapi(&$node, 'delete');
Like so?
How do I get the reference to the node? I was looking back at the drupal programming I've done and I realized that I have never handled nodes that way. Surely I don't just pass in a node id... A little code snippet example would really help. It's just something I've never done before so I don't know how to do it.
Thanks,
Caleb
http://www.cube-escape.com
i prefer node_delete
i prefer node_delete function...
if you have the node id, load the node with node_load function and call node_delete before...
cya...
--
Pedro Faria de Mirando Pinto
http://www.phpavancado.net - DevBlog (pt_BR)
http://www.eusouopedro.com - Blog (pt_BR)
irc://irc.freenode.org/drupal-br - IRC Help channel (pt_BR)
I tried to use the delete
I tried to use the delete hook, and I didn't get an error. However, I did get mixed results. The image files were deleted, but the nodes are still in the node table. All of the relevant records from the file table were removed. So, it looks like it worked with the exception of the node table records.
Here is the code I used:
Do I need to do anything else to get drupal to delete from the node table? I mean, I can write queries to delete records from the node and node revisions tables, but if there was a way to do it automatically... I guess I just assumed that the delete hook would do it. But, I could be missing a piece.
I guess if I used image_load($node->nid) before the image_delete($node)?
Thanks,
Caleb
http://www.cube-escape.com
try
try it...
but this code will delete all nodes with image type... :/
cya
--
Pedro Faria de Mirando Pinto
http://www.phpavancado.net - DevBlog (pt_BR)
http://www.eusouopedro.com - Blog (pt_BR)
irc://irc.freenode.org/drupal-br - IRC Help channel (pt_BR)