If using the Node export module I import nodes from the biblio module and the authors do not exist in the import-to site, the authors are not imported. If the authors exist, they are imported correctly. Can this be fixed? I'm not sure whether a biblio or node export problem.

Comments

tdombos’s picture

It is a biblio bug according to Node Export developer. See http://drupal.org/node/826504#comment-3106714

rjerome’s picture

I suspect the problem lies in the fact that the author "cid" is included in the export, thus when it's imported biblio assumes that it should already exists since it couldn't have a "cid" value if it didn't exist in the database. I bet if you were to delete the cid value it would work.

    'biblio_contributors' => array(
      '1' => array(
        '0' => array(
          'nid' => '717',
          'vid' => '954',
          'cid' => '579',                           // <---- Delete this line
          'auth_type' => '1',
          'auth_category' => '1',
          'rank' => '0',
          'aka' => '579',
          'drupal_uid' => NULL,
          'name' => 'Goldberg, Jonathan',
          'lastname' => 'Goldberg',
          'firstname' => 'Jonathan',
          'prefix' => '',
          'suffix' => '',
          'initials' => '',
          'affiliation' => '',
          'md5' => 'd3bf8423b7e2d4b1242e2c580bb28ab8',
        ),
tdombos’s picture

That was indeed the problem, thank you for pointing that out. Node export has a hook method for export/import transformations (hook_node_export_node_alter). If I simply delete all the cid programmatically, will that mean a double author entry for the same name will be created?

rjerome’s picture

No it should not create duplicates becuase when a new author is inserted, the "md5" value is compared with existing database entries and if a match exists, then the two entries are assumed to be the same and the existing "cid" value is used rather than creating a duplicate.

Ron.

rjerome’s picture

Just out of curiosity, what is your motivation for this export/import operation? Are you moving to a different installation or did you just want to duplicate the biblio data on another installation?

tdombos’s picture

I'm creating a metarepositosy based on project bibliographies running on different drupal instances. The ideal solution would be a services based push synchronization, but until those modules are working well, I'll use this manual method.

#4 great news, I hoped for this. I'll try to do a patch and post it, if I have more time, this could be included in biblio by default.

rjerome’s picture

The reason I asked was that I have developed a client/server module for biblio that, in conjunction with the services module and turns any biblio installation into a remote client of any biblio installation running the service module. The client side appears to be a normal biblio installation but there is no biblio data stored on the client and it's read-only, meaning you can't create, modify or delete biblio items on the client side.

daengo’s picture

would you mind sharing your code for how you did this programmatically? I need to figure this out too.

daengo’s picture

Hello,
I am trying to use Node Export also since it lets me export a group of records on a test site and import them on the production site. When using biblio's export records, I don't see a way to control how many it exports thus creating a HUGE file of my 8,000+ bibs. Is there an easier way or do you have advice on the code how to control the hook_node_export_node_alter to remove the 'cid' line for Node Export?

rjerome’s picture

I haven't actually tested this code, but if you paste the following at the end of your biblio.module file, it should remove the "cid" value for you...


function biblio_node_export_node_alter(&$node, $original_node, $method) {
  if ($method == 'export') {
    foreach ($node->biblio_contributors as $cat => $authors) {
      foreach ($authors as $key => $author) {
        unset($node->biblio_contributors[$cat][$key]['cid']);
      }
    }
  }
}
daengo’s picture

Thank you so much! That seems to work. At first I had trouble getting it to work because I only enabled the hook on the destination and not the source site. I'm not sure if the hook has to been enabled on the destination, but obviously based on the the fact that it is dealing with an export, the source has to have the hook enabled. I'll have to see what happens when I try to export from my 6.x-1.x-dev test site to the 6.x-1.15 production site. Hopefully, it will be no problem.

daengo’s picture

Thank you so much! That seems to work. At first I had trouble getting it to work because I only enabled the hook on the destination and not the source site. I'm not sure if the hook has to been enabled on the destination, but obviously based on the the fact that it is dealing with an export, the source has to have the hook enabled. I'll have to see what happens when I try to export from my 6.x-1.x-dev test site to the 6.x-1.15 production site. Hopefully, it will be no problem.

rjerome’s picture

Let me know if it imports OK and if so I'll put that code in the module.

Ron.

rory_o’s picture

Title: new auhtors dropped on node export/import » new authors dropped on node export/import
Version: 6.x-1.9 » 7.x-1.x-dev

Hi, I'm having the same problem using the 7-x version. I tried removing the cid field and it works fine, but the node_export_node_alter hook doesn't appear to be valid in Node Export 3.x... I'm not sure. I cross posted asking this here to get a definitive answer from Node Export.

rjerome’s picture

I believe the issue here is that the $node->biblio_contributors data structure has changed in 7.x

The following will probably work...

function biblio_node_export_node_alter(&$node, $original_node, $method) {
  if ($method == 'export') {
    foreach ($node->biblio_contributors as $key => $author) {
        unset($node->biblio_contributors[$key]['cid']);
    }
  }
}
rory_o’s picture

That didn't unfortunately :( but I'll play around with it and see what I can come up with.

Though on a different going the different, could you ignore cid on biblio_node_save instead? I'm thinking on other external manipulations that can manipulate entities directly like Services.

rory_o’s picture

Got it, here's what works now:

function biblio_node_export_node_alter($node, $original_node) {
  foreach ($node->biblio_contributors as $n => $value) {
    unset($node->biblio_contributors[$n]['cid']);
  }
}

The $method is removed from the signature since node_export_node_alter is only called on export now.

rjerome’s picture

Status: Active » Fixed

OK, thanks for tracking that down.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rory_o’s picture

StatusFileSize
new700 bytes

Ran into this again, guess it didn't get rolled in. Here's a patch.

rjerome’s picture

OK, this time it's committed...

http://drupalcode.org/project/biblio.git/commit/8ec5612

Thanks,

Ron.

rory_o’s picture

StatusFileSize
new769 bytes

Actually there's a bit of a problem, that hook gets run on every node export so we need to check to see if the exported node really does have the biblio_contributors property, otherwise it will give a ton of PHP warnings. This really really fixes it, sorry about that.

rjerome’s picture