You are here

private function ExportCommand::exportAll in Devel 4.x

Same name and namespace in other branches
  1. 8.3 webprofiler/src/Command/ExportCommand.php \Drupal\webprofiler\Command\ExportCommand::exportAll()
  2. 8 webprofiler/src/Command/ExportCommand.php \Drupal\webprofiler\Command\ExportCommand::exportAll()
  3. 8.2 webprofiler/src/Command/ExportCommand.php \Drupal\webprofiler\Command\ExportCommand::exportAll()

Exports all stored profiles (cap limit at 1000 items).

Parameters

\Drupal\webprofiler\Profiler\Profiler $profiler:

string $directory:

\Symfony\Component\Console\Output\OutputInterface $output:

Return value

string

1 call to ExportCommand::exportAll()
ExportCommand::execute in webprofiler/src/Command/ExportCommand.php

File

webprofiler/src/Command/ExportCommand.php, line 109

Class

ExportCommand
Class ExportCommand.

Namespace

Drupal\webprofiler\Command

Code

private function exportAll(Profiler $profiler, $directory, $output) {
  $filename = $directory . DIRECTORY_SEPARATOR . 'profiles_' . time() . '.tar.gz';
  $archiver = new ArchiveTar($filename, 'gz');
  $profiles = $profiler
    ->find(NULL, NULL, 1000, NULL, '', '');
  $progress = new ProgressBar($output, count($profiles) + 2);
  $progress
    ->setFormat(' %current%/%max% [%bar%] %percent:3s%% %message%');
  $files = [];
  $progress
    ->start();
  $progress
    ->setMessage($this
    ->trans('commands.webprofiler.export.progress.exporting'));
  foreach ($profiles as $profile) {
    $data = $profiler
      ->export($profiler
      ->loadProfile($profile['token']));
    $profileFilename = $directory . "/{$profile['token']}.txt";
    file_put_contents($profileFilename, $data);
    $files[] = $profileFilename;
    $progress
      ->advance();
  }
  $progress
    ->setMessage($this
    ->trans('commands.webprofiler.export.progress.archive'));
  $archiver
    ->createModify($files, '', $directory);
  $progress
    ->advance();
  $progress
    ->setMessage($this
    ->trans('commands.webprofiler.export.progress.delete_tmp'));
  foreach ($files as $file) {
    unlink($file);
  }
  $progress
    ->advance();
  $progress
    ->setMessage($this
    ->trans('commands.webprofiler.export.progress.done'));
  $progress
    ->finish();
  $output
    ->writeln('');
  $output
    ->writeln(sprintf($this
    ->trans('commands.webprofiler.export.messages.exported_count'), count($profiles)));
  return $filename;
}