В Drupal 7 порядок инвертирован по сравнению с Drupal 6: сначала сохраняется узел, а затем сохраняется версия узла.
// Save the node and node revision.
if ($node->is_new) {
// For new nodes, save new records for both the node itself and the node
// revision.
drupal_write_record('node', $node);
_node_save_revision($node, $user->uid);
$op = 'insert';
}
Также, когда узел обновляется, узел сначала сохраняется, а затем сохраняется версия узла.
// For existing nodes, update the node record which matches the value of
// $node->nid.
drupal_write_record('node', $node, 'nid');
// Then, if a new node revision was requested, save a new record for
// that; otherwise, update the node revision record which matches the
// value of $node->vid.
if (!empty($node->revision)) {
_node_save_revision($node, $user->uid);
}
else {
_node_save_revision($node, $user->uid, 'vid');
$update_node = FALSE;
}
$op = 'update';
После сохранения версии узла строка узла обновляется.
if ($update_node) {
db_update('node')
->fields(array('vid' => $node->vid))
->condition('nid', $node->nid)
->execute();
}
В Drupal 7 поле vid для таблицы узлов может быть NULL
, тогда как поля nid и vid для node_revision не NULL
, хотя значение nid по умолчанию равно 0.