Basicly I want to migrate content from one drupal8 instance to another. they are mostly identical with some small changes.
first step is to migrate the content type via drush gen module
module and drupal-console drupal config:export:content:type
then i export the content type via script:
<?PHP
define('DRUPAL_DIR', __DIR__ . "/web");
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
require_once DRUPAL_DIR . '/core/includes/database.inc';
require_once DRUPAL_DIR . '/core/includes/schema.inc';
$autoloader = require_once DRUPAL_DIR . '/autoload.php';
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel->boot();
$kernel->prepareLegacyRequest($request);
use Drupal\node\Entity\Node;
use Drupal\Component\Serialization;
$serializer = \Drupal::service('serializer');
echo "Node Export Starting... \n\n";
// Nodes
$node_ids = \Drupal::entityQuery('node')->condition('type', 'content-type')->execute();
echo count($node_ids);
$single_nodes = \Drupal\node\Entity\Node::loadMultiple($node_ids);
$data = $serializer->serialize($single_nodes, 'json');
file_put_contents('nodes.json', $data);
i serialize it and write it into a file.
on the new page I install the exported module to receive all fields for the content type + dependencies and so on.
if I try now to run my importer script i get serveral errors that the (exported) nodes can not be created.
$json = json_decode(file_get_contents(__DIR__ . "/import/nodes.json"));
foreach ($json as $nid => $nodeImport) {
$node = Node::create($nodeImport);
$node->save();
}
Node::create() doesnt seems to accept whole exported/loaded NodeArrays nor casted arrays like (array)$nodeImport
Am I missing something?