Last active
August 29, 2015 14:06
-
-
Save Jaesin/ab4bf5f78cb029fa43ce to your computer and use it in GitHub Desktop.
Export some nodes to be imported via a hook_update_N. (Drupal)
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 | |
// From: http://steindom.com/articles/how-export-and-import-drupal-nodes | |
// Enter node NIDs to export. | |
$nids = array( | |
1991, // path/to/node/1991 | |
2061, // path/to/node/2061 | |
2016, // path/to/node/2016 | |
2021, // path/to/node/2021 | |
2026, // path/to/node/2026 | |
2031, // path/to/node/2031 | |
2036, // path/to/node/2036 | |
2041, // path/to/node/2041 | |
2046, // path/to/node/2046 | |
2051, // path/to/node/2051 | |
); | |
foreach($nids as $nid){ | |
// 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);'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment