Merge pull request #58790 from nextcloud/chore/remove-oc-app-get-current-app
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Integration sqlite / changes (push) Waiting to run
Integration sqlite / integration-sqlite (master, 8.4, main, --tags ~@large files_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, capabilities_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, collaboration_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, comments_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, dav_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, federation_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, file_conversions) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, files_reminders) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, filesdrop_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, ldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, openldap_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, openldap_numerical_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, remoteapi_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, routing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, setup_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, sharees_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, sharing_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, theming_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite (master, 8.4, main, videoverification_features) (push) Blocked by required conditions
Integration sqlite / integration-sqlite-summary (push) Blocked by required conditions
Psalm static code analysis / static-code-analysis (push) Waiting to run
Psalm static code analysis / static-code-analysis-security (push) Waiting to run
Psalm static code analysis / static-code-analysis-ocp (push) Waiting to run
Psalm static code analysis / static-code-analysis-ncu (push) Waiting to run
Psalm static code analysis / static-code-analysis-strict (push) Waiting to run

fix: Deprecate OC_App::getCurrentApp and remove its only use
This commit is contained in:
Carl Schwan 2026-03-09 10:20:08 +01:00 committed by GitHub
commit 2613f3274b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 5 deletions

View file

@ -58,6 +58,7 @@ class TemplateLayout {
private INavigationManager $navigationManager,
private ITemplateManager $templateManager,
private ServerVersion $serverVersion,
private IRequest $request,
) {
}
@ -72,7 +73,8 @@ class TemplateLayout {
switch ($renderAs) {
case TemplateResponse::RENDER_AS_USER:
$page = $this->templateManager->getTemplate('core', 'layout.user');
if (in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
$pathInfo = $this->request->getPathInfo();
if ($pathInfo !== false && str_starts_with($pathInfo, '/settings/')) {
$page->assign('bodyid', 'body-settings');
} else {
$page->assign('bodyid', 'body-user');
@ -254,10 +256,8 @@ class TemplateLayout {
$page->append('jsfiles', $web . '/' . $file . $this->getVersionHashSuffix());
}
$request = Server::get(IRequest::class);
try {
$pathInfo = $request->getPathInfo();
$pathInfo = $this->request->getPathInfo();
} catch (\Exception $e) {
$pathInfo = '';
}
@ -298,7 +298,7 @@ class TemplateLayout {
}
}
if ($request->isUserAgent([Request::USER_AGENT_CLIENT_IOS, Request::USER_AGENT_SAFARI, Request::USER_AGENT_SAFARI_MOBILE])) {
if ($this->request->isUserAgent([Request::USER_AGENT_CLIENT_IOS, Request::USER_AGENT_SAFARI, Request::USER_AGENT_SAFARI_MOBILE])) {
// Prevent auto zoom with iOS but still allow user zoom
// On chrome (and others) this does not work (will also disable user zoom)
$page->assign('viewport_maximum_scale', '1.0');

View file

@ -261,6 +261,7 @@ class OC_App {
/**
* get the id of loaded app
* @deprecated 34.0.0 Dont do that
*/
public static function getCurrentApp(): string {
if (\OC::$CLI) {

View file

@ -16,6 +16,7 @@ use OCP\AppFramework\Http\TemplateResponse;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\ServerVersion;
use OCP\Template\ITemplateManager;
use PHPUnit\Framework\MockObject\MockObject;
@ -28,6 +29,7 @@ class TemplateLayoutTest extends \Test\TestCase {
private INavigationManager&MockObject $navigationManager;
private ITemplateManager&MockObject $templateManager;
private ServerVersion&MockObject $serverVersion;
private IRequest&MockObject $request;
private TemplateLayout $templateLayout;
@ -41,6 +43,7 @@ class TemplateLayoutTest extends \Test\TestCase {
$this->navigationManager = $this->createMock(INavigationManager::class);
$this->templateManager = $this->createMock(ITemplateManager::class);
$this->serverVersion = $this->createMock(ServerVersion::class);
$this->request = $this->createMock(IRequest::class);
}
#[\PHPUnit\Framework\Attributes\DataProvider('dataVersionHash')]
@ -73,6 +76,9 @@ class TemplateLayoutTest extends \Test\TestCase {
->with('theming', 'cachebuster', '0')
->willReturn('42');
$this->request->method('getPathInfo')
->willReturn('/' . $path);
$this->templateLayout = $this->getMockBuilder(TemplateLayout::class)
->onlyMethods(['getAppNamefromPath'])
->setConstructorArgs([
@ -83,6 +89,7 @@ class TemplateLayoutTest extends \Test\TestCase {
$this->navigationManager,
$this->templateManager,
$this->serverVersion,
$this->request,
])
->getMock();