1515
1616use CleverAge \UiProcessBundle \Admin \Field \EnumField ;
1717use CleverAge \UiProcessBundle \Entity \ProcessExecution ;
18+ use CleverAge \UiProcessBundle \Repository \ProcessExecutionRepository ;
1819use EasyCorp \Bundle \EasyAdminBundle \Config \Action ;
1920use EasyCorp \Bundle \EasyAdminBundle \Config \Actions ;
2021use EasyCorp \Bundle \EasyAdminBundle \Config \Crud ;
3334#[IsGranted('ROLE_USER ' )]
3435class ProcessExecutionCrudController extends AbstractCrudController
3536{
37+ public function __construct (
38+ private readonly ProcessExecutionRepository $ processExecutionRepository ,
39+ private readonly string $ logDirectory ,
40+ ) {
41+ }
42+
3643 public static function getEntityFqcn (): string
3744 {
3845 return ProcessExecution::class;
@@ -77,6 +84,7 @@ public function configureActions(Actions $actions): Actions
7784 ]
7885 )
7986 ->linkToCrudAction ('showLogs ' )
87+ ->displayIf (fn (ProcessExecution $ entity ) => $ this ->processExecutionRepository ->hasLogs ($ entity ))
8088 )->add (
8189 Crud::PAGE_INDEX ,
8290 Action::new ('downloadLogfile ' , false , 'fas fa-download ' )
@@ -88,6 +96,7 @@ public function configureActions(Actions $actions): Actions
8896 ]
8997 )
9098 ->linkToCrudAction ('downloadLogFile ' )
99+ ->displayIf (fn (ProcessExecution $ entity ) => file_exists ($ this ->getLogFilePath ($ entity )))
91100 );
92101 }
93102
@@ -115,12 +124,10 @@ public function showLogs(AdminContext $adminContext): RedirectResponse
115124
116125 public function downloadLogFile (
117126 AdminContext $ context ,
118- string $ logDirectory ,
119127 ): Response {
120128 /** @var ProcessExecution $processExecution */
121129 $ processExecution = $ context ->getEntity ()->getInstance ();
122- $ filepath = $ logDirectory .\DIRECTORY_SEPARATOR .$ processExecution ->code .\DIRECTORY_SEPARATOR
123- .$ processExecution ->logFilename ;
130+ $ filepath = $ this ->getLogFilePath ($ processExecution );
124131 $ basename = basename ($ filepath );
125132 $ content = file_get_contents ($ filepath );
126133 if (false === $ content ) {
@@ -137,4 +144,12 @@ public function configureFilters(Filters $filters): Filters
137144 {
138145 return $ filters ->add ('code ' )->add ('startDate ' );
139146 }
147+
148+ private function getLogFilePath (ProcessExecution $ processExecution ): string
149+ {
150+ return $ this ->logDirectory .
151+ \DIRECTORY_SEPARATOR .$ processExecution ->code .
152+ \DIRECTORY_SEPARATOR .$ processExecution ->logFilename
153+ ;
154+ }
140155}
0 commit comments