Created
October 2, 2014 21:50
-
-
Save Morasta/52df0a0e4096f0682fde to your computer and use it in GitHub Desktop.
Drupal: Export node for reimport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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