<br>For various reasons, I also arrived at node_save()&#39;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&#39;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 ==&gt;<br>$node-&gt;field_secondarytitle[0][&#39;value&#39;] = &quot;some value&quot;;<br>$node-&gt;field_related[0][&#39;nid&#39;] = 123;<br>node_save($node);<br>
<br>For imagefield ==&gt;<br>node_save($node);<br>// need the second node_save to save the imagefield<br>$n-&gt;field_image[0][&#39;fid&#39;] = $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> &lt;<a href="mailto:emspace.com.au@gmail.com">emspace.com.au@gmail.com</a>&gt; 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&#39;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&#39;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&#39;ve had is making the submitted form the right structure - the cck<br>fields are difficult to emulate, but I&#39;m handling many of them (text,<br>
number, nodereference, etc).<br><br>If it&#39;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>
&nbsp;&nbsp;global $user;<br><br>&nbsp;&nbsp;$default = array();<br>&nbsp;&nbsp;$default[&#39;type&#39;] = $content_type;<br>&nbsp;&nbsp;$default[&#39;format&#39;] = 0;<br>&nbsp;&nbsp;$default[&#39;comment&#39;] = 2; // Enable read/write comments<br>&nbsp;&nbsp;$default[&#39;status&#39;] = 1;&nbsp;&nbsp;// Published<br>
&nbsp;&nbsp;$default[&#39;promote&#39;] = 0; // Not promoted to front page.<br>&nbsp;&nbsp;$default[&#39;sticky&#39;] = 0;&nbsp;&nbsp;// Not sticky.<br><br>&nbsp;&nbsp;$default[&#39;created&#39;] = date(&#39;g:i:sA&#39;);<br>&nbsp;&nbsp;$default[&#39;log&#39;] = &#39;Updated at &#39; . date(&#39;g:i:sA&#39;) . &#39; via<br>
install_create_content&#39; ;<br><br>&nbsp;&nbsp;$default[&#39;name&#39;] = $user-&gt;name;<br>&nbsp;&nbsp;$default[&#39;uid&#39;] = $user-&gt;uid;<br><br>&nbsp;&nbsp;foreach ($properties AS $property =&gt; $value) {<br>&nbsp;&nbsp;&nbsp;&nbsp;$field = content_fields($property, $content_type);<br>
&nbsp;&nbsp;&nbsp;&nbsp;if (isset($field[&#39;field_name&#39;])) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch ($field[&#39;type&#39;]) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &#39;nodereference&#39;:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &#39;userreference&#39;:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$default[$property] = array(array(&#39;nid&#39; =&gt; $value));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (is_array($value)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Uncertain.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$default[$property][] = $value;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$default[$property] = array(array(&#39;value&#39; =&gt; $value));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($field[&#39;widget&#39;][&#39;type&#39;] == &#39;options_select&#39; &amp;&amp;<br>isset($default[$property][0][&#39;value&#39;])) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($field[&#39;multiple&#39;]) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach ($property[0] AS $v) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$default[$property][&#39;keys&#39;][$value] = $value;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$default[$property][&#39;key&#39;] = $default[$property][0][&#39;value&#39;];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//unset($default[$property][0]);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unset($properties[$property]);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;$node = array_merge($default, $properties);<br>&nbsp;&nbsp;$node = node_submit($node);<br>&nbsp;&nbsp;node_save($node);<br>&nbsp;&nbsp;return $node;<br>}<br><br>On 1/26/08, adrian rossouw &lt;<a href="mailto:adrian@bryght.com">adrian@bryght.com</a>&gt; wrote:<br>
&gt;<br>&gt; On 25 Jan 2008, at 4:56 PM, Daniel F. Kudwien wrote:<br>&gt;<br>&gt; &gt;<br>&gt; &gt; It is.&nbsp;&nbsp;But it&#39;s the most advanced and flexible solution currently<br>&gt; &gt; available<br>&gt; &gt; for Drupal.&nbsp;&nbsp;Many folks have contributed to ImportExport API,<br>
&gt; &gt; however the<br>&gt; &gt; module seems to be unmaintained currently.&nbsp;&nbsp;The API docs are in an<br>&gt; &gt; pre-alpha<br>&gt; &gt; state, too.&nbsp;&nbsp;So it is definitely not easy to understand, how<br>&gt; &gt; ImportExport<br>
&gt; &gt; API works, and how it could work out for your requirements.<br>&gt; it&#39;s a query builder. just like views / cck.<br>&gt;<br>&gt; and it has it&#39;s own set of _schema like hooks, which is what&#39;s<br>&gt; annoying about it.<br>
&gt; since you get to type everything out ... again.<br>&gt;<br>&gt; I once wrote a install profile generator for it for drupal 4.7, but i<br>&gt; didn&#39;t have the time nor energy<br>&gt; to update ieapi for d5<br>&gt;<br>
&gt;<br></blockquote></div><br>