@@ -45,9 +45,23 @@ public function displayLog(int $id): Response
4545 $ log = array_map (fn ($ line ) => preg_replace ('~#\d+~ ' , "\n$0 " , (string ) $ line ), $ item ->getExceptions () ?? []);
4646
4747 if (empty ($ log ) && $ item ->getStreamExceptions ()) {
48- return new StreamedResponse (function () use ($ item ) {
48+ return new StreamedResponse (function () use ($ item , $ id ) {
49+ $ maxBytes = 1048576 ;
50+ $ bytesRead = 0 ;
51+
4952 while (($ line = fgets ($ item ->getStreamExceptions ())) !== false ) {
50- echo "<p> " ,preg_replace ('~#\d+~ ' , "<br>$0 " , (string ) $ line ),"</p> " ;
53+ $ bytesRead += strlen ($ line );
54+
55+ if ($ bytesRead > $ maxBytes ) {
56+ echo sprintf ('<p><strong>[%s]</strong></p><p><a href="%s">%s</a></p> ' ,
57+ $ this ->translator ->trans ('coderhapsodie.ibexa_dataflow.logs.trucated ' ),
58+ $ this ->generateUrl ('coderhapsodie.ibexa_dataflow.job.log.download ' , ['id ' => $ id ]),
59+ $ this ->translator ->trans ('coderhapsodie.ibexa_dataflow.logs.download ' )
60+ );
61+ break ;
62+ }
63+
64+ echo "<p> " , preg_replace ('~#\d+~ ' , "<br>$0 " , (string )$ line ), "</p> " ;
5165 flush ();
5266 }
5367 });
@@ -58,6 +72,32 @@ public function displayLog(int $id): Response
5872 ]);
5973 }
6074
75+ #[Route(path: '/details/log/{id}/download ' , name: 'coderhapsodie.ibexa_dataflow.job.log.download ' , methods: 'GET ' )]
76+ public function downloadLog (int $ id ): Response
77+ {
78+ $ this ->denyAccessUnlessGranted (new Attribute ('ibexa_dataflow ' , 'view ' ));
79+ $ item = $ this ->jobGateway ->find ($ id );
80+ $ log = array_map (fn ($ line ) => preg_replace ('~#\d+~ ' , "\n$0 " , (string ) $ line ), $ item ->getExceptions () ?? []);
81+
82+ if (empty ($ log ) && $ item ->getStreamExceptions ()) {
83+ $ headers = [
84+ 'Content-Type ' => 'plain/text; charset=utf-8 ' ,
85+ 'Content-Disposition ' => sprintf ('attachment; filename="%s.log" ' , $ item ->getLabel ().'- ' .$ item ->getStartTime ()->format ('Y-m-d-H-i-s ' )),
86+ ];
87+
88+ return new StreamedResponse (function () use ($ item ) {
89+ while (($ line = fgets ($ item ->getStreamExceptions ())) !== false ) {
90+ echo $ line ;
91+ flush ();
92+ }
93+ }, headers: $ headers );
94+ }
95+
96+ throw $ this ->createNotFoundException ();
97+ }
98+
99+
100+
61101 #[Route(path: '/create ' , name: 'coderhapsodie.ibexa_dataflow.job.create ' , methods: ['POST ' ])]
62102 public function create (Request $ request ): Response
63103 {
0 commit comments