Skip to content

Commit

Permalink
Merge pull request #47517 from nextcloud/backport/47508/stable29
Browse files Browse the repository at this point in the history
[stable29] fix(Router): Load attribute routes of all apps when not app is specified
  • Loading branch information
AndyScherzinger authored Aug 27, 2024
2 parents a91067c + 351cf89 commit 63ce129
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions lib/private/Route/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,14 @@ public function loadRoutes($app = null) {
if ($this->loaded) {
return;
}
$this->eventLogger->start('route:load:' . $requestedApp, 'Loading Routes for ' . $requestedApp);
if (is_null($app)) {
$this->loaded = true;
$routingFiles = $this->getRoutingFiles();

foreach (\OC_App::getEnabledApps() as $enabledApp) {
$this->loadAttributeRoutes($enabledApp);
}
} else {
if (isset($this->loadedApps[$app])) {
return;
Expand All @@ -154,21 +159,9 @@ public function loadRoutes($app = null) {
} else {
$routingFiles = [];
}
}
$this->eventLogger->start('route:load:' . $requestedApp, 'Loading Routes for ' . $requestedApp);

if ($requestedApp !== null && in_array($requestedApp, \OC_App::getEnabledApps())) {
$routes = $this->getAttributeRoutes($requestedApp);
if (count($routes) > 0) {
$this->useCollection($requestedApp);
$this->setupRoutes($routes, $requestedApp);
$collection = $this->getCollection($requestedApp);
$this->root->addCollection($collection);

// Also add the OCS collection
$collection = $this->getCollection($requestedApp . '.ocs');
$collection->addPrefix('/ocsapp');
$this->root->addCollection($collection);
if (in_array($app, \OC_App::getEnabledApps())) {
$this->loadAttributeRoutes($app);
}
}

Expand Down Expand Up @@ -442,6 +435,23 @@ protected function fixLegacyRootName(string $routeName): string {
return $routeName;
}

private function loadAttributeRoutes(string $app): void {
$routes = $this->getAttributeRoutes($app);
if (count($routes) === 0) {
return;
}

$this->useCollection($app);
$this->setupRoutes($routes, $app);
$collection = $this->getCollection($app);
$this->root->addCollection($collection);

// Also add the OCS collection
$collection = $this->getCollection($app . '.ocs');
$collection->addPrefix('/ocsapp');
$this->root->addCollection($collection);
}

/**
* @throws ReflectionException
*/
Expand Down

0 comments on commit 63ce129

Please sign in to comment.