Skip to content

Commit eea91fa

Browse files
committed
fix(TemplateLayout): core is not an app but the server itself
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 31664b3 commit eea91fa

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

build/psalm-baseline.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,15 +2576,6 @@
25762576
<code><![CDATA[$script]]></code>
25772577
</ParamNameMismatch>
25782578
</file>
2579-
<file src="lib/private/TemplateLayout.php">
2580-
<InvalidParamDefault>
2581-
<code><![CDATA[string]]></code>
2582-
<code><![CDATA[string]]></code>
2583-
</InvalidParamDefault>
2584-
<InvalidScalarArgument>
2585-
<code><![CDATA[$appId]]></code>
2586-
</InvalidScalarArgument>
2587-
</file>
25882579
<file src="lib/private/URLGenerator.php">
25892580
<InvalidReturnStatement>
25902581
<code><![CDATA[$path]]></code>

lib/private/TemplateLayout.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,18 @@ private function getVersionHashByPath(string $path): string|false {
344344
return false;
345345
}
346346

347-
$appVersion = $this->appManager->getAppVersion($appId);
348-
// For shipped apps the app version is not a single source of truth, we rather also need to consider the Nextcloud version
349-
if ($this->appManager->isShipped($appId)) {
350-
$appVersion .= '-' . self::$versionHash;
351-
}
347+
if ($appId === 'core') {
348+
// core is not a real app but the server itself
349+
$hash = self::$versionHash;
350+
} else {
351+
$appVersion = $this->appManager->getAppVersion($appId);
352+
// For shipped apps the app version is not a single source of truth, we rather also need to consider the Nextcloud version
353+
if ($this->appManager->isShipped($appId)) {
354+
$appVersion .= '-' . self::$versionHash;
355+
}
352356

353-
$hash = substr(md5($appVersion), 0, 8);
357+
$hash = substr(md5($appVersion), 0, 8);
358+
}
354359
self::$cacheBusterCache[$path] = $hash;
355360
}
356361

tests/lib/AppTest.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
use OC\AppConfig;
1313
use OCP\EventDispatcher\IEventDispatcher;
1414
use OCP\IAppConfig;
15-
use OCP\IURLGenerator;
15+
use OCP\ICacheFactory;
16+
use OCP\IConfig;
17+
use OCP\IDBConnection;
18+
use OCP\IGroupManager;
19+
use OCP\IUserManager;
20+
use OCP\IUserSession;
21+
use OCP\ServerVersion;
1622
use PHPUnit\Framework\MockObject\MockObject;
1723
use Psr\Log\LoggerInterface;
1824

@@ -463,8 +469,8 @@ public function appConfigValuesProvider() {
463469
* @dataProvider appConfigValuesProvider
464470
*/
465471
public function testEnabledApps($user, $expectedApps, $forceAll): void {
466-
$userManager = \OC::$server->getUserManager();
467-
$groupManager = \OC::$server->getGroupManager();
472+
$userManager = \OCP\Server::get(IUserManager::class);
473+
$groupManager = \OCP\Server::get(IGroupManager::class);
468474
$user1 = $userManager->createUser(self::TEST_USER1, 'NotAnEasyPassword123456+');
469475
$user2 = $userManager->createUser(self::TEST_USER2, 'NotAnEasyPassword123456_');
470476
$user3 = $userManager->createUser(self::TEST_USER3, 'NotAnEasyPassword123456?');
@@ -512,7 +518,7 @@ public function testEnabledApps($user, $expectedApps, $forceAll): void {
512518
* enabled apps more than once when a user is set.
513519
*/
514520
public function testEnabledAppsCache(): void {
515-
$userManager = \OC::$server->getUserManager();
521+
$userManager = \OCP\Server::get(IUserManager::class);
516522
$user1 = $userManager->createUser(self::TEST_USER1, 'NotAnEasyPassword123456+');
517523

518524
\OC_User::setUserId(self::TEST_USER1);
@@ -544,8 +550,8 @@ public function testEnabledAppsCache(): void {
544550
private function setupAppConfigMock() {
545551
/** @var AppConfig|MockObject */
546552
$appConfig = $this->getMockBuilder(AppConfig::class)
547-
->setMethods(['getValues'])
548-
->setConstructorArgs([\OC::$server->getDatabaseConnection()])
553+
->onlyMethods(['getValues'])
554+
->setConstructorArgs([\OCP\Server::get(IDBConnection::class)])
549555
->disableOriginalConstructor()
550556
->getMock();
551557

@@ -561,13 +567,13 @@ private function setupAppConfigMock() {
561567
private function registerAppConfig(AppConfig $appConfig) {
562568
$this->overwriteService(AppConfig::class, $appConfig);
563569
$this->overwriteService(AppManager::class, new AppManager(
564-
\OC::$server->getUserSession(),
565-
\OC::$server->getConfig(),
566-
\OC::$server->getGroupManager(),
567-
\OC::$server->getMemCacheFactory(),
568-
\OC::$server->get(IEventDispatcher::class),
569-
\OC::$server->get(LoggerInterface::class),
570-
\OC::$server->get(IURLGenerator::class),
570+
\OCP\Server::get(IUserSession::class),
571+
\OCP\Server::get(IConfig::class),
572+
\OCP\Server::get(IGroupManager::class),
573+
\OCP\Server::get(ICacheFactory::class),
574+
\OCP\Server::get(IEventDispatcher::class),
575+
\OCP\Server::get(LoggerInterface::class),
576+
\OCP\Server::get(ServerVersion::class),
571577
));
572578
}
573579

0 commit comments

Comments
 (0)