Beispiel #1
0
 /**
  * Exports all stored profiles (cap limit at 1000 items).
  *
  * @param \Drupal\webprofiler\Profiler\Profiler $profiler
  * @param string $directory
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return string
  */
 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;
 }