From 85d79349cff0257d700a29b055c267a1da23ccc6 Mon Sep 17 00:00:00 2001 From: Robin Windey Date: Mon, 17 Feb 2025 20:36:56 +0000 Subject: [PATCH] Fix parameter preparation for occ command * Fix for #517 Signed-off-by: Robin Windey --- lib/Fetcher/ExAppArchiveFetcher.php | 2 +- lib/Service/AppAPIService.php | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/Fetcher/ExAppArchiveFetcher.php b/lib/Fetcher/ExAppArchiveFetcher.php index a5456906..73f89bc1 100644 --- a/lib/Fetcher/ExAppArchiveFetcher.php +++ b/lib/Fetcher/ExAppArchiveFetcher.php @@ -116,7 +116,7 @@ public function getExAppFolder(string $appId): ?string { } public function removeExAppFolder(string $appId): void { - foreach ($this->config->getSystemValue('apps_paths') as $appPath) { + foreach ($this->config->getSystemValue('apps_paths', []) as $appPath) { if ($appPath['writable']) { if (file_exists($appPath['path'] . '/' . $appId)) { $this->rmdirr($appPath['path'] . '/' . $appId); diff --git a/lib/Service/AppAPIService.php b/lib/Service/AppAPIService.php index c92d5a32..fc2b9b85 100644 --- a/lib/Service/AppAPIService.php +++ b/lib/Service/AppAPIService.php @@ -428,8 +428,9 @@ public function dispatchExAppInitInternal(ExApp $exApp): void { */ public function runOccCommand(string $command): bool { $args = array_map(function ($arg) { - return escapeshellarg($arg); + return $arg === '' ? null : escapeshellarg($arg); }, explode(' ', $command)); + $args = array_filter($args, fn ($arg) => $arg !== null); $args[] = '--no-ansi --no-warnings'; return $this->runOccCommandInternal($args); } @@ -447,13 +448,28 @@ public function runOccCommandInternal(array $args): bool { } $this->logger->info(sprintf('Calling occ(directory=%s): %s', $occDirectory ?? 'null', $args)); $process = proc_open('php console.php ' . $args, $descriptors, $pipes, $occDirectory); + if (!is_resource($process)) { $this->logger->error(sprintf('Error calling occ(directory=%s): %s', $occDirectory ?? 'null', $args)); return false; } + + $stdout = stream_get_contents($pipes[1]); + $stderr = stream_get_contents($pipes[2]); + fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); + + $returnCode = proc_close($process); + + if ($returnCode !== 0) { + $this->logger->error(sprintf('Error executing occ command. Return code: %d, stdout: %s, stderr: %s', $returnCode, $stdout, $stderr)); + return false; + } + + $this->logger->info(sprintf('OCC command executed successfully. stdout: %s, stderr: %s', $stdout, $stderr)); + return true; }