Skip to content

Instantly share code, notes, and snippets.

@pedrofaria
Created January 8, 2010 17:48
Show Gist options
  • Save pedrofaria/272226 to your computer and use it in GitHub Desktop.
Save pedrofaria/272226 to your computer and use it in GitHub Desktop.
<?php
function my_node_save(&$node) {
// Let modules modify the node before it is saved to the database.
node_invoke_nodeapi($node, 'presave');
global $user;
// ALEAGI -- Comentei aqui!
//$node->is_new = FALSE;
// Apply filters to some default node fields:
if (empty($node->nid)) {
// Insert a new node.
$node->is_new = TRUE;
// When inserting a node, $node->log must be set because
// {node_revisions}.log does not (and cannot) have a default
// value. If the user does not have permission to create
// revisions, however, the form will not contain an element for
// log so $node->log will be unset at this point.
if (!isset($node->log)) {
$node->log = '';
}
// For the same reasons, make sure we have $node->teaser and
// $node->body. We should consider making these fields nullable
// in a future version since node types are not required to use them.
if (!isset($node->teaser)) {
$node->teaser = '';
}
if (!isset($node->body)) {
$node->body = '';
}
}
elseif (!empty($node->revision)) {
$node->old_vid = $node->vid;
}
else {
// When updating a node, avoid clobberring an existing log entry with an empty one.
if (empty($node->log)) {
unset($node->log);
}
}
// Set some required fields:
if (empty($node->created)) {
$node->created = time();
}
// The changed timestamp is always updated for bookkeeping purposes (revisions, searching, ...)
$node->changed = time();
$node->timestamp = time();
$node->format = isset($node->format) ? $node->format : FILTER_FORMAT_DEFAULT;
// Generate the node table query and the node_revisions table query.
if ($node->is_new) {
_node_save_revision($node, $user->uid);
drupal_write_record('node', $node);
db_query('UPDATE {node_revisions} SET nid = %d WHERE vid = %d', $node->nid, $node->vid);
$op = 'insert';
}
else {
drupal_write_record('node', $node, 'nid');
if (!empty($node->revision)) {
_node_save_revision($node, $user->uid);
db_query('UPDATE {node} SET vid = %d WHERE nid = %d', $node->vid, $node->nid);
}
else {
_node_save_revision($node, $user->uid, 'vid');
}
$op = 'update';
}
// Call the node specific callback (if any).
node_invoke($node, $op);
node_invoke_nodeapi($node, $op);
// Update the node access table for this node.
node_access_acquire_grants($node);
// Clear the page and block caches.
cache_clear_all();
}
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
db_set_active('old');
$rs = db_query("SELECT nid FROM nodes");
db_set_active();
while ($nid = db_fetch_object($rs)) {
$node = node_load($nid);
$node->is_new = TRUE;
my_node_save($node);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment