Created
July 16, 2018 21:34
-
-
Save mortenson/c037f2ba745f5b152bdba1b821b6d7ad to your computer and use it in GitHub Desktop.
Dump Drupal nodes as YML
This file contains hidden or 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 | |
// Download to Drupal root (where index.php is) and run "drush scr dump.php" | |
$storage = \Drupal::entityTypeManager()->getStorage('node'); | |
$nodes = $storage->loadMultiple(); | |
echo 'Processing ' . count($nodes) . ' nodes...' . "\n"; | |
/** @var Drupal\node\Entity\Node $node */ | |
foreach ($nodes as $node) { | |
$path = 'node_dump/' . ltrim(urldecode($node->url()), '/') . '.yml'; | |
file_prepare_directory(dirname($path), FILE_CREATE_DIRECTORY); | |
echo "Saving node " . $node->id() . " to $path\n"; | |
file_put_contents($path, \Drupal\Core\Serialization\Yaml::encode($node->toArray())); | |
} | |
echo "Done!\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment