Skip to content

Commit

Permalink
Fix parameter preparation for occ command
Browse files Browse the repository at this point in the history
* Fix for #517

Signed-off-by: Robin Windey <ro.windey@gmail.com>
  • Loading branch information
R0Wi committed Feb 17, 2025
1 parent 6ca2336 commit 275486f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Fetcher/ExAppArchiveFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion lib/Service/AppAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 empty($arg) ? null : escapeshellarg($arg);
}, explode(' ', $command));
$args = array_filter($args, fn ($arg) => $arg !== null);
$args[] = '--no-ansi --no-warnings';
return $this->runOccCommandInternal($args);
}
Expand All @@ -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;
}

Expand Down

0 comments on commit 275486f

Please sign in to comment.