1

私は非常に奇妙な行動に出くわしました。私のコードでは、いくつかのフィールドで新しいノードを保存しています。これは以前は完全にうまく機能していたと言わざるを得ません。しかし、今では機能しなくなりました。devel モジュールを使用して、オブジェクトと変数の内容を出力します。これが私のコードです。

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

最初の dsm() 関数は、ノード オブジェクトを作成したとおりに表示し、想定どおりに表示します。2 番目の 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