Skip to content
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
22 changes: 17 additions & 5 deletions lib/Controller/DaemonConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,16 @@ public function startTestDeploy(string $name): Response {
return new JSONResponse(['error' => $this->l10n->t('Daemon config not found')], Http::STATUS_NOT_FOUND);
}

if (!$this->service->runOccCommand(
sprintf("app_api:app:register --silent %s %s --info-xml %s --test-deploy-mode",
Application::TEST_DEPLOY_APPID, $daemonConfig->getName(), Application::TEST_DEPLOY_INFO_XML)
)) {
$commandParts = [
'app_api:app:register',
'--silent',
Application::TEST_DEPLOY_APPID,
$daemonConfig->getName(),
'--info-xml',
Application::TEST_DEPLOY_INFO_XML,
'--test-deploy-mode',
];
if (!$this->service->runOccCommand($commandParts)) {
return new JSONResponse(['error' => $this->l10n->t('Error starting install of ExApp')], Http::STATUS_INTERNAL_SERVER_ERROR);
}

Expand All @@ -199,7 +205,13 @@ public function startTestDeploy(string $name): Response {
public function stopTestDeploy(string $name): Response {
$exApp = $this->exAppService->getExApp(Application::TEST_DEPLOY_APPID);
if ($exApp !== null) {
$this->service->runOccCommand(sprintf("app_api:app:unregister --silent --force %s", Application::TEST_DEPLOY_APPID));
$commandParts = [
'app_api:app:unregister',
'--silent',
'--force',
Application::TEST_DEPLOY_APPID,
];
$this->service->runOccCommand($commandParts);
$elapsedTime = 0;
while ($elapsedTime < 5000000 && $this->exAppService->getExApp(Application::TEST_DEPLOY_APPID) !== null) {
usleep(150000); // 0.15
Expand Down
30 changes: 22 additions & 8 deletions lib/Controller/ExAppsPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,23 +320,32 @@ public function enableApp(string $appId, array $deployOptions = []): JSONRespons

$envOptions = isset($deployOptions['environment_variables'])
? array_keys($deployOptions['environment_variables']) : [];
$envOptionsString = '';
$envArgs = [];
foreach ($envOptions as $envOption) {
$envOptionsString .= sprintf(' --env %s=%s', $envOption, $deployOptions['environment_variables'][$envOption]);
$envArgs[] = '--env';
$envArgs[] = sprintf('%s=%s', $envOption, $deployOptions['environment_variables'][$envOption]);
}
$envOptionsString = trim($envOptionsString);

$mountOptions = $deployOptions['mounts'] ?? [];
$mountOptionsString = '';
$mountArgs = [];
foreach ($mountOptions as $mountOption) {
$readonlyModifier = $mountOption['readonly'] ? 'ro' : 'rw';
$mountOptionsString .= sprintf(' --mount %s:%s:%s', $mountOption['hostPath'], $mountOption['containerPath'], $readonlyModifier);
$mountArgs[] = '--mount';
$mountArgs[] = sprintf('%s:%s:%s', $mountOption['hostPath'], $mountOption['containerPath'], $readonlyModifier);
}
$mountOptionsString = trim($mountOptionsString);

// If ExApp is not registered - then it's a "Deploy and Enable" action.
if (!$exApp) {
if (!$this->service->runOccCommand(sprintf("app_api:app:register --silent %s %s %s", $appId, $envOptionsString, $mountOptionsString))) {
$commandParts = array_merge(
[
'app_api:app:register',
'--silent',
$appId,
],
$envArgs,
$mountArgs
);
if (!$this->service->runOccCommand($commandParts)) {
return new JSONResponse(['data' => ['message' => $this->l10n->t('Error starting install of ExApp')]], Http::STATUS_INTERNAL_SERVER_ERROR);
}
$elapsedTime = 0;
Expand Down Expand Up @@ -394,7 +403,12 @@ public function updateApp(string $appId): JSONResponse {
}

$exAppOldVersion = $this->exAppService->getExApp($appId)->getVersion();
if (!$this->service->runOccCommand(sprintf("app_api:app:update --silent %s", $appId))) {
$commandParts = [
'app_api:app:update',
'--silent',
$appId,
];
if (!$this->service->runOccCommand($commandParts)) {
return new JSONResponse(['data' => ['message' => $this->l10n->t('Error starting update of ExApp')]], Http::STATUS_INTERNAL_SERVER_ERROR);
}

Expand Down
13 changes: 6 additions & 7 deletions lib/Service/AppAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,16 @@ public function dispatchExAppInitInternal(ExApp $exApp): void {
/**
* Dispatch ExApp initialization step, that may take a long time to display the progress of initialization.
*/
public function runOccCommand(string $command): bool {
$args = array_map(function ($arg) {
return $arg === '' ? null : escapeshellarg($arg);
}, explode(' ', $command));
$args = array_filter($args, fn ($arg) => $arg !== null);
$args[] = '--no-ansi --no-warnings';
public function runOccCommand(array $commandParts): bool {
$args = array_filter($commandParts, static fn ($part) => $part !== null);
$args[] = '--no-ansi';
$args[] = '--no-warnings';
return $this->runOccCommandInternal($args);
}

public function runOccCommandInternal(array $args): bool {
$args = implode(' ', $args);
$escapedArgs = array_map('escapeshellarg', $args);
$args = implode(' ', $escapedArgs);
$descriptors = [
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
Expand Down