public function NodeExportCommands::importNode in Node export 8
Import nodes.
@usage node-export-import '/path/to/file.json' Import nodes from a given file.
@command node-export-import
@aliases ne-import
Parameters
string $file: File containing exported node code.
File
- src/
Commands/ NodeExportCommands.php, line 71
Class
- NodeExportCommands
- A Drush commandfile.
Namespace
Drupal\node_export\CommandsCode
public function importNode($file) {
$data = file_get_contents($file);
if ($data) {
$nodes = json_decode($data, TRUE);
$countImported = 0;
$countNotImported = 0;
foreach ($nodes as $node) {
$id = NodeImport::import($node);
$id ? $countImported++ : $countNotImported++;
}
if ($countImported > 0) {
$this
->logger()
->success(dt('{count} nodes imported successfully.', [
'count' => $countImported,
]));
}
if ($countNotImported > 0) {
$this
->logger()
->error(dt('{count} nodes could not be imported.', [
'count' => $countNotImported,
]));
}
}
else {
$this
->logger()
->error('Could not read the file.');
}
}