Skip to content

Instantly share code, notes, and snippets.

@Morasta
Created October 2, 2014 21:50
Show Gist options
  • Save Morasta/52df0a0e4096f0682fde to your computer and use it in GitHub Desktop.
Save Morasta/52df0a0e4096f0682fde to your computer and use it in GitHub Desktop.
Drupal: Export node for reimport
<?php
// Enter node NID to export.
$nid = 1234;
// Use Drupal's export utility to convert the object to code.
include_once DRUPAL_ROOT . '/includes/utility.inc';
$export = drupal_var_export(node_load($nid));
// Strip node NIDs and VIDs, so it imports cleanly.
$export = preg_replace("/'(n|v)id' => '?\d+'?,/", "'$1id' => NULL,", $export);
// Print code needed to import node.
dpm('$node = ' . $export . ';' . "\n" . 'node_save($node);');
//import using the code printed in DPM.
//the resulting node_save nid can be grabbed using dpm($node->nid) immediately following node_save
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment