I'm using Rules module to execute a python script after a user has been created / updated. This python script retrieves information of users from the database and feeds a datapushing / realtime data engine.

Everything works perfect, BUT, the script is executing before saving.

Update regarding 'script is executing before saving'

When I get the information from the DB with the python script is the one I have before saving, the only workaround is saving twice. One to make changes, to second one to 'really' update. I've noticed this because I need to save twice to get real information.

I found this issue: http://drupal.org/node/430274

I thought on running the script in Drupal's User Core but good practices kind of don't let me do it ( for now :) )

Update

I created a Module with this Info

<?php
// $Id: infographic.module

/**
* @file
* Custom functions for this site.
*/
function infographic_user_insert(&$edit, $account, $category) {
    exec('python GenerateInfographic.py');
}

function infographic_user_update(&$edit, $account, $category) {
    exec('python GenerateInfographic.py');
}

Any Suggestion!?

Thanks!

link|improve this question

Can you elaborate on the script is executing before saving. Drupal does drupal_write_record before the hook is executed so what exactly is your problem, are you using transactions in your database? – googletorp Jul 30 '11 at 9:46
No, I access directly to the DB, I have updated concerning 'script is executing before saving' – Xavi Colomer Jul 30 '11 at 9:59
feedback

1 Answer

up vote 1 down vote accepted

You can use hook_user_insert and hook_user_update to execute your script, which is called after the user has been saved to the database.

Hooks should be implemented in a module. If you are new to module development, the Drupal documentation describes this very well: http://drupal.org/documentation

link|improve this answer
Thanks @googletorp, I'm kind of newbie on Drupal. Where can I found this hooks? Or should I implement a new class. – Xavi Colomer Jul 30 '11 at 9:09
Ok, I've been investigating, api.drupal.org/api/drupal/modules--user--user.api.php/function/… here. Should I create a custom module with just an empty function ( hook_user_insert ) with the execute script? that's all? – Xavi Colomer Jul 30 '11 at 9:26
@Xavi Updated with links – googletorp Jul 30 '11 at 9:27
@Xavi Almost, create a custom module and create function called [name of module]_user_insert and do you things there. – googletorp Jul 30 '11 at 9:28
Have the same problem I had with Rules. It's executed before saving. I updated my question with the code, which works, but before – Xavi Colomer Jul 30 '11 at 9:36
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.