[development] The state of import export

Roman Chyla roman.chyla at gmail.com
Tue Jan 29 00:45:54 UTC 2008


i was not asking the right question, so i will try to reiterate, maybe
some developers with  better knowledge of Drupal and its modules will
know the answer.

as you see, many people are trying to construct node array and submit
it to node_save()
however, would it be possible with Drupal to do something like this?

$new = get_new_node('article');
$new->add('title', 'Hello world');
$new->add('userid', 1);
$new->commit;

basically, the new import function would only have to construct the
node object and submit it to Drupal

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


More information about the development mailing list