1

我刚刚偶然发现了非常奇怪的行为。在我的代码中,我正在使用一些字段保存新节点。我必须说这曾经很好地工作。但是现在它刚刚停止工作。我使用开发模块打印出对象和变量的内容,这是我的代码:

dsm($node);
node_save($node);
dsm($node);

第一个 dsm() 函数显示了我创建的节点对象以及它应该是的样子。第二个 dsm() 函数显示完全正确的节点对象,其中填充了 nid、字段内容等......但是,尽管 {node} 表中有新记录,但没有任何字段保存在数据库中。此外, node_save 不会产生任何类型的错误。

知道这里发生了什么吗?

这是存储节点的函数:

function manhattan_incident_save($data) {
if ($data['nid']) {
  $node = node_load($data['nid']);
  manhattan_compare_changes($node, $data);
}
else {
  $node = new stdClass();
  $node->type = 'incident';
  node_object_prepare($node);

  $node->title = manhattan_create_incident_id();
  $node->language = LANGUAGE_NONE;      
}

$node->field_incident_popis[$node->language][0]['value'] = $data['field_incident_popis'];
$node->field_incident_popis[$node->language][0]['safe_value'] = check_plain($data['field_incident_popis']);

$node->field_incident_agent[$node->language][0]['uid'] = isset($data['field_incident_agent'])?intval($data['field_incident_agent']):NULL;

$node->field_incident_zdroj[$node->language][0]['tid'] = intval($data['field_incident_zdroj']);
$node->og_group_ref[$node->language][0]['target_id'] = $data['field_incident_oblast']?intval($data['field_incident_oblast']):variable_get('manhattan_public_form_default_area_nid', NULL);
$node->field_incident_riesitel[$node->language][0]['uid'] = isset($data['field_incident_riesitel'])?intval($data['field_incident_riesitel']):NULL;
$node->field_incident_typ[$node->language][0]['tid'] = intval($data['field_incident_typ']);
$node->field_incident_doplnenie[$node->language][0]['nid'] = intval($data['field_incident_doplnenie']);
$node->field_incident_sposob_kontaktu[$node->language][0]['value'] = $data['field_incident_sposob_kontaktu'];
$node->field_incident_dovod_vzniku[$node->language][0]['tid'] = intval($data['field_incident_dovod_vzniku']);

if ($data['field_incident_suvisiaci_zaznam']) {
  foreach ($data['field_incident_suvisiaci_zaznam'] as $file) {
    $result = manhattan_save_files($file);
    if ($result) {
      $node->field_incident_suvisiaci_zaznam[$node->language][] = array('nid' => $result); 
    }
  }
}

// now create/save the customer
if (function_exists('customer_customer_save')) {
  $customer = $data;
  $customer['nid'] = $data['field_incident_customer'];
  $result = customer_customer_save($customer); 
  if ($result) {
    watchdog('upvs', $result['message'], array(), WATCHDOG_NOTICE);
  }
  else {
    watchdog('upvs', t('There was a problem with saving customer %nid'), array('%nid' => $data['nid']), WATCHDOG_ERROR);
  }
}
// now we store nid of saved customer to the node object
$node->field_incident_customer[$node->language][0]['nid'] = $result['nid'];

dsm($node);
node_save($node); 
dsm($node);

if ($data['nid']) {
  watchdog('upvs', t('Incident number %title has been succesfully saved.'), array('%title' => $node->title), WATCHDOG_NOTICE);
}
else {
  watchdog('upvs', t('Incident number %title has been succesfully created.'), array('%title' => $node->title), WATCHDOG_NOTICE);
}

return $node;
}
4

0 回答 0