Fix parameter preparation for occ command

* Fix for #517

Signed-off-by: Robin Windey <ro.windey@gmail.com>
This commit is contained in:
Robin Windey
2025-02-17 20:36:56 +00:00
parent 30281c199f
commit 85d79349cf
2 changed files with 18 additions and 2 deletions

View File

@ -116,7 +116,7 @@ class ExAppArchiveFetcher {
}
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);

View File

@ -428,8 +428,9 @@ class AppAPIService {
*/
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 @@ class AppAPIService {
}
$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;
}