Skip to content

Commit

Permalink
fix(occ): correct app_api:app:update enabled state of ExApps, intro…
Browse files Browse the repository at this point in the history
…duce helper options (#478)

Resolves: #474 

This PR corrects AppAPI `occ app_api:app:update` command logic in the
following way:

1. By default disabled ExApps are not updated. Use option
`--include-disabled` to update disabled ExApps too.
2. During update ExApp is enabled to perform initialization step, if it
was disabled before update - by default it will be disabled after
update.

---------

Signed-off-by: Andrey Borysenko <[email protected]>
  • Loading branch information
andrey18106 authored Dec 27, 2024
1 parent fe0b180 commit 217a6f9
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/Command/ExApp/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ protected function configure(): void {
$this->addOption('force-scopes', null, InputOption::VALUE_NONE, 'Force new ExApp scopes approval[deprecated]');
$this->addOption('wait-finish', null, InputOption::VALUE_NONE, 'Wait until finish');
$this->addOption('silent', null, InputOption::VALUE_NONE, 'Do not print to console');
$this->addOption('all', null, InputOption::VALUE_NONE, 'Update all updatable apps');
$this->addOption('all', null, InputOption::VALUE_NONE, 'Updates all enabled and updatable apps');
$this->addOption('showonly', null, InputOption::VALUE_NONE, 'Additional flag for "--all" to only show all updatable apps');
$this->addOption('include-disabled', null, InputOption::VALUE_NONE, 'Additional flag for "--all" to also update disabled apps');
}

protected function execute(InputInterface $input, OutputInterface $output): int {
Expand Down Expand Up @@ -110,6 +111,15 @@ private function updateExApp(InputInterface $input, OutputInterface $output, str
return 1;
}

$includeDisabledApps = $input->getOption('include-disabled');
if ($input->getOption('all') && !$exApp->getEnabled() && !$includeDisabledApps) {
$this->logger->info(sprintf('ExApp %s is disabled. Update skipped (use --include-disabled to update disabled apps).', $appId));
if ($outputConsole) {
$output->writeln(sprintf('ExApp %s is disabled. Update skipped (use --include-disabled to update disabled apps).', $appId));
}
return 0;
}

$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($exApp->getDaemonConfigName());
if ($daemonConfig === null) {
$this->logger->error(sprintf('Daemon config %s not found.', $exApp->getDaemonConfigName()));
Expand Down Expand Up @@ -145,7 +155,8 @@ private function updateExApp(InputInterface $input, OutputInterface $output, str
$exApp->setStatus($status);
$this->exAppService->updateExApp($exApp, ['status']);

if ($exApp->getEnabled()) {
$wasEnabled = $exApp->getEnabled();
if ($wasEnabled) {
if ($this->service->disableExApp($exApp)) {
$this->logger->info(sprintf('ExApp %s successfully disabled.', $appId));
if ($outputConsole) {
Expand Down Expand Up @@ -253,6 +264,19 @@ private function updateExApp(InputInterface $input, OutputInterface $output, str
if ($outputConsole) {
$output->writeln(sprintf('ExApp %s successfully updated.', $appId));
}

if ($includeDisabledApps) {
$exApp = $this->exAppService->getExApp($appId);
if (!$wasEnabled && $exApp->getEnabled()) {
if ($this->service->disableExApp($exApp)) {
$this->logger->info(sprintf('ExApp %s successfully disabled after update.', $appId));
if ($outputConsole) {
$output->writeln(sprintf('ExApp %s successfully disabled after update.', $appId));
}
}
}
}

return 0;
}
}

0 comments on commit 217a6f9

Please sign in to comment.