summaryrefslogtreecommitdiffstats
path: root/lib/private/AppFramework
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-11-16 19:41:22 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-11-18 08:48:45 +0100
commit3cf39c573f389ca0d55ee2e7dbfe05a518ef94a3 (patch)
treea64887800d551c01ac84f3132ad8297ad47c1f0e /lib/private/AppFramework
parentb5ba1dec5d7e6a9822185d76a5952244d0152051 (diff)
downloadnextcloud-server-3cf39c573f389ca0d55ee2e7dbfe05a518ef94a3.tar.gz
nextcloud-server-3cf39c573f389ca0d55ee2e7dbfe05a518ef94a3.zip
Allow lazy app registration
During app installation we run migration steps. Those steps may use services the app registers or classes from composer. Hence we have to make sure the app runs through the registration. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/AppFramework')
-rw-r--r--lib/private/AppFramework/Bootstrap/Coordinator.php22
-rw-r--r--lib/private/AppFramework/Bootstrap/RegistrationContext.php12
2 files changed, 21 insertions, 13 deletions
diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php
index c8155c3b5ba..06a17e5242b 100644
--- a/lib/private/AppFramework/Bootstrap/Coordinator.php
+++ b/lib/private/AppFramework/Bootstrap/Coordinator.php
@@ -38,7 +38,6 @@ use OCP\Dashboard\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\IServerContainer;
-use RuntimeException;
use Throwable;
use function class_exists;
use function class_implements;
@@ -79,14 +78,23 @@ class Coordinator {
$this->logger = $logger;
}
- public function runRegistration(): void {
- if ($this->registrationContext !== null) {
- throw new RuntimeException('Registration has already been run');
- }
+ public function runInitialRegistration(): void {
+ $this->registerApps(OC_App::getEnabledApps());
+ }
- $this->registrationContext = new RegistrationContext($this->logger);
+ public function runLazyRegistration(string $appId): void {
+ $this->registerApps([$appId]);
+ }
+
+ /**
+ * @param string[] $appIds
+ */
+ private function registerApps(array $appIds): void {
+ if ($this->registrationContext === null) {
+ $this->registrationContext = new RegistrationContext($this->logger);
+ }
$apps = [];
- foreach (OC_App::getEnabledApps() as $appId) {
+ foreach ($appIds as $appId) {
/*
* First, we have to enable the app's autoloader
*
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
index 023590596e3..68e2701de27 100644
--- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php
+++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
@@ -264,7 +264,7 @@ class RegistrationContext {
* @param App[] $apps
*/
public function delegateCapabilityRegistrations(array $apps): void {
- foreach ($this->capabilities as $registration) {
+ while (($registration = array_pop($this->capabilities)) !== null) {
try {
$apps[$registration['appId']]
->getContainer()
@@ -283,7 +283,7 @@ class RegistrationContext {
* @param App[] $apps
*/
public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void {
- foreach ($this->crashReporters as $registration) {
+ while (($registration = array_pop($this->crashReporters)) !== null) {
try {
$registry->registerLazy($registration['class']);
} catch (Throwable $e) {
@@ -300,7 +300,7 @@ class RegistrationContext {
* @param App[] $apps
*/
public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
- foreach ($this->dashboardPanels as $panel) {
+ while (($panel = array_pop($this->dashboardPanels)) !== null) {
try {
$dashboardManager->lazyRegisterWidget($panel['class']);
} catch (Throwable $e) {
@@ -314,7 +314,7 @@ class RegistrationContext {
}
public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void {
- foreach ($this->eventListeners as $registration) {
+ while (($registration = array_pop($this->eventListeners)) !== null) {
try {
if (isset($registration['priority'])) {
$eventDispatcher->addServiceListener(
@@ -342,7 +342,7 @@ class RegistrationContext {
* @param App[] $apps
*/
public function delegateContainerRegistrations(array $apps): void {
- foreach ($this->services as $registration) {
+ while (($registration = array_pop($this->services)) !== null) {
try {
/**
* Register the service and convert the callable into a \Closure if necessary
@@ -402,7 +402,7 @@ class RegistrationContext {
* @param App[] $apps
*/
public function delegateMiddlewareRegistrations(array $apps): void {
- foreach ($this->middlewares as $middleware) {
+ while (($middleware = array_pop($this->middlewares)) !== null) {
try {
$apps[$middleware['appId']]
->getContainer()