Drupal node_save crashes but gives no errors

I create a batch importer module that will take data from one database and create nodes in drupal. The code for creating the node object is as follows:

$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 above it is displayed in my debug window http://screencast.com/t/R5PhWZWraIR8 When I run this, it does not create a node, but as you can see from screencast, it sets $ node β†’ validates to 1, so im assuming that it is valid. I spent about 5 hours trying to debug this and still can't figure it out. Any help would be appreciated ...

+4
source share
1 answer

Drupal 6 example:

 <?php $node = new stdClass(); //Create instance of class stdClass which will create node for you. $node->type = 'library'; //Name of the content type $node->field_book_no[0][value] = 22;//Book number CCK Field $node->field_book_name[0][value] = "Drupal"; //Book name CCK Field $node->field_book_author[0][value]='Sachin'; //Author name - CCK field $node->field_year[0][value]='2011'; //Publication year - CCK field $node->uid = 1; // user id, 1 is created by admin $node->status = 1;//1 is published, 0 is unpublished $node->promote = 0;//1 is promote to home page, 0 is not to promote on home page node_save($node); // Save this node ?> 

node_load () does not return anything, so it does not check.

You can check this with:

 $new_node = node_load($node->nid, NULL, TRUE); 

If 3d arg will reset the cache before loading node. Expensive, but this is the only way I know.

Then you will need to check 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 above node_save code example.

0
source

All Articles