0

Is there such thing as a post-save type of case in the node_api function or any other type of function? This question is in reference to a question I posted What operation should I use to write node's information in an email when the node is saved?

I want to be able to have something happen after pressing the save button, but AFTER the saving into the database has been completed. I have tried 'update' and 'insert' and they don't seem to work.

EDIT: heres my code

case 'presave':
    {
        if(($node->type == 'team_practice_info') | ($node->type == 'schedule'))
        {

            if(!empty($node->field_alert[0]['value']))
            {
                if($node->field_alert[0]['value'] == 'on')
                {                       
                    //email out to everyone an email about the content change/update
                    $query = db_query("SELECT * 
                                       FROM {content_type_athletics_alert}
                                       JOIN {content_field_team}
                                       ON content_type_athletics_alert.nid = content_field_team.nid
                                       WHERE content_field_team.field_team_nid = 
                                            (SELECT field_team_nid
                                             FROM {node}
                                             JOIN {content_field_team}
                                             ON node.nid = content_field_team.nid
                                             WHERE node.nid = %d)", $node->nid);
                    $rows = array();
                    //db_fetch returns an array of the next row in the query
                    while ($row = db_fetch_array($query))
                    {                       
                        //pull out the email from the array, then send an email to each subscriber                          
                        $email = $row['field_email_address_value'];
                        $first_name = $row['field_first_name_value'];
                        $last_name = $row['field_last_name_value'];
                        $t_id = $row['field_team_nid'];
                        $t=node_load($t_id);
                        $sport = (current($t->taxonomy));
                        $team = $t->title.' '.$sport->name;

                        alert_message_mail_send($email, $first_name, $last_name, $team, $node);
                    }
                    //reset the alert checkbox to off
                    $node->field_alert[0]['value'] = 'off';
                }                   
            }
        }
    }

   break;
  • The 'insert' and 'update' $op work perfectly for me (and have done for a couple of years now), can you post the code you're using that doesn't work? To answer your question, no, there isn't a 'post-save' $op, as that is taken care of by 'insert' and 'update' – Clive May 7 '12 at 17:43
  • I've written a module that provides what you're looking for. You can find the details here : stackoverflow.com/questions/5308465/post-save-callback – Sina Salek Jun 4 '14 at 11:20
1

If you are having trouble with hook_nodeapi (though I have never had problems with it), you could try using Rules.

There is a stock event After saving new content that you can try. There is also a stock DO action, Send a mail to a user. You then get the normalish token-based email form that you can configure.

We have used this on few projects with good luck.

|improve this answer|||||
  • Everyone is saying that they don't have any issues with node_api, there must be some way of fixing my problem without having to use a different module.... – user1015214 May 8 '12 at 19:01
0

Use the register_shutdown_function. Here's the code for drupal 7, modify it for drupal 6 as needed:

<?php

function your_module_node_update($node){    
    if($node->type == 'your_node'){
        register_shutdown_function('_your_module_send_report_email',$node);
    }
}
?>
|improve this answer|||||
  • see drupal_register_shutdown_function – Arosboro Jun 8 '13 at 18:55

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.