You are here

protected function StaticCommand::exportPaths in Tome 8

Exports the given paths to the static directory.

Parameters

string[] $paths: An array of paths.

array $old_paths: An array of paths that have already been processed.

int $process_count: The number of processes to invoke.

int $path_count: The number of paths to export per process.

bool $show_progress: Whether or not a progress bar should be shown.

int $retry_count: The number of times to retry a failed command.

string $uri: The URI of the site, probably passed by -l or --uri.

2 calls to StaticCommand::exportPaths()
StaticCommand::execute in modules/tome_static/src/Commands/StaticCommand.php
StaticExportPathCommand::execute in modules/tome_static/src/Commands/StaticExportPathCommand.php

File

modules/tome_static/src/Commands/StaticCommand.php, line 154

Class

StaticCommand
Contains the tome:static command.

Namespace

Drupal\tome_static\Commands

Code

protected function exportPaths(array $paths, array $old_paths, $process_count, $path_count, $show_progress, $retry_count, $uri) {
  $paths = $this->static
    ->exportPaths($paths);
  if (empty($paths)) {
    return;
  }
  if ($this->io
    ->isVerbose()) {
    $this->io
      ->writeln('Exporting paths:');
    $this->io
      ->listing($paths);
  }
  $commands = [];
  $chunks = array_chunk($paths, $path_count);
  foreach ($chunks as $chunk) {
    $command = $this->executable . ' tome:static-export-path ' . escapeshellarg(implode(',', $chunk)) . ' --return-json --process-count=' . escapeshellarg($process_count) . ' --uri=' . escapeshellarg($uri);
    $commands[] = $command;
  }
  $show_progress && $this->io
    ->progressStart(count($paths));
  $invoke_paths = [];
  $collected_errors = $this
    ->runCommands($commands, $process_count, $retry_count, function (Process $process) use ($show_progress, &$invoke_paths, $path_count) {
    $show_progress && $this->io
      ->progressAdvance($path_count);
    $output = $process
      ->getOutput();
    if (!empty($output) && ($json = json_decode($output, TRUE))) {
      $invoke_paths = array_merge($invoke_paths, $json);
    }
  });
  $invoke_paths = array_diff($invoke_paths, $old_paths);
  $old_paths = array_merge($old_paths, $invoke_paths);
  $show_progress && $this->io
    ->progressFinish();
  if (!empty($collected_errors)) {
    $this
      ->displayErrors($collected_errors);
  }
  if (count($invoke_paths)) {
    $this->io
      ->writeln('Processing related assets and paths...');
    $this
      ->exportPaths($invoke_paths, $old_paths, $process_count, $path_count, $show_progress, $retry_count, $uri);
  }
}