I'm trying to update a node->body using a php script in my root directory of my Drupal 7.22 installation.
I call the script through a browser (firefox) with [http://MYSITEURL/nodeupdate.php]
But somehow I don't get it to work.
Here is the code I use:
<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$nid = 9; // YES node 9 exists.
$node = node_load($nid); // where $nid is the node id
echo "$node->title <br>"; // Just to make sure it changes the right node and it does.
$node->body[$node->language][0]['value'] = "Test updated";
if( $node = node_submit($node)) {
node_save($node);
echo "Node with nid " . $node->nid . " updated!<br>";
}
print_r($node); // Check if we see any changes.
?>
The script executes fine without any errors. Through the print_r function I can see that the "changed" field and "revision_timestamp" field are changing.
However the body doesn't change!
I have been googling and found many posts from which I gather that this is the way to do it.
What am I missing?
print(user_access('edit any page content'));
, replacing "page" with the machine-readable content type. It should return 1 (true). Also, is the body not updating when you view the node, or even when you runprint_r($node);
in your script? – eclecto Jul 31 at 15:56