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>
This commit is contained in:
parent
b5ba1dec5d
commit
3cf39c573f
|
@ -641,7 +641,7 @@ class OC {
|
||||||
|
|
||||||
/** @var \OC\AppFramework\Bootstrap\Coordinator $bootstrapCoordinator */
|
/** @var \OC\AppFramework\Bootstrap\Coordinator $bootstrapCoordinator */
|
||||||
$bootstrapCoordinator = \OC::$server->query(\OC\AppFramework\Bootstrap\Coordinator::class);
|
$bootstrapCoordinator = \OC::$server->query(\OC\AppFramework\Bootstrap\Coordinator::class);
|
||||||
$bootstrapCoordinator->runRegistration();
|
$bootstrapCoordinator->runInitialRegistration();
|
||||||
|
|
||||||
\OC::$server->getEventLogger()->start('init_session', 'Initialize session');
|
\OC::$server->getEventLogger()->start('init_session', 'Initialize session');
|
||||||
OC_App::loadApps(['session']);
|
OC_App::loadApps(['session']);
|
||||||
|
|
|
@ -38,7 +38,6 @@ use OCP\Dashboard\IManager;
|
||||||
use OCP\EventDispatcher\IEventDispatcher;
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IServerContainer;
|
use OCP\IServerContainer;
|
||||||
use RuntimeException;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use function class_exists;
|
use function class_exists;
|
||||||
use function class_implements;
|
use function class_implements;
|
||||||
|
@ -79,14 +78,23 @@ class Coordinator {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function runRegistration(): void {
|
public function runInitialRegistration(): void {
|
||||||
if ($this->registrationContext !== null) {
|
$this->registerApps(OC_App::getEnabledApps());
|
||||||
throw new RuntimeException('Registration has already been run');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
$this->registrationContext = new RegistrationContext($this->logger);
|
||||||
|
}
|
||||||
$apps = [];
|
$apps = [];
|
||||||
foreach (OC_App::getEnabledApps() as $appId) {
|
foreach ($appIds as $appId) {
|
||||||
/*
|
/*
|
||||||
* First, we have to enable the app's autoloader
|
* First, we have to enable the app's autoloader
|
||||||
*
|
*
|
||||||
|
|
|
@ -264,7 +264,7 @@ class RegistrationContext {
|
||||||
* @param App[] $apps
|
* @param App[] $apps
|
||||||
*/
|
*/
|
||||||
public function delegateCapabilityRegistrations(array $apps): void {
|
public function delegateCapabilityRegistrations(array $apps): void {
|
||||||
foreach ($this->capabilities as $registration) {
|
while (($registration = array_pop($this->capabilities)) !== null) {
|
||||||
try {
|
try {
|
||||||
$apps[$registration['appId']]
|
$apps[$registration['appId']]
|
||||||
->getContainer()
|
->getContainer()
|
||||||
|
@ -283,7 +283,7 @@ class RegistrationContext {
|
||||||
* @param App[] $apps
|
* @param App[] $apps
|
||||||
*/
|
*/
|
||||||
public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void {
|
public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void {
|
||||||
foreach ($this->crashReporters as $registration) {
|
while (($registration = array_pop($this->crashReporters)) !== null) {
|
||||||
try {
|
try {
|
||||||
$registry->registerLazy($registration['class']);
|
$registry->registerLazy($registration['class']);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
|
@ -300,7 +300,7 @@ class RegistrationContext {
|
||||||
* @param App[] $apps
|
* @param App[] $apps
|
||||||
*/
|
*/
|
||||||
public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
|
public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
|
||||||
foreach ($this->dashboardPanels as $panel) {
|
while (($panel = array_pop($this->dashboardPanels)) !== null) {
|
||||||
try {
|
try {
|
||||||
$dashboardManager->lazyRegisterWidget($panel['class']);
|
$dashboardManager->lazyRegisterWidget($panel['class']);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
|
@ -314,7 +314,7 @@ class RegistrationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void {
|
public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void {
|
||||||
foreach ($this->eventListeners as $registration) {
|
while (($registration = array_pop($this->eventListeners)) !== null) {
|
||||||
try {
|
try {
|
||||||
if (isset($registration['priority'])) {
|
if (isset($registration['priority'])) {
|
||||||
$eventDispatcher->addServiceListener(
|
$eventDispatcher->addServiceListener(
|
||||||
|
@ -342,7 +342,7 @@ class RegistrationContext {
|
||||||
* @param App[] $apps
|
* @param App[] $apps
|
||||||
*/
|
*/
|
||||||
public function delegateContainerRegistrations(array $apps): void {
|
public function delegateContainerRegistrations(array $apps): void {
|
||||||
foreach ($this->services as $registration) {
|
while (($registration = array_pop($this->services)) !== null) {
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
* Register the service and convert the callable into a \Closure if necessary
|
* Register the service and convert the callable into a \Closure if necessary
|
||||||
|
@ -402,7 +402,7 @@ class RegistrationContext {
|
||||||
* @param App[] $apps
|
* @param App[] $apps
|
||||||
*/
|
*/
|
||||||
public function delegateMiddlewareRegistrations(array $apps): void {
|
public function delegateMiddlewareRegistrations(array $apps): void {
|
||||||
foreach ($this->middlewares as $middleware) {
|
while (($middleware = array_pop($this->middlewares)) !== null) {
|
||||||
try {
|
try {
|
||||||
$apps[$middleware['appId']]
|
$apps[$middleware['appId']]
|
||||||
->getContainer()
|
->getContainer()
|
||||||
|
|
|
@ -42,6 +42,7 @@ namespace OC;
|
||||||
use Doctrine\DBAL\Exception\TableExistsException;
|
use Doctrine\DBAL\Exception\TableExistsException;
|
||||||
use OC\App\AppStore\Bundles\Bundle;
|
use OC\App\AppStore\Bundles\Bundle;
|
||||||
use OC\App\AppStore\Fetcher\AppFetcher;
|
use OC\App\AppStore\Fetcher\AppFetcher;
|
||||||
|
use OC\AppFramework\Bootstrap\Coordinator;
|
||||||
use OC\Archive\TAR;
|
use OC\Archive\TAR;
|
||||||
use OC_App;
|
use OC_App;
|
||||||
use OC_DB;
|
use OC_DB;
|
||||||
|
@ -138,6 +139,9 @@ class Installer {
|
||||||
|
|
||||||
// check for required dependencies
|
// check for required dependencies
|
||||||
\OC_App::checkAppDependencies($this->config, $l, $info, $ignoreMax);
|
\OC_App::checkAppDependencies($this->config, $l, $info, $ignoreMax);
|
||||||
|
/** @var Coordinator $coordinator */
|
||||||
|
$coordinator = \OC::$server->get(Coordinator::class);
|
||||||
|
$coordinator->runLazyRegistration($appId);
|
||||||
\OC_App::registerAutoloading($appId, $basedir);
|
\OC_App::registerAutoloading($appId, $basedir);
|
||||||
|
|
||||||
$previousVersion = $this->config->getAppValue($info['id'], 'installed_version', false);
|
$previousVersion = $this->config->getAppValue($info['id'], 'installed_version', false);
|
||||||
|
|
Loading…
Reference in New Issue