Skip to content

Commit ac15544

Browse files
Merge pull request #60299 from nextcloud/fix/remove-iservercontainer-from-core-apps
Chore: Remove references to deprecated interface IServerContainer
2 parents 88b79c6 + 028719b commit ac15544

42 files changed

Lines changed: 168 additions & 319 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/dav/tests/unit/Connector/Sabre/NodeTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,12 @@ public function testDavPermissions(int $permissions, string $type, bool $shared,
9898
->method('getRelativePath')
9999
->with(null)
100100
->willReturn('');
101+
$view
102+
->method('getAbsolutePath')
103+
->with(null)
104+
->willReturn('');
101105

102-
$node = new File($view, $info);
106+
$node = new File($view, $info);
103107
$this->assertEquals($expected, $node->getDavPermissions());
104108
}
105109

apps/files/lib/AppInfo/Application.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use OCA\Files\Collaboration\Resources\Listener;
1515
use OCA\Files\Collaboration\Resources\ResourceProvider;
1616
use OCA\Files\ConfigLexicon;
17-
use OCA\Files\Controller\ApiController;
1817
use OCA\Files\Dashboard\FavoriteWidget;
1918
use OCA\Files\DirectEditingCapabilities;
2019
use OCA\Files\Event\LoadSearchPlugins;
@@ -28,10 +27,6 @@
2827
use OCA\Files\Listener\UserFirstTimeLoggedInListener;
2928
use OCA\Files\Notification\Notifier;
3029
use OCA\Files\Search\FilesSearchProvider;
31-
use OCA\Files\Service\TagService;
32-
use OCA\Files\Service\UserConfig;
33-
use OCA\Files\Service\ViewConfig;
34-
use OCP\Activity\IManager as IActivityManager;
3530
use OCP\AppFramework\App;
3631
use OCP\AppFramework\Bootstrap\IBootContext;
3732
use OCP\AppFramework\Bootstrap\IBootstrap;
@@ -45,19 +40,8 @@
4540
use OCP\Files\Events\Node\NodeCopiedEvent;
4641
use OCP\Files\Events\NodeAddedToFavorite;
4742
use OCP\Files\Events\NodeRemovedFromFavorite;
48-
use OCP\Files\IRootFolder;
49-
use OCP\IConfig;
50-
use OCP\IL10N;
51-
use OCP\IPreview;
52-
use OCP\IRequest;
53-
use OCP\IServerContainer;
54-
use OCP\ITagManager;
55-
use OCP\IUserSession;
56-
use OCP\Share\IManager as IShareManager;
5743
use OCP\User\Events\UserFirstTimeLoggedInEvent;
5844
use OCP\Util;
59-
use Psr\Container\ContainerInterface;
60-
use Psr\Log\LoggerInterface;
6145

6246
class Application extends App implements IBootstrap {
6347
public const APP_ID = 'files';
@@ -68,45 +52,6 @@ public function __construct(array $urlParams = []) {
6852

6953
#[\Override]
7054
public function register(IRegistrationContext $context): void {
71-
/**
72-
* Controllers
73-
*/
74-
$context->registerService('APIController', function (ContainerInterface $c) {
75-
/** @var IServerContainer $server */
76-
$server = $c->get(IServerContainer::class);
77-
78-
return new ApiController(
79-
$c->get('AppName'),
80-
$c->get(IRequest::class),
81-
$c->get(IUserSession::class),
82-
$c->get(TagService::class),
83-
$c->get(IPreview::class),
84-
$c->get(IShareManager::class),
85-
$c->get(IConfig::class),
86-
$server->getUserFolder(),
87-
$c->get(UserConfig::class),
88-
$c->get(ViewConfig::class),
89-
$c->get(IL10N::class),
90-
$c->get(IRootFolder::class),
91-
$c->get(LoggerInterface::class),
92-
);
93-
});
94-
95-
/**
96-
* Services
97-
*/
98-
$context->registerService(TagService::class, function (ContainerInterface $c) {
99-
/** @var IServerContainer $server */
100-
$server = $c->get(IServerContainer::class);
101-
102-
return new TagService(
103-
$c->get(IUserSession::class),
104-
$c->get(IActivityManager::class),
105-
$c->get(ITagManager::class)->load(self::APP_ID),
106-
$server->getUserFolder(),
107-
);
108-
});
109-
11055
/*
11156
* Register capabilities
11257
*/

apps/files/lib/Controller/ApiController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
* @package OCA\Files\Controller
5454
*/
5555
class ApiController extends Controller {
56+
private ?Folder $userFolder = null;
57+
5658
public function __construct(
5759
string $appName,
5860
IRequest $request,
@@ -61,14 +63,17 @@ public function __construct(
6163
private IPreview $previewManager,
6264
private IManager $shareManager,
6365
private IConfig $config,
64-
private ?Folder $userFolder,
6566
private UserConfig $userConfig,
6667
private ViewConfig $viewConfig,
6768
private IL10N $l10n,
6869
private IRootFolder $rootFolder,
6970
private LoggerInterface $logger,
7071
) {
7172
parent::__construct($appName, $request);
73+
$user = $this->userSession->getUser();
74+
if ($user) {
75+
$this->userFolder = $this->rootFolder->getUserFolder($user->getUID());
76+
}
7277
}
7378

7479
/**

apps/files/lib/Service/TagService.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,33 @@
77
*/
88
namespace OCA\Files\Service;
99

10+
use OCA\Files\AppInfo\Application;
1011
use OCP\Activity\IManager;
1112
use OCP\Files\Folder;
13+
use OCP\Files\IRootFolder;
1214
use OCP\Files\NotFoundException;
15+
use OCP\ITagManager;
1316
use OCP\ITags;
1417
use OCP\IUserSession;
1518

1619
/**
1720
* Service class to manage tags on files.
1821
*/
1922
class TagService {
23+
private ?Folder $homeFolder = null;
24+
private ?ITags $tagger;
2025

2126
public function __construct(
2227
private IUserSession $userSession,
2328
private IManager $activityManager,
24-
private ?ITags $tagger,
25-
private ?Folder $homeFolder,
29+
ITagManager $tagManager,
30+
IRootFolder $rootFolder,
2631
) {
32+
$user = $this->userSession->getUser();
33+
if ($user) {
34+
$this->homeFolder = $rootFolder->getUserFolder($user->getUID());
35+
}
36+
$this->tagger = $tagManager->load(Application::APP_ID);
2737
}
2838

2939
/**

apps/files/tests/Controller/ApiControllerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ protected function setUp(): void {
7777
$this->viewConfig = $this->createMock(ViewConfig::class);
7878
$this->l10n = $this->createMock(IL10N::class);
7979
$this->rootFolder = $this->createMock(IRootFolder::class);
80+
$this->rootFolder->expects($this->any())
81+
->method('getUserFolder')
82+
->willReturn($this->userFolder);
8083
$this->logger = $this->createMock(LoggerInterface::class);
8184

8285
$this->apiController = new ApiController(
@@ -87,7 +90,6 @@ protected function setUp(): void {
8790
$this->preview,
8891
$this->shareManager,
8992
$this->config,
90-
$this->userFolder,
9193
$this->userConfig,
9294
$this->viewConfig,
9395
$this->l10n,

apps/files/tests/Service/TagServiceTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ protected function setUp(): void {
4444
\OC_User::setUserId($this->user);
4545
\OC_Util::setupFS($this->user);
4646
$user = $this->createMock(IUser::class);
47+
$user->expects($this->any())
48+
->method('getUID')
49+
->willReturn($this->user);
4750
$this->userSession = $this->createMock(IUserSession::class);
4851
$this->userSession->expects($this->any())
4952
->method('getUser')
@@ -61,8 +64,8 @@ protected function getTagService(array $methods = []): TagService&MockObject {
6164
->setConstructorArgs([
6265
$this->userSession,
6366
$this->activityManager,
64-
$this->tagger,
65-
$this->root,
67+
Server::get(ITagManager::class),
68+
Server::get(IRootFolder::class),
6669
])
6770
->onlyMethods($methods)
6871
->getMock();
@@ -91,16 +94,22 @@ public function testUpdateFileTags(): void {
9194
// set tags
9295
$this->tagService->updateFileTags('subdir/test.txt', [$tag1, $tag2]);
9396

97+
// Sync to reload tags
98+
$this->tagger->addMultiple([], sync:true);
9499
$this->assertEquals([$fileId], $this->tagger->getIdsForTag($tag1));
95100
$this->assertEquals([$fileId], $this->tagger->getIdsForTag($tag2));
96101

97102
// remove tag
98103
$this->tagService->updateFileTags('subdir/test.txt', [$tag2]);
104+
// Sync to reload tags
105+
$this->tagger->addMultiple([], sync:true);
99106
$this->assertEquals([], $this->tagger->getIdsForTag($tag1));
100107
$this->assertEquals([$fileId], $this->tagger->getIdsForTag($tag2));
101108

102109
// clear tags
103110
$this->tagService->updateFileTags('subdir/test.txt', []);
111+
// Sync to reload tags
112+
$this->tagger->addMultiple([], sync:true);
104113
$this->assertEquals([], $this->tagger->getIdsForTag($tag1));
105114
$this->assertEquals([], $this->tagger->getIdsForTag($tag2));
106115

apps/files_versions/lib/AppInfo/Application.php

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
*/
88
namespace OCA\Files_Versions\AppInfo;
99

10-
use OC\KnownUser\KnownUserService;
11-
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
1210
use OCA\DAV\Connector\Sabre\Principal;
1311
use OCA\Files\Event\LoadAdditionalScriptsEvent;
1412
use OCA\Files\Event\LoadSidebar;
@@ -22,7 +20,6 @@
2220
use OCA\Files_Versions\Listener\VersionStorageMoveListener;
2321
use OCA\Files_Versions\Versions\IVersionManager;
2422
use OCA\Files_Versions\Versions\VersionManager;
25-
use OCP\Accounts\IAccountManager;
2623
use OCP\App\IAppManager;
2724
use OCP\AppFramework\App;
2825
use OCP\AppFramework\Bootstrap\IBootContext;
@@ -39,14 +36,6 @@
3936
use OCP\Files\Events\Node\NodeRenamedEvent;
4037
use OCP\Files\Events\Node\NodeTouchedEvent;
4138
use OCP\Files\Events\Node\NodeWrittenEvent;
42-
use OCP\IConfig;
43-
use OCP\IGroupManager;
44-
use OCP\IServerContainer;
45-
use OCP\IUserManager;
46-
use OCP\IUserSession;
47-
use OCP\L10N\IFactory;
48-
use OCP\Server;
49-
use OCP\Share\IManager as IShareManager;
5039
use Psr\Container\ContainerInterface;
5140
use Psr\Log\LoggerInterface;
5241

@@ -67,22 +56,7 @@ public function register(IRegistrationContext $context): void {
6756
/**
6857
* Register $principalBackend for the DAV collection
6958
*/
70-
$context->registerService('principalBackend', function (ContainerInterface $c) {
71-
/** @var IServerContainer $server */
72-
$server = $c->get(IServerContainer::class);
73-
return new Principal(
74-
$server->get(IUserManager::class),
75-
$server->get(IGroupManager::class),
76-
Server::get(IAccountManager::class),
77-
$server->get(IShareManager::class),
78-
$server->get(IUserSession::class),
79-
$server->get(IAppManager::class),
80-
$server->get(ProxyMapper::class),
81-
$server->get(KnownUserService::class),
82-
$server->get(IConfig::class),
83-
$server->get(IFactory::class),
84-
);
85-
});
59+
$context->registerServiceAlias('principalBackend', Principal::class);
8660

8761
$context->registerServiceAlias(IVersionManager::class, VersionManager::class);
8862

apps/provisioning_api/composer/composer/autoload_classmap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
'OCA\\Provisioning_API\\Controller\\PreferencesController' => $baseDir . '/../lib/Controller/PreferencesController.php',
1717
'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir . '/../lib/Controller/UsersController.php',
1818
'OCA\\Provisioning_API\\Controller\\VerificationController' => $baseDir . '/../lib/Controller/VerificationController.php',
19-
'OCA\\Provisioning_API\\FederatedShareProviderFactory' => $baseDir . '/../lib/FederatedShareProviderFactory.php',
2019
'OCA\\Provisioning_API\\Listener\\UserDeletedListener' => $baseDir . '/../lib/Listener/UserDeletedListener.php',
2120
'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
2221
'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => $baseDir . '/../lib/Middleware/ProvisioningApiMiddleware.php',

apps/provisioning_api/composer/composer/autoload_static.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class ComposerStaticInitProvisioning_API
3131
'OCA\\Provisioning_API\\Controller\\PreferencesController' => __DIR__ . '/..' . '/../lib/Controller/PreferencesController.php',
3232
'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__ . '/..' . '/../lib/Controller/UsersController.php',
3333
'OCA\\Provisioning_API\\Controller\\VerificationController' => __DIR__ . '/..' . '/../lib/Controller/VerificationController.php',
34-
'OCA\\Provisioning_API\\FederatedShareProviderFactory' => __DIR__ . '/..' . '/../lib/FederatedShareProviderFactory.php',
3534
'OCA\\Provisioning_API\\Listener\\UserDeletedListener' => __DIR__ . '/..' . '/../lib/Listener/UserDeletedListener.php',
3635
'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__ . '/..' . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
3736
'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/ProvisioningApiMiddleware.php',

apps/provisioning_api/lib/FederatedShareProviderFactory.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)