I’m building a batch importer module that will take data from one database and create the nodes in drupal. The code to create the node object is this:
$node = new stdClass();
$node->type = 'jobs';
$node->uid = 1;
$node->status = $row->J_Approved;
$node->title = $row->J_Title;
$node->comment = 0;
$node->revision = 1;
$node->promote = 0;
$node->sticky = 0;
$node->created = $row->J_DateTime_Mod;
$node->field_description = $row->J_Body;
$node->field_email = $row->J_MI_Email;
$node->field_jobs_fax = $row->J_MI_Phone;
$node->field_aia_firm = $row->J_AIA;
$node->field_name = $row->J_Sub_Name;
$node->field_phone = $row->J_Sub_Phone;
$node->field_jobs_email = $row->J_Sub_Email;
$node = node_submit($node);
node_save($node);
And the above outputs this in my debug window http://screencast.com/t/R5PhWZWraIR8
When I run this, it doesn’t create the node, but as you can see from the screencast, it sets $node->validates to 1, so im assuming it is valid. I’ve spent around 5 hours trying to debug this and still can’t figure it out. Any help would be appreciated…
Drupal 6 example:
node_load() doesn’t return anything, so it doesn’t check.
You can check it with:
Where the 3d arg will reset the cache before loading the node. Expensive, but that’s the only way I know.
You would then have to check the node->[vars] against each other, and return TRUE if they all match.
I credit http://www.learn-drupal.in/cck/how-to-create-a-drupal-node-programmatically.html with the node_save code example above.