For better or worse, this is the code I use in the aggregation module and it seems to be working flawlessly. This is in the yet to be released release though (drupal 5). If there's a better way I'd be glad to know it.<br>
<br>(INSERT)<br>$node = new stdClass();<br>$node->title = "{$XML->name}";<br>$node->body = "{$XML->description}";<br>$node->eid = $eid;<br><br>node_save($node);<br>module_invoke_all('nodeapi', $node, 'insert', NULL, NULL);<br>
<br>--------------<br>(UPDATE)<br>$node = node_load(array('nid' => 5));<br>$node->title = "{$XML->name}";<br>
$node->body = "{$XML->description}";<br>
$node->eid = $eid;<br><br>node_save($node);<br>module_invoke_all('nodeapi', $node, 'update', NULL, NULL);<br>
<br><br><div class="gmail_quote">On Sat, Mar 8, 2008 at 8:01 PM, Larry Garfield <<a href="mailto:larry@garfieldtech.com">larry@garfieldtech.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Using drupal_execute() or drupal_execute_macro() is a nasty, evil, slow, and<br>
ugly way to programmatically create users and nodes. It's also usually the<br>
only way that will reliably work. :-) I have, however, run into cases where<br>
it does not. For those, I have to fall back to creating the $node object<br>
myself and saving it. Fortunately I've only had to do that for one-off<br>
imports, so I could hard-code defaults.<br>
<br>
There is no real good answer here, not until we get a real Data API in core.<br>
We're working on it. :-)<br>
<div><div></div><div class="Wj3C7c"><br>
On Saturday 08 March 2008, Moshe Weitzman wrote:<br>
> In drupal5, you should call hook_node_submit() and<br>
> hook_nodeapi('submit') before node_save(). that will assure that any<br>
> group info gets saved (for example).<br>
><br>
> In d6 this is not needed since those submit hooks became<br>
> hook_nodeapi(pre_save) and that happens from within node_save().<br>
><br>
> drupal_execute is also a valid way. the node_load() is a little<br>
> expensive but this is a very clean way to proceed. if it is working<br>
> for you, i would proceed like this.<br>
><br>
> On Sat, Mar 8, 2008 at 10:53 AM, Novák Áron <<a href="mailto:aron@novaak.net">aron@novaak.net</a>> wrote:<br>
> > Hi!<br>
> ><br>
> > While the development of FeedAPI, i faced with a problem. FeedAPI has to<br>
> > create nodes programmatically, i believed that this is a really easy<br>
> > thing to do, feedapi now works like this:<br>
> > $node->data1 = "foo";<br>
> > $node->data2 = "bar";<br>
> > node_object_prepare($node); // this is about the default values<br>
> > node_save($node);<br>
> ><br>
> > But I got a report that this is not a good way to do:<br>
> > <a href="http://drupal.org/node/196273" target="_blank">http://drupal.org/node/196273</a><br>
> > Summary:<br>
> > "node_object_prepare() and node_prepare() functions are meant to<br>
> > simulate the demonstration of a node"<br>
> > And some users, who use FeedAPI + 3rd party modules together, really<br>
> > experience bugs around node creation / handling:<br>
> > <a href="http://drupal.org/node/195105" target="_blank">http://drupal.org/node/195105</a> (summary: the core forum module uses<br>
> > form_alter to pass taxonomy-like data. And this data is lost now.)<br>
> ><br>
> > Can you suggest me a perfect way to handle this problem?<br>
> > mustafau (<a href="http://drupal.org/user/207559" target="_blank">http://drupal.org/user/207559</a>) suggested to use<br>
> > drupal_execute($form_id, $form_values), but in this case, i had another<br>
> > problem: drupal_execute has no useful return value and $node structure<br>
> > remains unaltered, so i had to do a node_load after this, which is quite<br>
> > expensive.<br>
> ><br>
> > Thanks,<br>
> ><br>
> > Aron Novak<br>
<br>
<br>
</div></div>--<br>
Larry Garfield AIM: LOLG42<br>
<a href="mailto:larry@garfieldtech.com">larry@garfieldtech.com</a> ICQ: 6817012<br>
<br>
"If nature has made any one thing less susceptible than all others of<br>
exclusive property, it is the action of the thinking power called an idea,<br>
which an individual may exclusively possess as long as he keeps it to<br>
himself; but the moment it is divulged, it forces itself into the possession<br>
of every one, and the receiver cannot dispossess himself of it." -- Thomas<br>
Jefferson<br>
</blockquote></div><br><br clear="all"><br>-- <br>Ashraf Amayreh<br><a href="http://blogs.aamayreh.org">http://blogs.aamayreh.org</a>