1

Drupal: 7.31 Php: 5.5.9-1ubuntu4.3

I am trying to create node type 'recibo_promocion_type', after create nodes of type 'offer_type' (diferent type). I am using hook_node_presave. I run the code in the development environment 'run php code', successfully, but the same code within in my personal module does not respond, getting a blank page. I did debug and the line of code that fails is 'node_save ($node)'.

function nuevo_Recibo_Promocion($nid, $uid, $ruta){

define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $user;
$nodeConfigura=node_load($nid);
$node = new stdClass();
$node->nid=0;
$node->type = 'recibo_promocion_type';
$node->uid = $user->uid;
$node->name = $user->name;
$node->title = $nodeConfigura->title;
$node->language = 'es';
$node->field_organizacion = $nodeConfigura->field_organizacion;
$node->field_enlace['und'][0]['url']=$ruta;
$node->field_enlace['und'][0]['title']=$nodeConfigura->title;
$node->field_enlace['und'][0]['attributes']['target']=0;
$node->field_fecha_promocion = $nodeConfigura->field_fecha_promocion;
$node->field_cliente_envio['und'][0]['target_id'] = $uid;
node_object_prepare($node);
$node = node_submit($node);
node_save($node);

}

This is the test code with moc parameters from 'ejecute code php' of dev module, and save node successfully. The moc parameters was extrated from dpm($node) replace save_node($node) in a module.

//moc paraeters
$ruta='http://...';
$uid=184;
$nid =81;


$nodeConfigura=node_load($nid);
$node = new stdClass();
$node->type = 'recibo_promocion_type';
$node->uid = 1;
$node->title = $nodeConfigura->title;
$node->language = 'es';
$node->field_organizacion = $nodeConfigura->field_organizacion;
$node->field_enlace['und'][0]['url']=$ruta;
$node->field_enlace['und'][0]['title']=$nodeConfigura->title;
$node->field_enlace['und'][0]['attributes']['target']=0;
$node->field_fecha_promocion = $nodeConfigura->field_fecha_promocion;
$node->field_cliente_envio['und'][0]['target_id'] = $uid;

node_object_prepare($node);
$node = node_submit($node);
node_save($node); 

the node save successfully.

enter image description here

This is the result to repace 'node_save($node)' for 'dpm($node)' in function 'nuevo_Recibo_Promocion' inside my module: enter image description here

I tried also:

1)Use drupal_register_shutdown_function but the bug is the same.

2)I have created a xmlrpc service, and replace instead the nuevo_Recibo_Promocion call function. The xmlrpc creates successfully the node, but if it's invoked from 'execute php code' (dev module). if xmlrpc it's invoked from from my module, it doesn't created the new node.

$methods = xmlrpc('http://...', array('reciboPromocion.new' => array($nid,$ruta,$uid)));

3) I have disabled all my modules to avoid confict with othes modules (loops Infinite)

4) use try{} catch(exception $e){}... to get the bug.

5) use hock_cron(), but not save the new node.

6) I've tried the user custom permissions, the function node_access($node) before node_save ($node) in two cases: my personal module and dev console 'Run PHP code'. The result is true in all cases.

The question for is, why the process do not shoot any exception, alert, or notify, The result is a don't response and 'blank page' in my web browser.

any suggestion?

2 Answers 2

0

When you are doing node_save() inside hook_node_presave, it will trigger hook_node_presave where you have node_save()...

You could move the node_save else where. Perhaps if your using form in creating the original node just add submit handler in case the node type matches? Or some other way to by pass the infinite loop.

1
  • thanks for your answer. What you say is exactly what i was investigating with dpm (), but was not the problem. I've already solved and describe the bug fix in another post below. Thank you very much again Sep 5, 2014 at 16:39
0

Solved: The problem was the following:

1) I had not closed the hook_presave function, missing the last '}'. 2) The first sentence of my _presave function is:

if ($ node-> type == 'configuracion_promocion_type') { .... }

3) In the last function of my code had a '}' more.

The result was this strange behavior, because in my opinion, should not work with drupal not closed my code.

In the console dev 'execute php code' only proved the insertion node, so it was not in the infinite loop.

Thank you all.

1
  • For these kind of errors you really should tail web server error log.
    – user20301
    Sep 8, 2014 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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