aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Dashboard
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-06-23 15:23:28 +0200
committerJulius Härtl <jus@bitgrid.net>2020-07-15 09:27:57 +0200
commit81e559313325777649e640492cba1981aff3e54a (patch)
tree3a200debadabdc6ddb07b90699e0fb34f0e94603 /lib/private/Dashboard
parent86a7d1641aa85c83aab3b0bc22a84442d3ce3b26 (diff)
downloadnextcloud-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/Dashboard')
-rw-r--r--lib/private/Dashboard/Manager.php55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/private/Dashboard/Manager.php b/lib/private/Dashboard/Manager.php
index 99d8999c24a..0d149dc9a13 100644
--- a/lib/private/Dashboard/Manager.php
+++ b/lib/private/Dashboard/Manager.php
@@ -23,12 +23,26 @@
namespace OC\Dashboard;
+use OCP\AppFramework\QueryException;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IPanel;
+use OCP\IServerContainer;
class Manager implements IManager {
+
+ /** @var array */
+ private $lazyPanels = [];
+
+ /** @var IPanel[] */
private $panels = [];
+ /** @var IServerContainer */
+ private $serverContainer;
+
+ public function __construct(IServerContainer $serverContainer) {
+ $this->serverContainer = $serverContainer;
+ }
+
/**
* @inheritDoc
*/
@@ -40,7 +54,48 @@ class Manager implements IManager {
$this->panels[$panel->getId()] = $panel;
}
+ public function lazyRegisterPanel(string $panelClass): void {
+ $this->lazyPanels[] = $panelClass;
+ }
+
+ public function loadLazyPanels(): void {
+ $classes = $this->lazyPanels;
+ foreach ($classes as $class) {
+ try {
+ /** @var IPanel $panel */
+ $panel = $this->serverContainer->query($class);
+ } catch (QueryException $e) {
+ /*
+ * There is a circular dependency between the logger and the registry, so
+ * we can not inject it. Thus the static call.
+ */
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => 'Could not load lazy dashbaord panel: ' . $e->getMessage(),
+ 'level' => ILogger::FATAL,
+ ]);
+ }
+ /**
+ * Try to register the loaded reporter. Theoretically it could be of a wrong
+ * type, so we might get a TypeError here that we should catch.
+ */
+ try {
+ $this->registerPanel($panel);
+ } catch (Throwable $e) {
+ /*
+ * There is a circular dependency between the logger and the registry, so
+ * we can not inject it. Thus the static call.
+ */
+ \OC::$server->getLogger()->logException($e, [
+ 'message' => 'Could not register lazy crash reporter: ' . $e->getMessage(),
+ 'level' => ILogger::FATAL,
+ ]);
+ }
+ }
+ $this->lazyPanels = [];
+ }
+
public function getPanels(): array {
+ $this->loadLazyPanels();
return $this->panels;
}
}