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 | |
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')
-rw-r--r-- | lib/private/AppFramework/Bootstrap/RegistrationContext.php | 24 | ||||
-rw-r--r-- | lib/private/InitialStateService.php | 51 |
2 files changed, 74 insertions, 1 deletions
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index 1ed2dac4c45..0f408380e88 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -69,6 +69,9 @@ class RegistrationContext { /** @var array[] */ private $alternativeLogins = []; + /** @var array[] */ + private $initialStates = []; + /** @var ILogger */ private $logger; @@ -164,6 +167,13 @@ class RegistrationContext { $class ); } + + public function registerInitialStateProvider(string $class): void { + $this->context->registerInitialState( + $this->appId, + $class + ); + } }; } @@ -243,6 +253,13 @@ class RegistrationContext { ]; } + public function registerInitialState(string $appId, string $class): void { + $this->initialStates[] = [ + 'appId' => $appId, + 'class' => $class, + ]; + } + /** * @param App[] $apps */ @@ -413,4 +430,11 @@ class RegistrationContext { public function getAlternativeLogins(): array { return $this->alternativeLogins; } + + /** + * @erturn array[] + */ + public function getInitialStates(): array { + return $this->initialStates; + } } 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) { |