I have a trigger rule in my project on event "Content is going to be saved" and I developed a module to generate some nodes by node_submit and node_save. The first node is saved, but for the second it appears this error:
"Fatal error: Cannot redeclare _doxologia_replace_diacritics() (previously declared in /modules/rules/rules/modules/php.rules.inc(107) : eval()'d code:1)" and I don't understand why because it is about another node.
Can someone help me?

Thanks
Magda

Comments

klausi’s picture

Component: Rules Core » Rules Engine
Status: Active » Postponed (maintainer needs more info)

Seems like you execute some custom PHP code in your rule, could you post that?

magdab’s picture

In the trigger rule I have this code:

function _doxologia_replace_diacritics($str) {
  // s cu virgula este varianta corecta
  $from = explode(" ", html_entity_decode("Ş ş Ţ ţ",ENT_COMPAT,"UTF-8"));
  $to = explode(" ", html_entity_decode("Ș ș Ț ț",ENT_COMPAT,"UTF-8"));
  return str_replace($from, $to, $str);
}
$type_name = $node->type;
$type = content_types($type_name);
foreach ($type['fields'] as $field) {
   $val = $field['field_name'];
   $arr = array();
   $arr = $node->$val;
   $count = count($arr);
   for ($i = 0; $i < $count; $i++) {
      if (is_string($arr[$i ]['value'])) $arr[$i ]['value'] = _doxologia_replace_diacritics($arr[$i ]['value']);
      if (is_string($arr[$i ]['title']))  $arr[$i ]['title'] = _doxologia_replace_diacritics($arr[$i ]['title']);
   }
   $node->$val = $arr;
}

$node->body = _doxologia_replace_diacritics($node->body);
$node->taxonomy['tags'][2] = _doxologia_replace_diacritics($node->taxonomy['tags'][2]);
$node->title = _doxologia_replace_diacritics($node->title);
$node->teaser = _doxologia_replace_diacritics($node->teaser);
$node->comment = _doxologia_replace_diacritics($node->comment);


return array("node" => $node);

As a condition I have

return $node->language == 'ro';

In another module I try to generate some nodes by node_submit and node_save.


.....
$node1 = (object)$node1;
$node1 = node_submit($node1);
node_save($node1);
$node2 = (object)$node2;
$node2 = node_submit($node);
node_save($node2);
......

The first node is saved, but for the second it appears this error:
"Fatal error: Cannot redeclare _doxologia_replace_diacritics().

Probably I have to move the declaration of the function in another file, but I don't understand why it saw the same declaration if it is about another array node on the save.

klausi’s picture

Category: bug » support
Priority: Critical » Normal
Status: Postponed (maintainer needs more info) » Active

Declaring a function in an evaluated PHP field is not a good idea, because if the field is evaluated twice in one run, then PHP cries out because you try to define a function twice. I would suggest to move the function definition to a custom module.

magdab’s picture

Status: Active » Closed (fixed)

Yes, the problem is solved if I'll move the function in another file.
Thanks