Skip to content

Commit 41d8fc4

Browse files
authored
Merge pull request #525 from nextcloud/backport/518/stable31
[stable31] Fix parameter preparation for occ command
2 parents 6ca2336 + 517333f commit 41d8fc4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/Fetcher/ExAppArchiveFetcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function getExAppFolder(string $appId): ?string {
116116
}
117117

118118
public function removeExAppFolder(string $appId): void {
119-
foreach ($this->config->getSystemValue('apps_paths') as $appPath) {
119+
foreach ($this->config->getSystemValue('apps_paths', []) as $appPath) {
120120
if ($appPath['writable']) {
121121
if (file_exists($appPath['path'] . '/' . $appId)) {
122122
$this->rmdirr($appPath['path'] . '/' . $appId);

lib/Service/AppAPIService.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)