Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
89.47% |
17 / 19 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Logview | |
89.47% |
17 / 19 |
|
50.00% |
1 / 2 |
4.02 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
88.89% |
16 / 18 |
|
0.00% |
0 / 1 |
3.01 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Controller\System; |
| 6 | |
| 7 | use App\Controller\BaseController; |
| 8 | use App\Service\DeployLogParser; |
| 9 | use Symfony\Bundle\FrameworkBundle\Console\Application; |
| 10 | use Symfony\Component\Console\Input\ArrayInput; |
| 11 | use Symfony\Component\Console\Output\BufferedOutput; |
| 12 | use Symfony\Component\DependencyInjection\Attribute\Autowire; |
| 13 | use Symfony\Component\Filesystem\Exception\IOException; |
| 14 | use Symfony\Component\Filesystem\Filesystem; |
| 15 | use Symfony\Component\HttpFoundation\Response; |
| 16 | use Symfony\Component\HttpKernel\KernelInterface; |
| 17 | use Symfony\Component\Routing\Attribute\Route; |
| 18 | use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 19 | |
| 20 | #[Route('/system/logview', name: 'system_logview', methods: ['GET'])] |
| 21 | #[IsGranted('ROLE_ADMIN')] |
| 22 | class Logview extends BaseController |
| 23 | { |
| 24 | public function __construct( |
| 25 | private readonly KernelInterface $kernel, |
| 26 | private readonly DeployLogParser $logParser, |
| 27 | ) {} |
| 28 | |
| 29 | public function __invoke( |
| 30 | #[Autowire('%kernel.project_dir%')] string $projectDir |
| 31 | ): Response { |
| 32 | $filesystem = new Filesystem(); |
| 33 | $filename = $projectDir.'/var/log/deploy.log'; |
| 34 | $entries = []; |
| 35 | $error = ''; |
| 36 | |
| 37 | try { |
| 38 | if ($filesystem->exists($filename)) { |
| 39 | $entries = $this->logParser->parse($filesystem->readFile($filename)); |
| 40 | } else { |
| 41 | $error = 'No log file found!'; |
| 42 | } |
| 43 | } catch (IOException $ioException) { |
| 44 | $this->addFlash('danger', $ioException->getMessage()); |
| 45 | } |
| 46 | |
| 47 | $output = new BufferedOutput(); |
| 48 | |
| 49 | $application = new Application($this->kernel); |
| 50 | $application->setAutoExit(false); |
| 51 | $application->run(new ArrayInput(['command' => 'about']), $output); |
| 52 | |
| 53 | return $this->render('system/logview.html.twig', [ |
| 54 | 'project_dir' => $projectDir, |
| 55 | 'logEntries' => array_reverse($entries), |
| 56 | 'error' => $error, |
| 57 | ]); |
| 58 | } |
| 59 | } |