Skip to content

Fix parameter preparation for occ command #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 $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