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+
38+ public function __construct (
39+ private readonly ProcessExecutionRepository $ processExecutionRepository ,
40+ private readonly string $ logDirectory ,
41+ ) {
42+
43+ }
44+
3645 public static function getEntityFqcn (): string
3746 {
3847 return ProcessExecution::class;
@@ -65,6 +74,8 @@ public function configureCrud(Crud $crud): Crud
6574
6675 public function configureActions (Actions $ actions ): Actions
6776 {
77+ $ processExecutionRepository = $ this ->processExecutionRepository ;
78+
6879 return Actions::new ()
6980 ->add (
7081 Crud::PAGE_INDEX ,
@@ -77,6 +88,9 @@ public function configureActions(Actions $actions): Actions
7788 ]
7889 )
7990 ->linkToCrudAction ('showLogs ' )
91+ ->displayIf (function (ProcessExecution $ entity ) {
92+ return $ this ->processExecutionRepository ->hasLogs ($ entity );
93+ })
8094 )->add (
8195 Crud::PAGE_INDEX ,
8296 Action::new ('downloadLogfile ' , false , 'fas fa-download ' )
@@ -88,6 +102,9 @@ public function configureActions(Actions $actions): Actions
88102 ]
89103 )
90104 ->linkToCrudAction ('downloadLogFile ' )
105+ ->displayIf (function (ProcessExecution $ entity ) {
106+ return file_exists ($ this ->getLogFilePath ($ entity ));
107+ })
91108 );
92109 }
93110
@@ -115,12 +132,10 @@ public function showLogs(AdminContext $adminContext): RedirectResponse
115132
116133 public function downloadLogFile (
117134 AdminContext $ context ,
118- string $ logDirectory ,
119135 ): Response {
120136 /** @var ProcessExecution $processExecution */
121137 $ processExecution = $ context ->getEntity ()->getInstance ();
122- $ filepath = $ logDirectory .\DIRECTORY_SEPARATOR .$ processExecution ->code .\DIRECTORY_SEPARATOR
123- .$ processExecution ->logFilename ;
138+ $ filepath = $ this ->getLogFilePath ($ processExecution );
124139 $ basename = basename ($ filepath );
125140 $ content = file_get_contents ($ filepath );
126141 if (false === $ content ) {
@@ -137,4 +152,12 @@ public function configureFilters(Filters $filters): Filters
137152 {
138153 return $ filters ->add ('code ' )->add ('startDate ' );
139154 }
155+
156+ private function getLogFilePath (ProcessExecution $ processExecution ): string
157+ {
158+ return $ this ->logDirectory .
159+ \DIRECTORY_SEPARATOR .$ processExecution ->code .
160+ \DIRECTORY_SEPARATOR .$ processExecution ->logFilename
161+ ;
162+ }
140163}
0 commit comments