diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2020-10-03 15:47:38 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2020-10-04 09:35:33 +0200 |
commit | f865a3a1c2405af5c649b6d78f95b93ed60ba04f (patch) | |
tree | c7194750f2c4c88be23b0cd4ec508a59d8b61d0b /lib/private/InitialStateService.php | |
parent | eba83d22bbcf45caf400704b8794acce180c5ba9 (diff) | |
download | nextcloud-server-f865a3a1c2405af5c649b6d78f95b93ed60ba04f.tar.gz nextcloud-server-f865a3a1c2405af5c649b6d78f95b93ed60ba04f.zip |
Move initial state provider to boostrap
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/InitialStateService.php')
-rw-r--r-- | lib/private/InitialStateService.php | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/lib/private/InitialStateService.php b/lib/private/InitialStateService.php index c74eb683bd9..76e64d8b013 100644 --- a/lib/private/InitialStateService.php +++ b/lib/private/InitialStateService.php @@ -28,8 +28,12 @@ declare(strict_types=1); namespace OC; use Closure; +use OC\AppFramework\Bootstrap\Coordinator; +use OCP\AppFramework\QueryException; +use OCP\AppFramework\Services\InitialStateProvider; use OCP\IInitialStateService; use OCP\ILogger; +use OCP\IServerContainer; class InitialStateService implements IInitialStateService { @@ -42,8 +46,16 @@ class InitialStateService implements IInitialStateService { /** @var Closure[][] */ private $lazyStates = []; - public function __construct(ILogger $logger) { + /** @var Coordinator */ + private $bootstrapCoordinator; + + /** @var IServerContainer */ + private $container; + + public function __construct(ILogger $logger, Coordinator $bootstrapCoordinator, IServerContainer $container) { $this->logger = $logger; + $this->bootstrapCoordinator = $bootstrapCoordinator; + $this->container = $container; } public function provideInitialState(string $appName, string $key, $data): void { @@ -88,8 +100,45 @@ class InitialStateService implements IInitialStateService { $this->lazyStates = []; } + /** + * Load the lazy states via the IBootstrap mechanism + */ + private function loadLazyStates(): void { + $context = $this->bootstrapCoordinator->getRegistrationContext(); + + if ($context === null) { + // To early, nothing to do yet + return; + } + + $initialStates = $context->getInitialStates(); + foreach ($initialStates as $initialState) { + try { + $provider = $this->container->query($initialState['class']); + } catch (QueryException $e) { + // Log an continue. We can be fault tolerant here. + $this->logger->logException($e, [ + 'message' => 'Could not load initial state provider dynamically: ' . $e->getMessage(), + 'level' => ILogger::ERROR, + 'app' => $initialState['appId'], + ]); + continue; + } + + if (!($provider instanceof InitialStateProvider)) { + // Log an continue. We can be fault tolerant here. + $this->logger->error('Initial state provider is not an InitialStateProvider instance: ' . $initialState['class'], [ + 'app' => $initialState['appId'], + ]); + } + + $this->provideInitialState($initialState['appId'], $provider->getKey(), $provider); + } + } + public function getInitialStates(): array { $this->invokeLazyStateCallbacks(); + $this->loadLazyStates(); $appStates = []; foreach ($this->states as $app => $states) { |