Document where nid entries are pointing to

dannyobrien - June 24, 2009 - 00:49
Project:Node Export
Version:6.x-2.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Here's a patch that adds non-executing comments to the export output, giving the title of the node that any item with the keyname "nid" points to.

If, like me, you're using Node Export as a backup, it's reassuring to be able to work out what references what from the export text alone.

AttachmentSize
node_export_nid_comment.diff632 bytes

#1

danielb - June 24, 2009 - 01:29
Status:active» needs work

Not sure I'm comfortable with that being there by default - makes a few assumptions that could lead to problems (like values for a nid field being a valid node id), and the output is a bit anti-drupal (are you a perl programmer??). Perhaps I will provide a hook so this can be done another way that is configurable. I also think in a majority of use cases the 'nid' values are completely misleading, and any references will be inaccurate on the destination site, so this might lead people to try and read the export code and subsequently get the wrong idea.

<?php

   
foreach ($var as $key => $value) {
     
$code .= $tab ."  '". $key ."' => ".node_export_node_encode($value, $iteration).",\n";
    }

?>

could become

<?php

   
foreach ($var as $key => $value) {
     
$out = $tab ."  '". $key ."' => ".node_export_node_encode($value, $iteration).",\n";
     
$code .= drupal_alter('node_export_node_encode', $out, $tab, $key, $value, $iteration);
    }

?>

and then you do

<?php

function YOURMODULE_node_export_node_encode_alter(&$out, $tab, $key, $value, $iteration) {
  if ((
$key == 'nid') && $node = node_load($value)) {
    
$out = $tab ."  '". $key ."' => ".node_export_node_encode($value, $iteration).',';
    
$out .= "// '".$node->title."'";
    
$out .= "\n";
  }
}

?>

Will think about it some more.

#2

dannyobrien - June 24, 2009 - 04:19

Interesting! Thanks for the suggestions!

#3

danielb - June 25, 2009 - 12:01
Status:needs work» fixed

I've added the hook into the module. Hopefully this is satisfactory so you can change each array element to add your own output.

#4

System Message - July 9, 2009 - 12:10
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.