node_save вызванная из хука hook_node_insert = Duplicate entry ' for key 'PRIMARY': INSERT INTO
Primary tabs
итак в моём случае ошибка вызвана кодом типа =
function LL_node_insert($node) // use it because of needing NID of node
{
if (!isset($node->llcheck)) // check to stop recursion
{
$node->body['und']['0']['value'] = "123"; // update body
$node->llcheck =1; // up flag before node_save - stop recursion
node_save($node); // udate filed value ERROR IS HERE
}а именно - для ноды, для которой вызван хук _node_insert вызывается функция обновления node_save()
практика показывает, что возможно следующее решение =
<?php
function LL_node_insert($node) // use it because of needing NID of node
{
if (!isset($node->llcheck)) // check to stop recursion
{
$node2=node_load($node->nid); // ПОСТО ГРУЗИМ НОДУ ЕЩЁ РАЗ
$node2->body['und']['0']['value'] = "123"; // update body
$node2->llcheck =1; // up flag before node_save - stop recursion
node_save($node2); // udate filed value
}
}?>или же так - явно указав, что сохраняемая нода не новая - и сэкономив на загрузке дублирующего экземпляра =
if (!isset($node->llcheck)) // check to stop recursion
{
$node->is_new = FALSE;
$node->body['und']['0']['value'] = "123"; // update body
$node->llcheck =1; // up flag before node_save - stop recursion
node_save($node); // обновляем содержимое поля
}темы в помощь =
ошибка вызвана тем, что происходит попытка повторного сохранения ноды до выхода из данной функции = http://api.drupal.org/api/drupal/include...
- drudev's blog
- Log in to post comments
- 7187 reads