You are here

protected function StaticCommand::execute in Tome 8

1 method overrides StaticCommand::execute()
StaticExportPathCommand::execute in modules/tome_static/src/Commands/StaticExportPathCommand.php

File

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

Class

StaticCommand
Contains the tome:static command.

Namespace

Drupal\tome_static\Commands

Code

protected function execute(InputInterface $input, OutputInterface $output) {
  $options = $input
    ->getOptions();
  if ($this->state
    ->get(StaticGeneratorInterface::STATE_KEY_BUILDING, FALSE)) {
    if (!$options['yes'] && !$this
      ->io()
      ->confirm('Another user may be running a static build, proceed only if the last build failed unexpectedly. Ignore and continue build?', FALSE)) {
      return 0;
    }
  }
  $this->state
    ->set(StaticGeneratorInterface::STATE_KEY_BUILDING, TRUE);
  $warnings = $this
    ->getWarnings();
  if (empty($options['uri']) || $options['uri'] === 'http://default') {
    $warnings[] = 'No "--uri" option provided. This could lead to invalid absolute URLs. To resolve, pass the "--uri" option.';
  }
  if (!$options['ignore-warnings'] && $warnings) {
    $warnings[] = 'To suppress these messages, pass the --ignore-warnings option.';
    $this->io
      ->comment($warnings);
  }

  // @todo Is this a Drush bug?
  if (base_path() !== '/') {
    \Drupal::urlGenerator()
      ->getContext()
      ->setBaseUrl(rtrim(base_path(), '/'));
  }
  $this->static
    ->cleanupStaticDirectory();
  $this->static
    ->prepareStaticDirectory();
  $paths = $this->static
    ->getPaths();

  // Add a filter to export only pattern based paths.
  if ($options['path-pattern'] !== '') {
    $paths = preg_filter($options['path-pattern'], '$0', $paths);
  }
  $this->io
    ->writeln('Generating static HTML...');
  $this
    ->exportPaths($paths, [], $options['process-count'], $options['path-count'], TRUE, $options['retry-count'], $options['uri']);
  $this->io
    ->success('Exported static HTML and related assets.');
  $this->state
    ->set(StaticGeneratorInterface::STATE_KEY_BUILDING, FALSE);
  if ($options['run-server']) {
    $this
      ->runCommand($this->executable . ' tome:preview --port=' . escapeshellarg($options['port']), NULL, NULL);
  }
}