@@ -428,8 +428,9 @@ public function dispatchExAppInitInternal(ExApp $exApp): void {
428428 */
429429 public function runOccCommand (string $ command ): bool {
430430 $ args = array_map (function ($ arg ) {
431- return escapeshellarg ($ arg );
431+ return $ arg === '' ? null : escapeshellarg ($ arg );
432432 }, explode (' ' , $ command ));
433+ $ args = array_filter ($ args , fn ($ arg ) => $ arg !== null );
433434 $ args [] = '--no-ansi --no-warnings ' ;
434435 return $ this ->runOccCommandInternal ($ args );
435436 }
@@ -447,13 +448,28 @@ public function runOccCommandInternal(array $args): bool {
447448 }
448449 $ this ->logger ->info (sprintf ('Calling occ(directory=%s): %s ' , $ occDirectory ?? 'null ' , $ args ));
449450 $ process = proc_open ('php console.php ' . $ args , $ descriptors , $ pipes , $ occDirectory );
451+
450452 if (!is_resource ($ process )) {
451453 $ this ->logger ->error (sprintf ('Error calling occ(directory=%s): %s ' , $ occDirectory ?? 'null ' , $ args ));
452454 return false ;
453455 }
456+
457+ $ stdout = stream_get_contents ($ pipes [1 ]);
458+ $ stderr = stream_get_contents ($ pipes [2 ]);
459+
454460 fclose ($ pipes [0 ]);
455461 fclose ($ pipes [1 ]);
456462 fclose ($ pipes [2 ]);
463+
464+ $ returnCode = proc_close ($ process );
465+
466+ if ($ returnCode !== 0 ) {
467+ $ this ->logger ->error (sprintf ('Error executing occ command. Return code: %d, stdout: %s, stderr: %s ' , $ returnCode , $ stdout , $ stderr ));
468+ return false ;
469+ }
470+
471+ $ this ->logger ->info (sprintf ('OCC command executed successfully. stdout: %s, stderr: %s ' , $ stdout , $ stderr ));
472+
457473 return true ;
458474 }
459475
0 commit comments