This code should save a new node. It does so but with these errors:

Notice: Undefined property: stdClass::$nid in simplenews_node_presave() (line 441 of /Users/joachim/Sites/lab-7/sites/all/modules/contrib/simplenews/simplenews.module).
Notice: Undefined property: stdClass::$nid in simplenews_newsletter_defaults() (line 474 of /Users/joachim/Sites/lab-7/sites/all/modules/contrib/simplenews/simplenews.module).

  $node = (object) NULL;
  $node->type = 'simplenews';
  $node->title = 'New page';
  $node->uid = 0;
  $node->status = 1;
  $node->language = 'und';
  node_save($node);

The problem is that simplenews_node_presave() assumes a nid property is at least set. When a new node is saved via the UI, $node->nid is set but NULL. When using node_save(), $node->nid won't be set at all (which is the correct way to use node_save() -- see http://api.drupal.org/api/drupal/modules!node!node.module/function/node_...).

Marking as major as this is affecting unit tests in Simplenews Scheduler.

CommentFileSizeAuthor
#1 fix_presave_notices.patch2.39 KBberdir

Comments

berdir’s picture

Status: Active » Needs review
StatusFileSize
new2.39 KB

Patch including a test.

berdir’s picture

Status: Needs review » Fixed

Commited.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.