<br>For various reasons, I also arrived at node_save()'s doorstep for data import demands of 6000+ nodes of a few different content types.<br><br>Most recently had a little help from Adrian, and managed to import 10 000 nodes with the imagefield populated, as well as files table.<br>
<br>I find that the most difficult part of data import is to understand the older website, database and files structure, the current customer requirements, and making sure that all the taxonomy and content types are defined.<br>
<br>One little trick, which I haven't yet figured out, is why when populating the imagefield nid, I needed to use node_save twice. Node_save did not save the imagefield nid, when first creating a node. Once saved, and the node object was properly populated and passed back by reference, the second time, the imagefield nid was updated.<br>
<br>For example, most cck fields, can be populated before node_save() by ==><br>$node->field_secondarytitle[0]['value'] = "some value";<br>$node->field_related[0]['nid'] = 123;<br>node_save($node);<br>
<br>For imagefield ==><br>node_save($node);<br>// need the second node_save to save the imagefield<br>$n->field_image[0]['fid'] = $fid;<br>node_save($node);<br><br>Thanks<br>Audrey<br><br><br><div><span class="gmail_quote">On 1/27/08, <b class="gmail_sendername"><a href="mailto:emspace.com.au@gmail.com">emspace.com.au@gmail.com</a></b> <<a href="mailto:emspace.com.au@gmail.com">emspace.com.au@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I would add to the list <a href="http://drupal.org/project/install_profile_api">http://drupal.org/project/install_profile_api</a><br>Particularly the crud.inc file.<br><br>I've used it for a couple projects and added bits to it.<br>
<br>Topically, I do have a node create function that works well most of<br>the time. But it's a bit flakey depending what contrib modules are<br>doing to the node form.<br><br>I focus on passing everything in a simple keyed array format, and the<br>
function then makes it look like a node submission. The difficulty<br>I've had is making the submitted form the right structure - the cck<br>fields are difficult to emulate, but I'm handling many of them (text,<br>
number, nodereference, etc).<br><br>If it's of any interest, here is the uncommitted code. I chopped out<br>some hacks, so this version untested.<br><br>function install_create_content($content_type, $properties) {<br>
global $user;<br><br> $default = array();<br> $default['type'] = $content_type;<br> $default['format'] = 0;<br> $default['comment'] = 2; // Enable read/write comments<br> $default['status'] = 1; // Published<br>
$default['promote'] = 0; // Not promoted to front page.<br> $default['sticky'] = 0; // Not sticky.<br><br> $default['created'] = date('g:i:sA');<br> $default['log'] = 'Updated at ' . date('g:i:sA') . ' via<br>
install_create_content' ;<br><br> $default['name'] = $user->name;<br> $default['uid'] = $user->uid;<br><br> foreach ($properties AS $property => $value) {<br> $field = content_fields($property, $content_type);<br>
if (isset($field['field_name'])) {<br> switch ($field['type']) {<br> case 'nodereference':<br> case 'userreference':<br> $default[$property] = array(array('nid' => $value));<br>
break;<br> default:<br> if (is_array($value)) {<br> // Uncertain.<br> $default[$property][] = $value;<br> }<br> else {<br> $default[$property] = array(array('value' => $value));<br>
}<br> }<br> if ($field['widget']['type'] == 'options_select' &&<br>isset($default[$property][0]['value'])) {<br> if ($field['multiple']) {<br> foreach ($property[0] AS $v) {<br>
$default[$property]['keys'][$value] = $value;<br> }<br> }<br> else {<br> $default[$property]['key'] = $default[$property][0]['value'];<br> }<br> //unset($default[$property][0]);<br>
}<br> unset($properties[$property]);<br> }<br> }<br><br> $node = array_merge($default, $properties);<br> $node = node_submit($node);<br> node_save($node);<br> return $node;<br>}<br><br>On 1/26/08, adrian rossouw <<a href="mailto:adrian@bryght.com">adrian@bryght.com</a>> wrote:<br>
><br>> On 25 Jan 2008, at 4:56 PM, Daniel F. Kudwien wrote:<br>><br>> ><br>> > It is. But it's the most advanced and flexible solution currently<br>> > available<br>> > for Drupal. Many folks have contributed to ImportExport API,<br>
> > however the<br>> > module seems to be unmaintained currently. The API docs are in an<br>> > pre-alpha<br>> > state, too. So it is definitely not easy to understand, how<br>> > ImportExport<br>
> > API works, and how it could work out for your requirements.<br>> it's a query builder. just like views / cck.<br>><br>> and it has it's own set of _schema like hooks, which is what's<br>> annoying about it.<br>
> since you get to type everything out ... again.<br>><br>> I once wrote a install profile generator for it for drupal 4.7, but i<br>> didn't have the time nor energy<br>> to update ieapi for d5<br>><br>
><br></blockquote></div><br>