I was trying to create a parent node programatically in our tests:

$node-> // various properties here
$node->simplenews_scheduler = array( ... );
node_save($node);

... and it doesn't work at all, because this module is completely ignorant of node API: our records are saved in simplenews_scheduler_submit() only.

The fix would be to have a hook_node_update/insert and then have simplenews_scheduler_submit() dose up the node object then save it. Which also simplifies our code with the merge query too.

Comments

Berdir’s picture

I'm not very convinced of doing this anymore. My suggestion instead would be a separate API function to store this information.

Simplenews is doing it too but I have plans to remove that in the next major version.

Similar thing for hook_node_load(), we're currently checking every single node if it's maybe a scheduler node or an edition. I think it would save us quite a bit in the end if that is moved to separate load/check functions.

nevets’s picture

It really is best to use the existing api's and not go off on your own track.

Berdir’s picture

There is no existing API.

There is no need to go through node_save(), that's just an indirection, we'd still have our own query, just inside a hook rather than a submit callback. Not really a great example but comment.module uses comment_save() and not $node->new_comment + node_save() ;)

joachim’s picture

comment_save() isn't a good example, as it's saving a comment entity... comment module implements some node API hooks too.
A better example is maybe http://api.drupal.org/api/drupal/modules!forum!forum.module/function/for...

dgtlmoon’s picture

Category: bug » feature
Priority: Major » Normal