diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-06-23 15:23:28 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2020-07-15 09:27:57 +0200 |
commit | 81e559313325777649e640492cba1981aff3e54a (patch) | |
tree | 3a200debadabdc6ddb07b90699e0fb34f0e94603 /lib/private/AppFramework | |
parent | 86a7d1641aa85c83aab3b0bc22a84442d3ce3b26 (diff) | |
download | nextcloud-server-81e559313325777649e640492cba1981aff3e54a.tar.gz nextcloud-server-81e559313325777649e640492cba1981aff3e54a.zip |
Move to lazy panel registration during registration context
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/private/AppFramework')
-rw-r--r-- | lib/private/AppFramework/Bootstrap/Coordinator.php | 7 | ||||
-rw-r--r-- | lib/private/AppFramework/Bootstrap/RegistrationContext.php | 35 |
2 files changed, 42 insertions, 0 deletions
diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php index 3edc0f97472..358e71d7854 100644 --- a/lib/private/AppFramework/Bootstrap/Coordinator.php +++ b/lib/private/AppFramework/Bootstrap/Coordinator.php @@ -30,6 +30,7 @@ use OC_App; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\QueryException; +use OCP\Dashboard\IManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\ILogger; use OCP\IServerContainer; @@ -47,6 +48,9 @@ class Coordinator { /** @var Registry */ private $registry; + /** @var IManager */ + private $dashboardManager; + /** @var IEventDispatcher */ private $eventDispatcher; @@ -58,10 +62,12 @@ class Coordinator { public function __construct(IServerContainer $container, Registry $registry, + IManager $dashboardManager, IEventDispatcher $eventListener, ILogger $logger) { $this->serverContainer = $container; $this->registry = $registry; + $this->dashboardManager = $dashboardManager; $this->eventDispatcher = $eventListener; $this->logger = $logger; } @@ -117,6 +123,7 @@ class Coordinator { */ $this->registrationContext->delegateCapabilityRegistrations($apps); $this->registrationContext->delegateCrashReporterRegistrations($apps, $this->registry); + $this->registrationContext->delegateDashboardPanelRegistrations($apps, $this->dashboardManager); $this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher); $this->registrationContext->delegateContainerRegistrations($apps); $this->registrationContext->delegateMiddlewareRegistrations($apps); diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index 15b1cfa51e8..270035a2908 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -29,6 +29,7 @@ use Closure; use OC\Support\CrashReport\Registry; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\Dashboard\IManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\ILogger; use Throwable; @@ -42,6 +43,9 @@ class RegistrationContext { private $crashReporters = []; /** @var array[] */ + private $dashboardPanels = []; + + /** @var array[] */ private $services = []; /** @var array[] */ @@ -93,6 +97,13 @@ class RegistrationContext { ); } + public function registerDashboardPanel(string $panelClass): void { + $this->context->registerDashboardPanel( + $this->appId, + $panelClass + ); + } + public function registerService(string $name, callable $factory, bool $shared = true): void { $this->context->registerService( $this->appId, @@ -157,6 +168,13 @@ class RegistrationContext { ]; } + public function registerDashboardPanel(string $appId, string $panelClass): void { + $this->dashboardPanels[] = [ + 'appId' => $appId, + 'class' => $panelClass + ]; + } + public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void { $this->services[] = [ "appId" => $appId, @@ -241,6 +259,23 @@ class RegistrationContext { } } + /** + * @param App[] $apps + */ + public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void { + foreach ($this->dashboardPanels as $panel) { + try { + $dashboardManager->lazyRegisterPanel($panel['class']); + } catch (Throwable $e) { + $appId = $panel['appId']; + $this->logger->logException($e, [ + 'message' => "Error during dashboard registration of $appId: " . $e->getMessage(), + 'level' => ILogger::ERROR, + ]); + } + } + } + public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { foreach ($this->eventListeners as $registration) { try { |