views:

67

answers:

1

I've got the weirdest glitch. I'm using nodeapi and targetting the story node type. I have insert case before the presave case, where presave is being used instead of update.

switch ($op){
    case 'insert':
       //do some stuff
    break;
    case 'presave':
       //do some stuff
    break;
}

The weird thing is that when a story node is being created, the presave block runs. I thought insert should kick in instead and then it would quit because of the break, and presave wouldn't run at all. For some reason presave is running at node creation.

+2  A: 

presave is part of the node saving process: it always gets called before the node is saved to the database.

It's used when you want to alter the new $node object before you save it to the database during insert (which gets called when the node is first created) or update (which gets called when an existing node is updated).

So, in your case, when a node is first created, presave is called, then insert.

Mark Trapp