You are here

public function NodeExportCommands::exportNode in Node export 8

Export nodes.

@options save An option to specify whether or not to save the file.

@usage node-export-export 1,2,3,4,5 OR all Export all nodes or specify the nids.

@command node-export-export

@aliases ne-export

Parameters

string $nodes: IDs of the nodes to be exported.

array $options: Array of options for the command.

File

src/Commands/NodeExportCommands.php, line 40

Class

NodeExportCommands
A Drush commandfile.

Namespace

Drupal\node_export\Commands

Code

public function exportNode($nodes = 'all', array $options = [
  'save' => 'n',
]) {
  $save = substr(strtolower($options['save']), 0, 1) === 'y';
  $ids = $nodes === 'all' ? [] : explode(',', ltrim($nodes));
  $export = NodeExport::export($ids, 'json', $save);
  if ($save) {
    if ($export) {
      $this
        ->logger()
        ->success(dt('Nodes exported to ' . \Drupal::service('file_system')
        ->realpath($export
        ->getFileUri())));
    }
    else {
      $this
        ->logger()
        ->error('Could not export the nodes.');
    }
  }
  else {
    $this
      ->writeln($export);
  }
}