0

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!

  • 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
1

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

  • 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
0

At least in D7, it worked for me calling

user_save($account); 

at first. this it is if u need it changed in the own custom php rules code. I try to debug a message before/after that line of a load user and it seemed to work.

Actually, it didn't because i needed it changed because i was calling a script and in the script was getting the bad one, and i didn't have access to change that script.

So finally what it worked for me was calling the script in background:

$comando='php -f /var/www/moodle/auth/drupalservices/auth_drupalservices_sync_users.php '.$idUser.' >/var/tmp_files/output.txt &';
exec($comando);

and in the script putting a little sleep so i was sure was already changed in the other side :)

sleep(3);

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.