-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: add helper method for settings to provide initial state
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
- Loading branch information
1 parent
bbb1268
commit e57895a
Showing
3 changed files
with
73 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\AppAPI\Service; | ||
|
||
use OCA\AppAPI\DeployActions\DockerActions; | ||
use OCA\AppAPI\Fetcher\ExAppFetcher; | ||
use OCP\App\IAppManager; | ||
use OCP\AppFramework\Services\IInitialState; | ||
use OCP\IConfig; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class ExAppsPageService { | ||
|
||
public function __construct( | ||
private readonly ExAppFetcher $exAppFetcher, | ||
private readonly DaemonConfigService $daemonConfigService, | ||
private readonly DockerActions $dockerActions, | ||
private readonly IConfig $config, | ||
private readonly IAppManager $appManager, | ||
private readonly LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
/** | ||
* Helper method for settings app to provide initial state for Apps management UI | ||
* | ||
* @since 30.0.2 | ||
*/ | ||
public function provideAppApiState(IInitialState $initialState): void { | ||
$appApiEnabled = $this->appManager->isInstalled('app_api'); | ||
$initialState->provideInitialState('appApiEnabled', $appApiEnabled); | ||
$daemonConfigAccessible = false; | ||
$defaultDaemonConfig = null; | ||
|
||
if ($appApiEnabled) { | ||
$initialState->provideInitialState('appstoreExAppUpdateCount', count($this->exAppFetcher->getExAppsWithUpdates())); | ||
|
||
$defaultDaemonConfigName = $this->config->getAppValue('app_api', 'default_daemon_config'); | ||
if ($defaultDaemonConfigName !== '') { | ||
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($defaultDaemonConfigName); | ||
if ($daemonConfig !== null) { | ||
$defaultDaemonConfig = $daemonConfig->jsonSerialize(); | ||
unset($defaultDaemonConfig['deploy_config']['haproxy_password']); | ||
$this->dockerActions->initGuzzleClient($daemonConfig); | ||
$daemonConfigAccessible = $this->dockerActions->ping($this->dockerActions->buildDockerUrl($daemonConfig)); | ||
if (!$daemonConfigAccessible) { | ||
$this->logger->warning(sprintf('Deploy daemon "%s" is not accessible by Nextcloud. Please verify its configuration', $daemonConfig->getName())); | ||
} | ||
} | ||
} | ||
} | ||
|
||
$initialState->provideInitialState('defaultDaemonConfigAccessible', $daemonConfigAccessible); | ||
$initialState->provideInitialState('defaultDaemonConfig', $defaultDaemonConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters