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.
This is the result to repace 'node_save($node)' for 'dpm($node)' in function 'nuevo_Recibo_Promocion' inside my module:
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?