From 92966bfb5a52a9713326aafa91f48f13c403d557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 30 Jan 2025 17:16:26 +0100 Subject: [PATCH] chore: Apply new rector configuration to apps folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/comments/lib/Search/LegacyProvider.php | 6 +- .../tests/Unit/AppInfo/ApplicationTest.php | 8 +- .../tests/Db/RecentContactMapperTest.php | 5 +- apps/dav/appinfo/v1/caldav.php | 57 +++++---- apps/dav/appinfo/v1/carddav.php | 55 ++++---- apps/dav/appinfo/v1/publicwebdav.php | 39 +++--- apps/dav/appinfo/v1/webdav.php | 46 ++++--- apps/dav/appinfo/v2/direct.php | 12 +- apps/dav/appinfo/v2/remote.php | 3 +- apps/dav/lib/AppInfo/Application.php | 7 +- apps/dav/lib/Avatars/RootCollection.php | 3 +- apps/dav/lib/CalDAV/CalendarHome.php | 6 +- .../InvitationResponseServer.php | 12 +- apps/dav/lib/CardDAV/UserAddressBooks.php | 6 +- apps/dav/lib/Command/CreateCalendar.php | 26 ++-- apps/dav/lib/Connector/Sabre/Directory.php | 9 +- apps/dav/lib/Connector/Sabre/File.php | 20 +-- apps/dav/lib/Connector/Sabre/Node.php | 11 +- .../dav/lib/Connector/Sabre/ServerFactory.php | 22 ++-- apps/dav/lib/Files/BrowserErrorPagePlugin.php | 2 +- apps/dav/lib/Files/RootCollection.php | 4 +- apps/dav/lib/HookManager.php | 13 +- apps/dav/lib/RootCollection.php | 48 +++---- apps/dav/lib/Server.php | 119 ++++++++++-------- apps/dav/lib/Upload/UploadFolder.php | 4 +- apps/dav/lib/Upload/UploadHome.php | 4 +- apps/dav/templates/settings-admin-caldav.php | 2 +- .../settings-personal-availability.php | 2 +- .../integration/Db/PropertyMapperTest.php | 3 +- .../UserStatusAutomationTest.php | 6 +- .../unit/CalDAV/AbstractCalDavBackend.php | 5 +- .../unit/CalDAV/PublicCalendarRootTest.php | 6 +- .../tests/unit/CardDAV/CardDavBackendTest.php | 3 +- .../unit/Command/RemoveInvalidSharesTest.php | 6 +- .../Sabre/CustomPropertiesBackendTest.php | 6 +- .../unit/Connector/Sabre/RequestTest/Auth.php | 4 +- .../EncryptionMasterKeyUploadTest.php | 7 +- .../RequestTest/EncryptionUploadTest.php | 7 +- .../RequestTest/PartFileInRootUploadTest.php | 3 +- .../Sabre/RequestTest/RequestTestCase.php | 26 ++-- .../unit/DAV/CustomPropertiesBackendTest.php | 2 +- .../Migration/CalDAVRemoveEmptyValueTest.php | 10 +- apps/encryption/templates/settings-admin.php | 2 +- .../templates/settings-personal.php | 2 +- .../tests/Command/FixEncryptedVersionTest.php | 24 ++-- .../encryption/tests/EncryptedStorageTest.php | 3 +- .../lib/OCM/CloudFederationProviderFiles.php | 8 +- .../tests/FederatedShareProviderTest.php | 13 +- apps/federatedfilesharing/tests/TestCase.php | 20 +-- apps/federation/tests/DbHandlerTest.php | 3 +- .../lib/BackgroundJob/CleanupFileLocks.php | 4 +- apps/files/lib/Command/Scan.php | 7 +- apps/files/lib/Command/ScanAppData.php | 5 +- apps/files/lib/Helper.php | 10 +- .../DeleteOrphanedItemsJobTest.php | 5 +- .../tests/BackgroundJob/ScanFilesTest.php | 6 +- .../tests/Command/DeleteOrphanedFilesTest.php | 4 +- apps/files/tests/Service/TagServiceTest.php | 8 +- apps/files_external/ajax/applicable.php | 7 +- .../lib/Lib/Storage/AmazonS3.php | 5 +- apps/files_external/lib/Lib/Storage/FTP.php | 11 +- apps/files_external/lib/Lib/Storage/SFTP.php | 3 +- apps/files_external/lib/Lib/Storage/SMB.php | 6 +- apps/files_external/lib/Lib/Storage/Swift.php | 29 +++-- apps/files_external/lib/MountConfig.php | 11 +- .../lib/Service/BackendService.php | 5 +- .../lib/Service/LegacyStoragesService.php | 5 +- .../lib/Service/StoragesService.php | 5 +- apps/files_external/templates/settings.php | 4 +- .../tests/Service/DBConfigServiceTest.php | 6 +- .../tests/Service/StoragesServiceTest.php | 12 +- .../Service/UserGlobalStoragesServiceTest.php | 3 +- .../tests/Service/UserStoragesServiceTest.php | 5 +- .../tests/Storage/WebdavTest.php | 4 +- .../lib/Controller/ShareAPIController.php | 13 +- .../lib/Controller/ShareesAPIController.php | 6 +- .../lib/External/MountProvider.php | 4 +- apps/files_sharing/lib/External/Storage.php | 4 +- apps/files_sharing/lib/Helper.php | 6 +- apps/files_sharing/lib/Hooks.php | 3 +- .../lib/Listener/LoadAdditionalListener.php | 3 +- apps/files_sharing/lib/ShareBackend/File.php | 3 +- .../files_sharing/lib/ShareBackend/Folder.php | 6 +- apps/files_sharing/lib/SharedMount.php | 5 +- apps/files_sharing/lib/SharedStorage.php | 9 +- apps/files_sharing/lib/Updater.php | 5 +- .../templates/Settings/personal.php | 2 +- apps/files_sharing/templates/public.php | 8 +- apps/files_sharing/tests/ApiTest.php | 49 ++++---- apps/files_sharing/tests/CacheTest.php | 5 +- .../Command/CleanupRemoteStoragesTest.php | 17 +-- .../tests/Controller/ShareControllerTest.php | 16 +-- .../tests/DeleteOrphanedSharesJobTest.php | 16 +-- .../tests/EncryptedSizePropagationTest.php | 4 +- .../tests/EtagPropagationTest.php | 10 +- .../tests/ExpireSharesJobTest.php | 16 +-- .../tests/External/ManagerTest.php | 10 +- apps/files_sharing/tests/HelperTest.php | 4 +- apps/files_sharing/tests/LockingTest.php | 5 +- .../tests/Migration/SetPasswordColumnTest.php | 3 +- .../tests/PropagationTestCase.php | 6 +- apps/files_sharing/tests/ShareTest.php | 8 +- apps/files_sharing/tests/SharedMountTest.php | 7 +- .../files_sharing/tests/SharedStorageTest.php | 6 +- .../tests/SharesReminderJobTest.php | 27 ++-- .../tests/SizePropagationTest.php | 4 +- apps/files_sharing/tests/TestCase.php | 50 ++++---- apps/files_sharing/tests/UpdaterTest.php | 9 +- apps/files_trashbin/lib/Command/Expire.php | 3 +- apps/files_trashbin/lib/Helper.php | 4 +- .../lib/Sabre/RootCollection.php | 4 +- apps/files_trashbin/lib/Storage.php | 12 +- apps/files_trashbin/lib/Trashbin.php | 61 ++++----- .../tests/Command/CleanUpTest.php | 3 +- apps/files_trashbin/tests/StorageTest.php | 23 ++-- apps/files_trashbin/tests/TrashbinTest.php | 32 ++--- .../lib/AppInfo/Application.php | 3 +- apps/files_versions/lib/Command/Expire.php | 5 +- apps/files_versions/lib/Storage.php | 40 +++--- .../lib/Versions/VersionManager.php | 5 +- apps/files_versions/tests/StorageTest.php | 3 +- apps/files_versions/tests/VersioningTest.php | 67 +++++----- apps/oauth2/templates/admin.php | 2 +- .../Controller/SettingsControllerTest.php | 3 +- .../oauth2/tests/Db/AccessTokenMapperTest.php | 4 +- apps/oauth2/tests/Db/ClientMapperTest.php | 6 +- apps/profile/templates/404-profile.php | 4 +- .../lib/Controller/AUserDataOCSController.php | 3 +- .../tests/Controller/AppsControllerTest.php | 7 +- apps/provisioning_api/tests/TestCase.php | 5 +- apps/settings/lib/AppInfo/Application.php | 5 +- .../lib/Controller/AppSettingsController.php | 4 +- .../lib/Controller/UsersController.php | 4 +- .../templates/settings/admin/delegation.php | 2 +- .../templates/settings/admin/overview.php | 2 +- apps/settings/templates/settings/frame.php | 8 +- .../settings/personal/security/authtokens.php | 2 +- .../settings/personal/security/webauthn.php | 2 +- .../tests/Settings/Admin/ServerTest.php | 2 +- .../tests/ShareByMailProviderTest.php | 8 +- .../lib/AlternativeHomeUserBackend.php | 4 +- apps/theming/lib/Util.php | 3 +- .../Controller/ThemingControllerTest.php | 10 +- .../templates/personal.php | 2 +- .../tests/Db/BackupCodeMapperTest.php | 3 +- apps/user_ldap/ajax/clearMappings.php | 7 +- apps/user_ldap/ajax/deleteConfiguration.php | 5 +- .../ajax/getNewServerConfigPrefix.php | 5 +- apps/user_ldap/ajax/testConfiguration.php | 4 +- apps/user_ldap/ajax/wizard.php | 3 +- apps/user_ldap/lib/Access.php | 7 +- apps/user_ldap/lib/Command/Search.php | 4 +- apps/user_ldap/lib/Command/SetConfig.php | 5 +- apps/user_ldap/lib/Configuration.php | 7 +- apps/user_ldap/lib/Connection.php | 10 +- apps/user_ldap/lib/Helper.php | 3 +- apps/user_ldap/lib/Jobs/CleanUp.php | 8 +- apps/user_ldap/lib/LDAP.php | 2 +- apps/user_ldap/lib/Proxy.php | 3 +- apps/user_ldap/lib/Settings/Admin.php | 5 +- apps/user_ldap/lib/User/User.php | 7 +- apps/user_ldap/lib/Wizard.php | 7 +- apps/user_ldap/templates/renewpassword.php | 4 +- apps/user_ldap/tests/AccessTest.php | 4 +- apps/user_ldap/tests/Group_LDAPTest.php | 4 +- apps/user_ldap/tests/HelperTest.php | 4 +- .../Integration/AbstractIntegrationTest.php | 18 +-- .../Lib/IntegrationTestAttributeDetection.php | 18 +-- .../IntegrationTestFetchUsersByLoginName.php | 6 +- .../Integration/Lib/IntegrationTestPaging.php | 3 +- .../Lib/User/IntegrationTestUserAvatar.php | 29 +++-- .../Lib/User/IntegrationTestUserCleanUp.php | 10 +- .../User/IntegrationTestUserDisplayName.php | 10 +- apps/user_ldap/tests/LDAPProviderTest.php | 6 +- .../tests/Mapping/AbstractMappingTest.php | 3 +- .../tests/User/DeletedUsersIndexTest.php | 5 +- apps/user_ldap/tests/User_LDAPTest.php | 20 +-- .../lib/BackgroundJobs/Rotate.php | 4 +- apps/workflowengine/tests/ManagerTest.php | 5 +- 179 files changed, 1074 insertions(+), 770 deletions(-) diff --git a/apps/comments/lib/Search/LegacyProvider.php b/apps/comments/lib/Search/LegacyProvider.php index d78e5fe09f32a..a269c418d0657 100644 --- a/apps/comments/lib/Search/LegacyProvider.php +++ b/apps/comments/lib/Search/LegacyProvider.php @@ -14,7 +14,9 @@ use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IUser; +use OCP\IUserSession; use OCP\Search\Provider; +use OCP\Server; use function count; class LegacyProvider extends Provider { @@ -26,8 +28,8 @@ class LegacyProvider extends Provider { * @since 7.0.0 */ public function search($query): array { - $cm = \OC::$server->get(ICommentsManager::class); - $us = \OC::$server->getUserSession(); + $cm = Server::get(ICommentsManager::class); + $us = Server::get(IUserSession::class); $user = $us->getUser(); if (!$user instanceof IUser) { diff --git a/apps/comments/tests/Unit/AppInfo/ApplicationTest.php b/apps/comments/tests/Unit/AppInfo/ApplicationTest.php index 4b87982ab4511..91f8a9bcc998e 100644 --- a/apps/comments/tests/Unit/AppInfo/ApplicationTest.php +++ b/apps/comments/tests/Unit/AppInfo/ApplicationTest.php @@ -9,6 +9,8 @@ use OCA\Comments\AppInfo\Application; use OCA\Comments\Notification\Notifier; +use OCP\IUserSession; +use OCP\Server; use Test\TestCase; /** @@ -21,12 +23,12 @@ class ApplicationTest extends TestCase { protected function setUp(): void { parent::setUp(); - \OC::$server->getUserManager()->createUser('dummy', '456'); - \OC::$server->getUserSession()->setUser(\OC::$server->getUserManager()->get('dummy')); + Server::get(\OCP\User\IManager::class)->createUser('dummy', '456'); + Server::get(IUserSession::class)->setUser(Server::get(\OCP\User\IManager::class)->get('dummy')); } protected function tearDown(): void { - \OC::$server->getUserManager()->get('dummy')->delete(); + Server::get(\OCP\User\IManager::class)->get('dummy')->delete(); parent::tearDown(); } diff --git a/apps/contactsinteraction/tests/Db/RecentContactMapperTest.php b/apps/contactsinteraction/tests/Db/RecentContactMapperTest.php index a8e8ca3e1fb12..89e192d9da7d2 100644 --- a/apps/contactsinteraction/tests/Db/RecentContactMapperTest.php +++ b/apps/contactsinteraction/tests/Db/RecentContactMapperTest.php @@ -12,6 +12,7 @@ use OCA\ContactsInteraction\Db\RecentContactMapper; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IUser; +use OCP\Server; use Sabre\VObject\Component\VCard; use Sabre\VObject\UUIDUtil; use Test\TestCase; @@ -30,8 +31,8 @@ class RecentContactMapperTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->recentContactMapper = \OC::$server->get(RecentContactMapper::class); - $this->time = \OC::$server->get(ITimeFactory::class); + $this->recentContactMapper = Server::get(RecentContactMapper::class); + $this->time = Server::get(ITimeFactory::class); } protected function tearDown(): void { diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index ea6d2dcf40606..19c67ae125b65 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -20,38 +20,45 @@ use OCA\DAV\Connector\Sabre\MaintenancePlugin; use OCA\DAV\Connector\Sabre\Principal; use OCP\Accounts\IAccountManager; +use OCP\App\IAppManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IRequest; +use OCP\ISession; +use OCP\IUserSession; +use OCP\Security\Bruteforce\IThrottler; +use OCP\Security\ISecureRandom; use OCP\Server; use Psr\Log\LoggerInterface; $authBackend = new Auth( - \OC::$server->getSession(), - \OC::$server->getUserSession(), - \OC::$server->getRequest(), - \OC::$server->getTwoFactorAuthManager(), - \OC::$server->getBruteForceThrottler(), + Server::get(ISession::class), + Server::get(IUserSession::class), + Server::get(IRequest::class), + Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), + Server::get(IThrottler::class), 'principals/' ); $principalBackend = new Principal( - \OC::$server->getUserManager(), - \OC::$server->getGroupManager(), - \OC::$server->get(IAccountManager::class), - \OC::$server->getShareManager(), - \OC::$server->getUserSession(), - \OC::$server->getAppManager(), + Server::get(\OCP\User\IManager::class), + Server::get(\OCP\Group\IManager::class), + Server::get(IAccountManager::class), + Server::get(\OCP\Share\IManager::class), + Server::get(IUserSession::class), + Server::get(IAppManager::class), \OC::$server->query(ProxyMapper::class), - \OC::$server->get(KnownUserService::class), - \OC::$server->getConfig(), + Server::get(KnownUserService::class), + Server::get(IConfig::class), \OC::$server->getL10NFactory(), 'principals/' ); -$db = \OC::$server->getDatabaseConnection(); -$userManager = \OC::$server->getUserManager(); -$random = \OC::$server->getSecureRandom(); -$logger = \OC::$server->get(LoggerInterface::class); -$dispatcher = \OC::$server->get(IEventDispatcher::class); -$config = \OC::$server->get(IConfig::class); +$db = Server::get(IDBConnection::class); +$userManager = Server::get(\OCP\User\IManager::class); +$random = Server::get(ISecureRandom::class); +$logger = Server::get(LoggerInterface::class); +$dispatcher = Server::get(IEventDispatcher::class); +$config = Server::get(IConfig::class); $calDavBackend = new CalDavBackend( $db, @@ -61,12 +68,12 @@ $logger, $dispatcher, $config, - OC::$server->get(\OCA\DAV\CalDAV\Sharing\Backend::class), + Server::get(\OCA\DAV\CalDAV\Sharing\Backend::class), true ); -$debugging = \OC::$server->getConfig()->getSystemValue('debug', false); -$sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes'; +$debugging = Server::get(IConfig::class)->getSystemValue('debug', false); +$sendInvitations = Server::get(IConfig::class)->getAppValue('dav', 'sendInvitations', 'yes') === 'yes'; // Root nodes $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend); @@ -83,11 +90,11 @@ // Fire up server $server = new \Sabre\DAV\Server($nodes); $server::$exposeVersion = false; -$server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri()); +$server->httpRequest->setUrl(Server::get(IRequest::class)->getRequestUri()); $server->setBaseUri($baseuri); // Add plugins -$server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); +$server->addPlugin(new MaintenancePlugin(Server::get(IConfig::class), \OC::$server->getL10N('dav'))); $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend)); $server->addPlugin(new \Sabre\CalDAV\Plugin()); @@ -98,7 +105,7 @@ $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); -$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DefaultCalendarValidator::class))); +$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(Server::get(IConfig::class), Server::get(LoggerInterface::class), Server::get(DefaultCalendarValidator::class))); if ($sendInvitations) { $server->addPlugin(\OC::$server->query(IMipPlugin::class)); diff --git a/apps/dav/appinfo/v1/carddav.php b/apps/dav/appinfo/v1/carddav.php index dbcdacc27f0f6..1b11fe9d8bd65 100644 --- a/apps/dav/appinfo/v1/carddav.php +++ b/apps/dav/appinfo/v1/carddav.php @@ -23,49 +23,56 @@ use OCP\Accounts\IAccountManager; use OCP\App\IAppManager; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\IAppData; +use OCP\IConfig; +use OCP\IDBConnection; use OCP\IGroupManager; +use OCP\IRequest; +use OCP\ISession; +use OCP\IUserSession; +use OCP\Security\Bruteforce\IThrottler; use OCP\Server; use Psr\Log\LoggerInterface; use Sabre\CardDAV\Plugin; $authBackend = new Auth( - \OC::$server->getSession(), - \OC::$server->getUserSession(), - \OC::$server->getRequest(), - \OC::$server->getTwoFactorAuthManager(), - \OC::$server->getBruteForceThrottler(), + Server::get(ISession::class), + Server::get(IUserSession::class), + Server::get(IRequest::class), + Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), + Server::get(IThrottler::class), 'principals/' ); $principalBackend = new Principal( - \OC::$server->getUserManager(), - \OC::$server->getGroupManager(), - \OC::$server->get(IAccountManager::class), - \OC::$server->getShareManager(), - \OC::$server->getUserSession(), - \OC::$server->getAppManager(), + Server::get(\OCP\User\IManager::class), + Server::get(\OCP\Group\IManager::class), + Server::get(IAccountManager::class), + Server::get(\OCP\Share\IManager::class), + Server::get(IUserSession::class), + Server::get(IAppManager::class), \OC::$server->query(ProxyMapper::class), - \OC::$server->get(KnownUserService::class), - \OC::$server->getConfig(), + Server::get(KnownUserService::class), + Server::get(IConfig::class), \OC::$server->getL10NFactory(), 'principals/' ); -$db = \OC::$server->getDatabaseConnection(); +$db = Server::get(IDBConnection::class); $cardDavBackend = new CardDavBackend( $db, $principalBackend, - \OC::$server->getUserManager(), - \OC::$server->get(IEventDispatcher::class), - \OC::$server->get(\OCA\DAV\CardDAV\Sharing\Backend::class), + Server::get(\OCP\User\IManager::class), + Server::get(IEventDispatcher::class), + Server::get(\OCA\DAV\CardDAV\Sharing\Backend::class), ); -$debugging = \OC::$server->getConfig()->getSystemValue('debug', false); +$debugging = Server::get(IConfig::class)->getSystemValue('debug', false); // Root nodes $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend); $principalCollection->disableListing = !$debugging; // Disable listing $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class)); -$addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend, $pluginManager, \OC::$server->getUserSession()->getUser(), \OC::$server->get(IGroupManager::class)); +$addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend, $pluginManager, Server::get(IUserSession::class)->getUser(), Server::get(IGroupManager::class)); $addressBookRoot->disableListing = !$debugging; // Disable listing $nodes = [ @@ -76,10 +83,10 @@ // Fire up server $server = new \Sabre\DAV\Server($nodes); $server::$exposeVersion = false; -$server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri()); +$server->httpRequest->setUrl(Server::get(IRequest::class)->getRequestUri()); $server->setBaseUri($baseuri); // Add plugins -$server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); +$server->addPlugin(new MaintenancePlugin(Server::get(IConfig::class), \OC::$server->getL10N('dav'))); $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend)); $server->addPlugin(new Plugin()); @@ -91,10 +98,10 @@ $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin()); $server->addPlugin(new ImageExportPlugin(new PhotoCache( - \OC::$server->getAppDataDir('dav-photocache'), - \OC::$server->get(LoggerInterface::class) + Server::get(IAppData::class), + Server::get(LoggerInterface::class) ))); -$server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->get(LoggerInterface::class))); +$server->addPlugin(new ExceptionLoggerPlugin('carddav', Server::get(LoggerInterface::class))); $server->addPlugin(Server::get(CardDavRateLimitingPlugin::class)); $server->addPlugin(Server::get(CardDavValidatePlugin::class)); diff --git a/apps/dav/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php index dc74fe214afbb..b6c0fa17d64eb 100644 --- a/apps/dav/appinfo/v1/publicwebdav.php +++ b/apps/dav/appinfo/v1/publicwebdav.php @@ -18,6 +18,15 @@ use OCP\Constants; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IRootFolder; +use OCP\Files\Mount\IMountManager; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IPreview; +use OCP\IRequest; +use OCP\ISession; +use OCP\ITagManager; +use OCP\IUserSession; +use OCP\Security\Bruteforce\IThrottler; use OCP\Server; use Psr\Log\LoggerInterface; @@ -27,34 +36,34 @@ OC_App::loadApps($RUNTIME_APPTYPES); OC_Util::obEnd(); -\OC::$server->getSession()->close(); +Server::get(ISession::class)->close(); // Backends $authBackend = new LegacyPublicAuth( - \OC::$server->getRequest(), - \OC::$server->getShareManager(), - \OC::$server->getSession(), - \OC::$server->getBruteForceThrottler() + Server::get(IRequest::class), + Server::get(\OCP\Share\IManager::class), + Server::get(ISession::class), + Server::get(IThrottler::class) ); $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); /** @var IEventDispatcher $eventDispatcher */ -$eventDispatcher = \OC::$server->get(IEventDispatcher::class); +$eventDispatcher = Server::get(IEventDispatcher::class); $serverFactory = new ServerFactory( - \OC::$server->getConfig(), - \OC::$server->get(LoggerInterface::class), - \OC::$server->getDatabaseConnection(), - \OC::$server->getUserSession(), - \OC::$server->getMountManager(), - \OC::$server->getTagManager(), - \OC::$server->getRequest(), - \OC::$server->getPreviewManager(), + Server::get(IConfig::class), + Server::get(LoggerInterface::class), + Server::get(IDBConnection::class), + Server::get(IUserSession::class), + Server::get(IMountManager::class), + Server::get(ITagManager::class), + Server::get(IRequest::class), + Server::get(IPreview::class), $eventDispatcher, \OC::$server->getL10N('dav') ); -$requestUri = \OC::$server->getRequest()->getRequestUri(); +$requestUri = Server::get(IRequest::class)->getRequestUri(); $linkCheckPlugin = new PublicLinkCheckPlugin(); $filesDropPlugin = new FilesDropPlugin(); diff --git a/apps/dav/appinfo/v1/webdav.php b/apps/dav/appinfo/v1/webdav.php index 0faed7ccc947f..fe47ba7465298 100644 --- a/apps/dav/appinfo/v1/webdav.php +++ b/apps/dav/appinfo/v1/webdav.php @@ -11,7 +11,17 @@ use OCA\DAV\Connector\Sabre\ServerFactory; use OCA\DAV\Events\SabrePluginAddEvent; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Mount\IMountManager; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IPreview; +use OCP\IRequest; +use OCP\ISession; +use OCP\ITagManager; +use OCP\IUserSession; use OCP\SabrePluginEvent; +use OCP\Security\Bruteforce\IThrottler; +use OCP\Server; use Psr\Log\LoggerInterface; // no php execution timeout for webdav @@ -23,39 +33,39 @@ // Turn off output buffering to prevent memory problems \OC_Util::obEnd(); -$dispatcher = \OC::$server->get(IEventDispatcher::class); +$dispatcher = Server::get(IEventDispatcher::class); $serverFactory = new ServerFactory( - \OC::$server->getConfig(), - \OC::$server->get(LoggerInterface::class), - \OC::$server->getDatabaseConnection(), - \OC::$server->getUserSession(), - \OC::$server->getMountManager(), - \OC::$server->getTagManager(), - \OC::$server->getRequest(), - \OC::$server->getPreviewManager(), + Server::get(IConfig::class), + Server::get(LoggerInterface::class), + Server::get(IDBConnection::class), + Server::get(IUserSession::class), + Server::get(IMountManager::class), + Server::get(ITagManager::class), + Server::get(IRequest::class), + Server::get(IPreview::class), $dispatcher, \OC::$server->getL10N('dav') ); // Backends $authBackend = new Auth( - \OC::$server->getSession(), - \OC::$server->getUserSession(), - \OC::$server->getRequest(), - \OC::$server->getTwoFactorAuthManager(), - \OC::$server->getBruteForceThrottler(), + Server::get(ISession::class), + Server::get(IUserSession::class), + Server::get(IRequest::class), + Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), + Server::get(IThrottler::class), 'principals/' ); $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); $bearerAuthPlugin = new BearerAuth( - \OC::$server->getUserSession(), - \OC::$server->getSession(), - \OC::$server->getRequest() + Server::get(IUserSession::class), + Server::get(ISession::class), + Server::get(IRequest::class) ); $authPlugin->addBackend($bearerAuthPlugin); -$requestUri = \OC::$server->getRequest()->getRequestUri(); +$requestUri = Server::get(IRequest::class)->getRequestUri(); $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function () { // use the view for the logged in user diff --git a/apps/dav/appinfo/v2/direct.php b/apps/dav/appinfo/v2/direct.php index 5ba9570602acb..8f7b6647bd88a 100644 --- a/apps/dav/appinfo/v2/direct.php +++ b/apps/dav/appinfo/v2/direct.php @@ -9,6 +9,10 @@ use OCA\DAV\Db\DirectMapper; use OCA\DAV\Direct\ServerFactory; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Files\IRootFolder; +use OCP\IRequest; +use OCP\Security\Bruteforce\IThrottler; +use OCP\Server; // no php execution timeout for webdav if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) { @@ -19,18 +23,18 @@ // Turn off output buffering to prevent memory problems \OC_Util::obEnd(); -$requestUri = \OC::$server->getRequest()->getRequestUri(); +$requestUri = Server::get(IRequest::class)->getRequestUri(); /** @var ServerFactory $serverFactory */ $serverFactory = \OC::$server->query(ServerFactory::class); $server = $serverFactory->createServer( $baseuri, $requestUri, - \OC::$server->getRootFolder(), + Server::get(IRootFolder::class), \OC::$server->query(DirectMapper::class), \OC::$server->query(ITimeFactory::class), - \OC::$server->getBruteForceThrottler(), - \OC::$server->getRequest() + Server::get(IThrottler::class), + Server::get(IRequest::class) ); $server->exec(); diff --git a/apps/dav/appinfo/v2/remote.php b/apps/dav/appinfo/v2/remote.php index 28cfe338a9361..51d26b48a5a0f 100644 --- a/apps/dav/appinfo/v2/remote.php +++ b/apps/dav/appinfo/v2/remote.php @@ -1,6 +1,7 @@ getRequest(); +$request = \OCP\Server::get(IRequest::class); $server = new Server($request, $baseuri); $server->exec(); diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php index ae587c98965f8..95b1dd6876f54 100644 --- a/apps/dav/lib/AppInfo/Application.php +++ b/apps/dav/lib/AppInfo/Application.php @@ -20,8 +20,8 @@ use OCA\DAV\CalDAV\Reminder\NotificationProviderManager; use OCA\DAV\CalDAV\Reminder\Notifier; use OCA\DAV\Capabilities; - use OCA\DAV\CardDAV\ContactsManager; + use OCA\DAV\CardDAV\PhotoCache; use OCA\DAV\CardDAV\SyncService; use OCA\DAV\Events\AddressBookCreatedEvent; @@ -86,6 +86,7 @@ use OCP\Federation\Events\TrustedServerRemovedEvent; use OCP\Files\AppData\IAppDataFactory; use OCP\IUser; +use OCP\IUserSession; use OCP\Server; use OCP\User\Events\OutOfOfficeChangedEvent; use OCP\User\Events\OutOfOfficeClearedEvent; @@ -245,7 +246,7 @@ public function registerHooks(HookManager $hm, public function registerContactsManager(IContactsManager $cm, IAppContainer $container): void { $cm->register(function () use ($container, $cm): void { - $user = \OC::$server->getUserSession()->getUser(); + $user = Server::get(IUserSession::class)->getUser(); if (!is_null($user)) { $this->setupContactsProvider($cm, $container, $user->getUID()); } else { @@ -274,7 +275,7 @@ private function setupSystemContactsProvider(IContactsManager $contactsManager, public function registerCalendarManager(ICalendarManager $calendarManager, IAppContainer $container): void { $calendarManager->register(function () use ($container, $calendarManager): void { - $user = \OC::$server->getUserSession()->getUser(); + $user = Server::get(IUserSession::class)->getUser(); if ($user !== null) { $this->setupCalendarProvider($calendarManager, $container, $user->getUID()); } diff --git a/apps/dav/lib/Avatars/RootCollection.php b/apps/dav/lib/Avatars/RootCollection.php index d7cdb92c6be7d..ec88c65793f85 100644 --- a/apps/dav/lib/Avatars/RootCollection.php +++ b/apps/dav/lib/Avatars/RootCollection.php @@ -7,6 +7,7 @@ namespace OCA\DAV\Avatars; use OCP\IAvatarManager; +use OCP\Server; use Sabre\DAVACL\AbstractPrincipalCollection; class RootCollection extends AbstractPrincipalCollection { @@ -22,7 +23,7 @@ class RootCollection extends AbstractPrincipalCollection { * @return AvatarHome */ public function getChildForPrincipal(array $principalInfo) { - $avatarManager = \OC::$server->get(IAvatarManager::class); + $avatarManager = Server::get(IAvatarManager::class); return new AvatarHome($principalInfo, $avatarManager); } diff --git a/apps/dav/lib/CalDAV/CalendarHome.php b/apps/dav/lib/CalDAV/CalendarHome.php index c74c07bc4ab15..89b78ba9007c9 100644 --- a/apps/dav/lib/CalDAV/CalendarHome.php +++ b/apps/dav/lib/CalDAV/CalendarHome.php @@ -11,8 +11,10 @@ use OCA\DAV\CalDAV\Integration\ExternalCalendar; use OCA\DAV\CalDAV\Integration\ICalendarProvider; use OCA\DAV\CalDAV\Trashbin\TrashbinHome; +use OCP\App\IAppManager; use OCP\IConfig; use OCP\IL10N; +use OCP\Server; use Psr\Log\LoggerInterface; use Sabre\CalDAV\Backend\BackendInterface; use Sabre\CalDAV\Backend\NotificationSupport; @@ -45,10 +47,10 @@ public function __construct( ) { parent::__construct($caldavBackend, $principalInfo); $this->l10n = \OC::$server->getL10N('dav'); - $this->config = \OC::$server->getConfig(); + $this->config = Server::get(IConfig::class); $this->pluginManager = new PluginManager( \OC::$server, - \OC::$server->getAppManager() + Server::get(IAppManager::class) ); } diff --git a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php index 32a3eb0ae158a..3d650a4a059f5 100644 --- a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php +++ b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php @@ -20,8 +20,10 @@ use OCA\DAV\Events\SabrePluginAuthInitEvent; use OCA\DAV\RootCollection; use OCA\Theming\ThemingDefaults; +use OCP\App\IAppManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; +use OCP\IURLGenerator; use OCP\Server; use Psr\Log\LoggerInterface; use Sabre\VObject\ITip\Message; @@ -42,7 +44,7 @@ public function __construct(bool $public = true) { $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); // Add maintenance plugin - $this->server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); + $this->server->addPlugin(new MaintenancePlugin(Server::get(IConfig::class), \OC::$server->getL10N('dav'))); // Set URL explicitly due to reverse-proxy situations $this->server->httpRequest->setUrl($baseUri); @@ -79,13 +81,13 @@ public function __construct(bool $public = true) { // calendar plugins $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DefaultCalendarValidator::class))); + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(Server::get(IConfig::class), Server::get(LoggerInterface::class), Server::get(DefaultCalendarValidator::class))); $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); //$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); $this->server->addPlugin(new PublishPlugin( - \OC::$server->getConfig(), - \OC::$server->getURLGenerator() + Server::get(IConfig::class), + Server::get(IURLGenerator::class) )); // wait with registering these until auth is handled and the filesystem is setup @@ -93,7 +95,7 @@ public function __construct(bool $public = true) { // register plugins from apps $pluginManager = new PluginManager( \OC::$server, - \OC::$server->getAppManager() + Server::get(IAppManager::class) ); foreach ($pluginManager->getAppPlugins() as $appPlugin) { $this->server->addPlugin($appPlugin); diff --git a/apps/dav/lib/CardDAV/UserAddressBooks.php b/apps/dav/lib/CardDAV/UserAddressBooks.php index eaf393dec0490..e29e52e77dffd 100644 --- a/apps/dav/lib/CardDAV/UserAddressBooks.php +++ b/apps/dav/lib/CardDAV/UserAddressBooks.php @@ -56,7 +56,7 @@ public function getChildren() { $this->l10n = \OC::$server->getL10N('dav'); } if ($this->config === null) { - $this->config = \OC::$server->getConfig(); + $this->config = Server::get(IConfig::class); } /** @var string|array $principal */ @@ -82,8 +82,8 @@ public function getChildren() { $trustedServers = null; $request = null; try { - $trustedServers = \OC::$server->get(TrustedServers::class); - $request = \OC::$server->get(IRequest::class); + $trustedServers = Server::get(TrustedServers::class); + $request = Server::get(IRequest::class); } catch (QueryException|NotFoundExceptionInterface|ContainerExceptionInterface $e) { // nothing to do, the request / trusted servers don't exist } diff --git a/apps/dav/lib/Command/CreateCalendar.php b/apps/dav/lib/Command/CreateCalendar.php index 5339d9d1c79f5..4e9beeadb6240 100644 --- a/apps/dav/lib/Command/CreateCalendar.php +++ b/apps/dav/lib/Command/CreateCalendar.php @@ -13,11 +13,15 @@ use OCA\DAV\CalDAV\Sharing\Backend; use OCA\DAV\Connector\Sabre\Principal; use OCP\Accounts\IAccountManager; +use OCP\App\IAppManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUserManager; +use OCP\IUserSession; +use OCP\Security\ISecureRandom; +use OCP\Server; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -53,19 +57,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int $principalBackend = new Principal( $this->userManager, $this->groupManager, - \OC::$server->get(IAccountManager::class), - \OC::$server->getShareManager(), - \OC::$server->getUserSession(), - \OC::$server->getAppManager(), + Server::get(IAccountManager::class), + Server::get(\OCP\Share\IManager::class), + Server::get(IUserSession::class), + Server::get(IAppManager::class), \OC::$server->query(ProxyMapper::class), - \OC::$server->get(KnownUserService::class), - \OC::$server->getConfig(), + Server::get(KnownUserService::class), + Server::get(IConfig::class), \OC::$server->getL10NFactory(), ); - $random = \OC::$server->getSecureRandom(); - $logger = \OC::$server->get(LoggerInterface::class); - $dispatcher = \OC::$server->get(IEventDispatcher::class); - $config = \OC::$server->get(IConfig::class); + $random = Server::get(ISecureRandom::class); + $logger = Server::get(LoggerInterface::class); + $dispatcher = Server::get(IEventDispatcher::class); + $config = Server::get(IConfig::class); $name = $input->getArgument('name'); $caldav = new CalDavBackend( $this->dbConnection, @@ -75,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $logger, $dispatcher, $config, - \OC::$server->get(Backend::class), + Server::get(Backend::class), ); $caldav->createCalendar("principals/users/$user", $name, []); return self::SUCCESS; diff --git a/apps/dav/lib/Connector/Sabre/Directory.php b/apps/dav/lib/Connector/Sabre/Directory.php index ebef7f91ee06d..8b46907452ea7 100644 --- a/apps/dav/lib/Connector/Sabre/Directory.php +++ b/apps/dav/lib/Connector/Sabre/Directory.php @@ -18,6 +18,7 @@ use OCP\Files\Folder; use OCP\Files\ForbiddenException; use OCP\Files\InvalidPathException; +use OCP\Files\Mount\IMountManager; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\Files\StorageNotAvailableException; @@ -232,8 +233,8 @@ public function getChildren() { } $nodes = []; - $request = \OC::$server->get(IRequest::class); - $l10nFactory = \OC::$server->get(IFactory::class); + $request = Server::get(IRequest::class); + $l10nFactory = Server::get(IFactory::class); $l10n = $l10nFactory->get(Application::APP_ID); foreach ($folderContent as $info) { $node = $this->getChild($info->getName(), $info, $request, $l10n); @@ -286,7 +287,7 @@ public function delete() { } private function getLogger(): LoggerInterface { - return \OC::$server->get(LoggerInterface::class); + return Server::get(LoggerInterface::class); } /** @@ -380,7 +381,7 @@ public function moveInto($targetName, $fullSourcePath, INode $sourceNode) { $sourcePath = $sourceNode->getPath(); $isMovableMount = false; - $sourceMount = \OC::$server->getMountManager()->find($this->fileView->getAbsolutePath($sourcePath)); + $sourceMount = Server::get(IMountManager::class)->find($this->fileView->getAbsolutePath($sourcePath)); $internalPath = $sourceMount->getInternalPath($this->fileView->getAbsolutePath($sourcePath)); if ($sourceMount instanceof MoveableMount && $internalPath === '') { $isMovableMount = true; diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index d6bd6369c9d0b..13cf8d5b0c027 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -24,6 +24,7 @@ use OCP\Files\FileInfo; use OCP\Files\ForbiddenException; use OCP\Files\GenericFileException; +use OCP\Files\IMimeTypeDetector; use OCP\Files\InvalidContentException; use OCP\Files\InvalidPathException; use OCP\Files\LockNotAcquiredException; @@ -31,6 +32,7 @@ use OCP\Files\NotPermittedException; use OCP\Files\Storage\IWriteStreamStorage; use OCP\Files\StorageNotAvailableException; +use OCP\IConfig; use OCP\IL10N; use OCP\IRequest; use OCP\L10N\IFactory as IL10NFactory; @@ -67,14 +69,14 @@ public function __construct(View $view, FileInfo $info, ?IManager $shareManager } else { // Querying IL10N directly results in a dependency loop /** @var IL10NFactory $l10nFactory */ - $l10nFactory = \OC::$server->get(IL10NFactory::class); + $l10nFactory = Server::get(IL10NFactory::class); $this->l10n = $l10nFactory->get(Application::APP_ID); } if (isset($request)) { $this->request = $request; } else { - $this->request = \OC::$server->get(IRequest::class); + $this->request = Server::get(IRequest::class); } } @@ -227,7 +229,7 @@ public function put($data) { } else { $target = $partStorage->fopen($internalPartPath, 'wb'); if ($target === false) { - \OC::$server->get(LoggerInterface::class)->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']); + Server::get(LoggerInterface::class)->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']); // because we have no clue about the cause we can only throw back a 500/Internal Server Error throw new Exception($this->l10n->t('Could not write file contents')); } @@ -274,9 +276,9 @@ public function put($data) { } } catch (\Exception $e) { if ($e instanceof LockedException) { - \OC::$server->get(LoggerInterface::class)->debug($e->getMessage(), ['exception' => $e]); + Server::get(LoggerInterface::class)->debug($e->getMessage(), ['exception' => $e]); } else { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); + Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); } if ($needsPartFile) { @@ -317,7 +319,7 @@ public function put($data) { $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath); $fileExists = $storage->file_exists($internalPath); if ($renameOkay === false || $fileExists === false) { - \OC::$server->get(LoggerInterface::class)->error('renaming part file to final file failed $renameOkay: ' . ($renameOkay ? 'true' : 'false') . ', $fileExists: ' . ($fileExists ? 'true' : 'false') . ')', ['app' => 'webdav']); + Server::get(LoggerInterface::class)->error('renaming part file to final file failed $renameOkay: ' . ($renameOkay ? 'true' : 'false') . ', $fileExists: ' . ($fileExists ? 'true' : 'false') . ')', ['app' => 'webdav']); throw new Exception($this->l10n->t('Could not rename part file to final file')); } } catch (ForbiddenException $ex) { @@ -384,7 +386,7 @@ public function put($data) { } private function getPartFileBasePath($path) { - $partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true); + $partFileInStorage = Server::get(IConfig::class)->getSystemValue('part_file_in_storage', true); if ($partFileInStorage) { return $path; } else { @@ -476,7 +478,7 @@ public function get() { // comparing current file size with the one in DB // if different, fix DB and refresh cache. if ($this->getSize() !== $this->fileView->filesize($this->getPath())) { - $logger = \OC::$server->get(LoggerInterface::class); + $logger = Server::get(LoggerInterface::class); $logger->warning('fixing cached size of file id=' . $this->getId()); $this->getFileInfo()->getStorage()->getUpdater()->update($this->getFileInfo()->getInternalPath()); @@ -535,7 +537,7 @@ public function getContentType() { if ($this->request->getMethod() === 'PROPFIND') { return $mimeType; } - return \OC::$server->getMimeTypeDetector()->getSecureMimeType($mimeType); + return Server::get(IMimeTypeDetector::class)->getSecureMimeType($mimeType); } /** diff --git a/apps/dav/lib/Connector/Sabre/Node.php b/apps/dav/lib/Connector/Sabre/Node.php index 4ee6283b0d2c2..505e6b5eda466 100644 --- a/apps/dav/lib/Connector/Sabre/Node.php +++ b/apps/dav/lib/Connector/Sabre/Node.php @@ -20,6 +20,7 @@ use OCP\Files\NotFoundException; use OCP\Files\Storage\ISharedStorage; use OCP\Files\StorageNotAvailableException; +use OCP\Server; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; @@ -60,14 +61,14 @@ public function __construct( if ($shareManager) { $this->shareManager = $shareManager; } else { - $this->shareManager = \OC::$server->getShareManager(); + $this->shareManager = Server::get(\OCP\Share\IManager::class); } if ($info instanceof Folder || $info instanceof File) { $this->node = $info; } else { // The Node API assumes that the view passed doesn't have a fake root - $rootView = \OC::$server->get(View::class); - $root = \OC::$server->get(IRootFolder::class); + $rootView = Server::get(View::class); + $root = Server::get(IRootFolder::class); if ($info->getType() === FileInfo::TYPE_FOLDER) { $this->node = new Folder($root, $rootView, $this->fileView->getAbsolutePath($this->path), $info); } else { @@ -82,8 +83,8 @@ protected function refreshInfo(): void { throw new \Sabre\DAV\Exception('Failed to get fileinfo for ' . $this->path); } $this->info = $info; - $root = \OC::$server->get(IRootFolder::class); - $rootView = \OC::$server->get(View::class); + $root = Server::get(IRootFolder::class); + $rootView = Server::get(View::class); if ($this->info->getType() === FileInfo::TYPE_FOLDER) { $this->node = new Folder($root, $rootView, $this->path, $this->info); } else { diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php index dc6384daefe46..b1af8b15b1299 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -14,6 +14,8 @@ use OCA\DAV\DAV\ViewOnlyPlugin; use OCA\DAV\Files\BrowserErrorPagePlugin; use OCA\Theming\ThemingDefaults; +use OCP\App\IAppManager; +use OCP\Comments\ICommentsManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Folder; use OCP\Files\IFilenameValidator; @@ -26,6 +28,8 @@ use OCP\ITagManager; use OCP\IUserSession; use OCP\SabrePluginEvent; +use OCP\SystemTag\ISystemTagManager; +use OCP\SystemTag\ISystemTagObjectMapper; use Psr\Log\LoggerInterface; use Sabre\DAV\Auth\Plugin; @@ -141,19 +145,19 @@ public function createServer(string $baseUri, $objectTree, $this->userSession, $userFolder, - \OC::$server->getShareManager() + \OCP\Server::get(\OCP\Share\IManager::class) )); - $server->addPlugin(new CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); + $server->addPlugin(new CommentPropertiesPlugin(\OCP\Server::get(ICommentsManager::class), $this->userSession)); $server->addPlugin(new FilesReportPlugin( $objectTree, $view, - \OC::$server->getSystemTagManager(), - \OC::$server->getSystemTagObjectMapper(), - \OC::$server->getTagManager(), + \OCP\Server::get(ISystemTagManager::class), + \OCP\Server::get(ISystemTagObjectMapper::class), + \OCP\Server::get(ITagManager::class), $this->userSession, - \OC::$server->getGroupManager(), + \OCP\Server::get(\OCP\Group\IManager::class), $userFolder, - \OC::$server->getAppManager() + \OCP\Server::get(IAppManager::class) )); // custom properties plugin must be the last one $server->addPlugin( @@ -163,7 +167,7 @@ public function createServer(string $baseUri, $objectTree, $this->databaseConnection, $this->userSession->getUser(), - \OC::$server->get(DefaultCalendarValidator::class), + \OCP\Server::get(DefaultCalendarValidator::class), ) ) ); @@ -175,7 +179,7 @@ public function createServer(string $baseUri, $this->eventDispatcher->dispatchTyped($event); $pluginManager = new PluginManager( \OC::$server, - \OC::$server->getAppManager() + \OCP\Server::get(IAppManager::class) ); foreach ($pluginManager->getAppPlugins() as $appPlugin) { $server->addPlugin($appPlugin); diff --git a/apps/dav/lib/Files/BrowserErrorPagePlugin.php b/apps/dav/lib/Files/BrowserErrorPagePlugin.php index 46598db2040c4..1491e1a89b1d1 100644 --- a/apps/dav/lib/Files/BrowserErrorPagePlugin.php +++ b/apps/dav/lib/Files/BrowserErrorPagePlugin.php @@ -77,7 +77,7 @@ public function logException(\Throwable $ex): void { * @return bool|string */ public function generateBody(int $httpCode) { - $request = \OC::$server->getRequest(); + $request = \OCP\Server::get(IRequest::class); $templateName = 'exception'; if ($httpCode === 403 || $httpCode === 404) { diff --git a/apps/dav/lib/Files/RootCollection.php b/apps/dav/lib/Files/RootCollection.php index d538d15ec1b75..a11bea72c598f 100644 --- a/apps/dav/lib/Files/RootCollection.php +++ b/apps/dav/lib/Files/RootCollection.php @@ -8,6 +8,8 @@ namespace OCA\DAV\Files; use OCP\Files\FileInfo; +use OCP\IUserSession; +use OCP\Server; use Sabre\DAV\INode; use Sabre\DAV\SimpleCollection; use Sabre\DAVACL\AbstractPrincipalCollection; @@ -26,7 +28,7 @@ class RootCollection extends AbstractPrincipalCollection { */ public function getChildForPrincipal(array $principalInfo) { [,$name] = \Sabre\Uri\split($principalInfo['uri']); - $user = \OC::$server->getUserSession()->getUser(); + $user = Server::get(IUserSession::class)->getUser(); if (is_null($user) || $name !== $user->getUID()) { // a user is only allowed to see their own home contents, so in case another collection // is accessed, we return a simple empty collection for now diff --git a/apps/dav/lib/HookManager.php b/apps/dav/lib/HookManager.php index 9f4bc95d89b11..1ad1f733d3488 100644 --- a/apps/dav/lib/HookManager.php +++ b/apps/dav/lib/HookManager.php @@ -13,6 +13,7 @@ use OCP\Defaults; use OCP\IUser; use OCP\IUserManager; +use OCP\Server; use OCP\Util; use Psr\Log\LoggerInterface; @@ -44,22 +45,22 @@ public function setup() { 'post_createUser', $this, 'postCreateUser'); - \OC::$server->getUserManager()->listen('\OC\User', 'assignedUserId', function ($uid): void { + Server::get(\OCP\User\IManager::class)->listen('\OC\User', 'assignedUserId', function ($uid): void { $this->postCreateUser(['uid' => $uid]); }); Util::connectHook('OC_User', 'pre_deleteUser', $this, 'preDeleteUser'); - \OC::$server->getUserManager()->listen('\OC\User', 'preUnassignedUserId', [$this, 'preUnassignedUserId']); + Server::get(\OCP\User\IManager::class)->listen('\OC\User', 'preUnassignedUserId', [$this, 'preUnassignedUserId']); Util::connectHook('OC_User', 'post_deleteUser', $this, 'postDeleteUser'); - \OC::$server->getUserManager()->listen('\OC\User', 'postUnassignedUserId', function ($uid): void { + Server::get(\OCP\User\IManager::class)->listen('\OC\User', 'postUnassignedUserId', function ($uid): void { $this->postDeleteUser(['uid' => $uid]); }); - \OC::$server->getUserManager()->listen('\OC\User', 'postUnassignedUserId', [$this, 'postUnassignedUserId']); + Server::get(\OCP\User\IManager::class)->listen('\OC\User', 'postUnassignedUserId', [$this, 'postUnassignedUserId']); Util::connectHook('OC_User', 'changeUser', $this, 'changeUser'); } @@ -138,7 +139,7 @@ public function firstLogin(?IUser $user = null) { 'components' => 'VEVENT' ]); } catch (\Exception $e) { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); + Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); } } if ($this->cardDav->getAddressBooksForUserCount($principal) === 0) { @@ -147,7 +148,7 @@ public function firstLogin(?IUser $user = null) { '{DAV:}displayname' => CardDavBackend::PERSONAL_ADDRESSBOOK_NAME, ]); } catch (\Exception $e) { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); + Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); } } } diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php index 751ab17bb7aa6..8d4d2e561c542 100644 --- a/apps/dav/lib/RootCollection.php +++ b/apps/dav/lib/RootCollection.php @@ -30,38 +30,44 @@ use OCP\Accounts\IAccountManager; use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Comments\ICommentsManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IRootFolder; use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IUserSession; +use OCP\Security\ISecureRandom; use OCP\Server; +use OCP\SystemTag\ISystemTagManager; +use OCP\SystemTag\ISystemTagObjectMapper; use Psr\Log\LoggerInterface; use Sabre\DAV\SimpleCollection; class RootCollection extends SimpleCollection { public function __construct() { $l10n = \OC::$server->getL10N('dav'); - $random = \OC::$server->getSecureRandom(); - $logger = \OC::$server->get(LoggerInterface::class); - $userManager = \OC::$server->getUserManager(); - $userSession = \OC::$server->getUserSession(); - $groupManager = \OC::$server->getGroupManager(); - $shareManager = \OC::$server->getShareManager(); - $db = \OC::$server->getDatabaseConnection(); - $dispatcher = \OC::$server->get(IEventDispatcher::class); - $config = \OC::$server->get(IConfig::class); + $random = Server::get(ISecureRandom::class); + $logger = Server::get(LoggerInterface::class); + $userManager = Server::get(\OCP\User\IManager::class); + $userSession = Server::get(IUserSession::class); + $groupManager = Server::get(\OCP\Group\IManager::class); + $shareManager = Server::get(\OCP\Share\IManager::class); + $db = Server::get(IDBConnection::class); + $dispatcher = Server::get(IEventDispatcher::class); + $config = Server::get(IConfig::class); $proxyMapper = \OC::$server->query(ProxyMapper::class); $rootFolder = Server::get(IRootFolder::class); $userPrincipalBackend = new Principal( $userManager, $groupManager, - \OC::$server->get(IAccountManager::class), + Server::get(IAccountManager::class), $shareManager, - \OC::$server->getUserSession(), - \OC::$server->getAppManager(), + Server::get(IUserSession::class), + Server::get(IAppManager::class), $proxyMapper, - \OC::$server->get(KnownUserService::class), - \OC::$server->getConfig(), + Server::get(KnownUserService::class), + Server::get(IConfig::class), \OC::$server->getL10NFactory() ); @@ -80,7 +86,7 @@ public function __construct() { $systemPrincipals->disableListing = $disableListing; $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); - $calendarSharingBackend = \OC::$server->get(Backend::class); + $calendarSharingBackend = Server::get(Backend::class); $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); $filesCollection->disableListing = $disableListing; @@ -107,23 +113,23 @@ public function __construct() { $systemTagCollection = Server::get(SystemTagsByIdCollection::class); $systemTagRelationsCollection = new SystemTagsRelationsCollection( - \OC::$server->getSystemTagManager(), - \OC::$server->getSystemTagObjectMapper(), - \OC::$server->getUserSession(), + Server::get(ISystemTagManager::class), + Server::get(ISystemTagObjectMapper::class), + Server::get(IUserSession::class), $groupManager, $dispatcher, $rootFolder, ); $systemTagInUseCollection = Server::get(SystemTagsInUseCollection::class); $commentsCollection = new Comments\RootCollection( - \OC::$server->getCommentsManager(), + Server::get(ICommentsManager::class), $userManager, - \OC::$server->getUserSession(), + Server::get(IUserSession::class), $dispatcher, $logger ); - $contactsSharingBackend = \OC::$server->get(\OCA\DAV\CardDAV\Sharing\Backend::class); + $contactsSharingBackend = Server::get(\OCA\DAV\CardDAV\Sharing\Backend::class); $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class)); $usersCardDavBackend = new CardDavBackend( diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index f07927ff0f95b..f3dc4e21a574c 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -64,22 +64,33 @@ use OCA\DAV\Upload\ChunkingPlugin; use OCA\DAV\Upload\ChunkingV2Plugin; use OCA\Theming\ThemingDefaults; +use OCP\App\IAppManager; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Comments\ICommentsManager; use OCP\Defaults; use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\IAppData; use OCP\Files\IFilenameValidator; +use OCP\Files\IRootFolder; use OCP\FilesMetadata\IFilesMetadataManager; use OCP\IAppConfig; use OCP\ICacheFactory; use OCP\IConfig; +use OCP\IDBConnection; use OCP\IPreview; use OCP\IRequest; +use OCP\ISession; +use OCP\ITagManager; +use OCP\IURLGenerator; use OCP\IUserSession; use OCP\Mail\IMailer; use OCP\Profiler\IProfiler; use OCP\SabrePluginEvent; +use OCP\Security\Bruteforce\IThrottler; +use OCP\SystemTag\ISystemTagManager; +use OCP\SystemTag\ISystemTagObjectMapper; use Psr\Log\LoggerInterface; use Sabre\CardDAV\VCFExportPlugin; use Sabre\DAV\Auth\Plugin; @@ -94,10 +105,10 @@ public function __construct( private IRequest $request, private string $baseUri, ) { - $this->profiler = \OC::$server->get(IProfiler::class); + $this->profiler = \OCP\Server::get(IProfiler::class); if ($this->profiler->isEnabled()) { /** @var IEventLogger $eventLogger */ - $eventLogger = \OC::$server->get(IEventLogger::class); + $eventLogger = \OCP\Server::get(IEventLogger::class); $eventLogger->start('runtime', 'DAV Runtime'); } @@ -108,17 +119,17 @@ public function __construct( $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); // Add maintenance plugin - $this->server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); + $this->server->addPlugin(new MaintenancePlugin(\OCP\Server::get(IConfig::class), \OC::$server->getL10N('dav'))); $this->server->addPlugin(new AppleQuirksPlugin()); // Backends $authBackend = new Auth( - \OC::$server->getSession(), - \OC::$server->getUserSession(), - \OC::$server->getRequest(), - \OC::$server->getTwoFactorAuthManager(), - \OC::$server->getBruteForceThrottler() + \OCP\Server::get(ISession::class), + \OCP\Server::get(IUserSession::class), + \OCP\Server::get(IRequest::class), + \OCP\Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), + \OCP\Server::get(IThrottler::class) ); // Set URL explicitly due to reverse-proxy situations @@ -143,16 +154,16 @@ public function __construct( $eventDispatcher->dispatchTyped($newAuthEvent); $bearerAuthBackend = new BearerAuth( - \OC::$server->getUserSession(), - \OC::$server->getSession(), - \OC::$server->getRequest() + \OCP\Server::get(IUserSession::class), + \OCP\Server::get(ISession::class), + \OCP\Server::get(IRequest::class) ); $authPlugin->addBackend($bearerAuthBackend); // because we are throwing exceptions this plugin has to be the last one $authPlugin->addBackend($authBackend); // debugging - if (\OC::$server->getConfig()->getSystemValue('debug', false)) { + if (\OCP\Server::get(IConfig::class)->getSystemValue('debug', false)) { $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); } else { $this->server->addPlugin(new DummyGetResponsePlugin()); @@ -174,21 +185,21 @@ public function __construct( // calendar plugins if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class))); $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); - $this->server->addPlugin(new ICSExportPlugin(\OC::$server->getConfig(), $logger)); - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DefaultCalendarValidator::class))); + $this->server->addPlugin(new ICSExportPlugin(\OCP\Server::get(IConfig::class), $logger)); + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OCP\Server::get(IConfig::class), \OCP\Server::get(LoggerInterface::class), \OCP\Server::get(DefaultCalendarValidator::class))); - $this->server->addPlugin(\OC::$server->get(\OCA\DAV\CalDAV\Trashbin\Plugin::class)); + $this->server->addPlugin(\OCP\Server::get(\OCA\DAV\CalDAV\Trashbin\Plugin::class)); $this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($this->request)); - if (\OC::$server->getConfig()->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes') { + if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes') { $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); } $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); $this->server->addPlugin(new PublishPlugin( - \OC::$server->getConfig(), - \OC::$server->getURLGenerator() + \OCP\Server::get(IConfig::class), + \OCP\Server::get(IURLGenerator::class) )); $this->server->addPlugin(\OCP\Server::get(RateLimitingPlugin::class)); @@ -197,13 +208,13 @@ public function __construct( // addressbook plugins if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class))); $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); $this->server->addPlugin(new VCFExportPlugin()); $this->server->addPlugin(new MultiGetExportPlugin()); $this->server->addPlugin(new HasPhotoPlugin()); $this->server->addPlugin(new ImageExportPlugin(new PhotoCache( - \OC::$server->getAppDataDir('dav-photocache'), + \OCP\Server::get(IAppData::class), $logger) )); @@ -212,16 +223,16 @@ public function __construct( } // system tags plugins - $this->server->addPlugin(\OC::$server->get(SystemTagPlugin::class)); + $this->server->addPlugin(\OCP\Server::get(SystemTagPlugin::class)); // comments plugin $this->server->addPlugin(new CommentsPlugin( - \OC::$server->getCommentsManager(), - \OC::$server->getUserSession() + \OCP\Server::get(ICommentsManager::class), + \OCP\Server::get(IUserSession::class) )); $this->server->addPlugin(new CopyEtagHeaderPlugin()); - $this->server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class))); + $this->server->addPlugin(new RequestIdHeaderPlugin(\OCP\Server::get(IRequest::class))); $this->server->addPlugin(new ChunkingV2Plugin(\OCP\Server::get(ICacheFactory::class))); $this->server->addPlugin(new ChunkingPlugin()); $this->server->addPlugin(new ZipFolderPlugin( @@ -261,7 +272,7 @@ public function __construct( )); // custom properties plugin must be the last one - $userSession = \OC::$server->getUserSession(); + $userSession = \OCP\Server::get(IUserSession::class); $user = $userSession->getUser(); if ($user !== null) { $view = Filesystem::getView(); @@ -285,9 +296,9 @@ public function __construct( new CustomPropertiesBackend( $this->server, $this->server->tree, - \OC::$server->getDatabaseConnection(), - \OC::$server->getUserSession()->getUser(), - \OC::$server->get(DefaultCalendarValidator::class), + \OCP\Server::get(IDBConnection::class), + \OCP\Server::get(IUserSession::class)->getUser(), + \OCP\Server::get(DefaultCalendarValidator::class), ) ) ); @@ -297,7 +308,7 @@ public function __construct( } $this->server->addPlugin( new TagsPlugin( - $this->server->tree, \OC::$server->getTagManager(), \OC::$server->get(IEventDispatcher::class), \OC::$server->get(IUserSession::class) + $this->server->tree, \OCP\Server::get(ITagManager::class), \OCP\Server::get(IEventDispatcher::class), \OCP\Server::get(IUserSession::class) ) ); @@ -311,20 +322,20 @@ public function __construct( $shareManager, )); $this->server->addPlugin(new CommentPropertiesPlugin( - \OC::$server->getCommentsManager(), + \OCP\Server::get(ICommentsManager::class), $userSession )); - if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { + if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { $this->server->addPlugin(new IMipPlugin( - \OC::$server->get(IAppConfig::class), - \OC::$server->get(IMailer::class), - \OC::$server->get(LoggerInterface::class), - \OC::$server->get(ITimeFactory::class), - \OC::$server->get(Defaults::class), + \OCP\Server::get(IAppConfig::class), + \OCP\Server::get(IMailer::class), + \OCP\Server::get(LoggerInterface::class), + \OCP\Server::get(ITimeFactory::class), + \OCP\Server::get(Defaults::class), $userSession, - \OC::$server->get(IMipService::class), - \OC::$server->get(EventComparisonService::class), - \OC::$server->get(\OCP\Mail\Provider\IManager::class) + \OCP\Server::get(IMipService::class), + \OCP\Server::get(EventComparisonService::class), + \OCP\Server::get(\OCP\Mail\Provider\IManager::class) )); } $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); @@ -332,18 +343,18 @@ public function __construct( $this->server->addPlugin(new FilesReportPlugin( $this->server->tree, $view, - \OC::$server->getSystemTagManager(), - \OC::$server->getSystemTagObjectMapper(), - \OC::$server->getTagManager(), + \OCP\Server::get(ISystemTagManager::class), + \OCP\Server::get(ISystemTagObjectMapper::class), + \OCP\Server::get(ITagManager::class), $userSession, - \OC::$server->getGroupManager(), + \OCP\Server::get(\OCP\Group\IManager::class), $userFolder, - \OC::$server->getAppManager() + \OCP\Server::get(IAppManager::class) )); $lazySearchBackend->setBackend(new FileSearchBackend( $this->server->tree, $user, - \OC::$server->getRootFolder(), + \OCP\Server::get(IRootFolder::class), $shareManager, $view, \OCP\Server::get(IFilesMetadataManager::class) @@ -356,15 +367,15 @@ public function __construct( ); } $this->server->addPlugin(new EnablePlugin( - \OC::$server->getConfig(), + \OCP\Server::get(IConfig::class), \OC::$server->query(BirthdayService::class), $user )); $this->server->addPlugin(new AppleProvisioningPlugin( - \OC::$server->getUserSession(), - \OC::$server->getURLGenerator(), - \OC::$server->getThemingDefaults(), - \OC::$server->getRequest(), + \OCP\Server::get(IUserSession::class), + \OCP\Server::get(IURLGenerator::class), + \OCP\Server::get(ThemingDefaults::class), + \OCP\Server::get(IRequest::class), \OC::$server->getL10N('dav'), function () { return UUIDUtil::getUUID(); @@ -375,7 +386,7 @@ function () { // register plugins from apps $pluginManager = new PluginManager( \OC::$server, - \OC::$server->getAppManager() + \OCP\Server::get(IAppManager::class) ); foreach ($pluginManager->getAppPlugins() as $appPlugin) { $this->server->addPlugin($appPlugin); @@ -392,13 +403,13 @@ function () { public function exec() { /** @var IEventLogger $eventLogger */ - $eventLogger = \OC::$server->get(IEventLogger::class); + $eventLogger = \OCP\Server::get(IEventLogger::class); $eventLogger->start('dav_server_exec', ''); $this->server->start(); $eventLogger->end('dav_server_exec'); if ($this->profiler->isEnabled()) { $eventLogger->end('runtime'); - $profile = $this->profiler->collect(\OC::$server->get(IRequest::class), new Response()); + $profile = $this->profiler->collect(\OCP\Server::get(IRequest::class), new Response()); $this->profiler->saveProfile($profile); } } diff --git a/apps/dav/lib/Upload/UploadFolder.php b/apps/dav/lib/Upload/UploadFolder.php index 8ea0591ab1680..57e95d2b17b19 100644 --- a/apps/dav/lib/Upload/UploadFolder.php +++ b/apps/dav/lib/Upload/UploadFolder.php @@ -11,6 +11,8 @@ use OCA\DAV\Connector\Sabre\Directory; use OCP\Files\ObjectStore\IObjectStoreMultiPartUpload; use OCP\Files\Storage\IStorage; +use OCP\ICacheFactory; +use OCP\Server; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\ICollection; @@ -60,7 +62,7 @@ public function getChildren() { /** @var ObjectStoreStorage $storage */ $objectStore = $this->storage->getObjectStore(); if ($objectStore instanceof IObjectStoreMultiPartUpload) { - $cache = \OC::$server->getMemCacheFactory()->createDistributed(ChunkingV2Plugin::CACHE_KEY); + $cache = Server::get(ICacheFactory::class)->createDistributed(ChunkingV2Plugin::CACHE_KEY); $uploadSession = $cache->get($this->getName()); if ($uploadSession) { $uploadId = $uploadSession[ChunkingV2Plugin::UPLOAD_ID]; diff --git a/apps/dav/lib/Upload/UploadHome.php b/apps/dav/lib/Upload/UploadHome.php index 739c38feb3037..3a8e13eb02d13 100644 --- a/apps/dav/lib/Upload/UploadHome.php +++ b/apps/dav/lib/Upload/UploadHome.php @@ -10,6 +10,8 @@ use OC\Files\Filesystem; use OC\Files\View; use OCA\DAV\Connector\Sabre\Directory; +use OCP\IUserSession; +use OCP\Server; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\ICollection; @@ -73,7 +75,7 @@ private function impl() { private function getView() { $rootView = new View(); - $user = \OC::$server->getUserSession()->getUser(); + $user = Server::get(IUserSession::class)->getUser(); Filesystem::initMountPoints($user->getUID()); if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) { $rootView->mkdir('/' . $user->getUID() . '/uploads'); diff --git a/apps/dav/templates/settings-admin-caldav.php b/apps/dav/templates/settings-admin-caldav.php index d0bc92bc965f9..636114ced75e5 100644 --- a/apps/dav/templates/settings-admin-caldav.php +++ b/apps/dav/templates/settings-admin-caldav.php @@ -4,7 +4,7 @@ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -script('dav', 'settings-admin-caldav'); +\OCP\Util::addScript('dav', 'settings-admin-caldav', 'core'); ?> diff --git a/apps/dav/templates/settings-personal-availability.php b/apps/dav/templates/settings-personal-availability.php index da0b2d9f104d1..f1c049392a32e 100644 --- a/apps/dav/templates/settings-personal-availability.php +++ b/apps/dav/templates/settings-personal-availability.php @@ -4,7 +4,7 @@ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -script('dav', 'settings-personal-availability'); +\OCP\Util::addScript('dav', 'settings-personal-availability', 'core'); ?> diff --git a/apps/dav/tests/integration/Db/PropertyMapperTest.php b/apps/dav/tests/integration/Db/PropertyMapperTest.php index 054acedb664af..9bd47a82d35bf 100644 --- a/apps/dav/tests/integration/Db/PropertyMapperTest.php +++ b/apps/dav/tests/integration/Db/PropertyMapperTest.php @@ -10,6 +10,7 @@ namespace OCA\DAV\Tests\integration\Db; use OCA\DAV\Db\PropertyMapper; +use OCP\Server; use Test\TestCase; /** @@ -23,7 +24,7 @@ class PropertyMapperTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->mapper = \OC::$server->get(PropertyMapper::class); + $this->mapper = Server::get(PropertyMapper::class); } public function testFindNonExistent(): void { diff --git a/apps/dav/tests/unit/BackgroundJob/UserStatusAutomationTest.php b/apps/dav/tests/unit/BackgroundJob/UserStatusAutomationTest.php index 7e30ec3d2fe7b..ce3871aa400af 100644 --- a/apps/dav/tests/unit/BackgroundJob/UserStatusAutomationTest.php +++ b/apps/dav/tests/unit/BackgroundJob/UserStatusAutomationTest.php @@ -14,8 +14,10 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; use OCP\IConfig; +use OCP\IDBConnection; use OCP\IUser; use OCP\IUserManager; +use OCP\Server; use OCP\User\IAvailabilityCoordinator; use OCP\UserStatus\IManager; use OCP\UserStatus\IUserStatus; @@ -53,7 +55,7 @@ protected function getAutomationMock(array $methods): MockObject|UserStatusAutom if (empty($methods)) { return new UserStatusAutomation( $this->time, - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->jobList, $this->logger, $this->statusManager, @@ -66,7 +68,7 @@ protected function getAutomationMock(array $methods): MockObject|UserStatusAutom return $this->getMockBuilder(UserStatusAutomation::class) ->setConstructorArgs([ $this->time, - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->jobList, $this->logger, $this->statusManager, diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php index 946a2328bf8df..c1d8e8609b62b 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php @@ -25,6 +25,7 @@ use OCP\IUserSession; use OCP\L10N\IFactory; use OCP\Security\ISecureRandom; +use OCP\Server; use OCP\Share\IManager as ShareManager; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -87,8 +88,8 @@ protected function setUp(): void { ->withAnyParameters() ->willReturn([self::UNIT_TEST_GROUP, self::UNIT_TEST_GROUP2]); - $this->db = \OC::$server->getDatabaseConnection(); - $this->random = \OC::$server->getSecureRandom(); + $this->db = Server::get(IDBConnection::class); + $this->random = Server::get(ISecureRandom::class); $this->logger = $this->createMock(LoggerInterface::class); $this->config = $this->createMock(IConfig::class); $this->sharingBackend = new SharingBackend( diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php index 4333754222bad..075681eff7f60 100644 --- a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php +++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php @@ -12,10 +12,12 @@ use OCA\DAV\Connector\Sabre\Principal; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; +use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IL10N; use OCP\IUserManager; use OCP\Security\ISecureRandom; +use OCP\Server; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -51,11 +53,11 @@ class PublicCalendarRootTest extends TestCase { protected function setUp(): void { parent::setUp(); - $db = \OC::$server->getDatabaseConnection(); + $db = Server::get(IDBConnection::class); $this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal'); $this->userManager = $this->createMock(IUserManager::class); $this->groupManager = $this->createMock(IGroupManager::class); - $this->random = \OC::$server->getSecureRandom(); + $this->random = Server::get(ISecureRandom::class); $this->logger = $this->createMock(LoggerInterface::class); $dispatcher = $this->createMock(IEventDispatcher::class); $config = $this->createMock(IConfig::class); diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php index 96968909d1cc6..653edd226c334 100644 --- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php +++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php @@ -27,6 +27,7 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\Server; use OCP\Share\IManager as ShareManager; use Psr\Log\LoggerInterface; use Sabre\DAV\Exception\BadRequest; @@ -133,7 +134,7 @@ protected function setUp(): void { ->willReturn([self::UNIT_TEST_GROUP]); $this->dispatcher = $this->createMock(IEventDispatcher::class); - $this->db = \OC::$server->getDatabaseConnection(); + $this->db = Server::get(IDBConnection::class); $this->sharingBackend = new Backend($this->userManager, $this->groupManager, $this->principal, diff --git a/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php b/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php index 3c597e22a95a8..f2346c211ce0d 100644 --- a/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php +++ b/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php @@ -9,7 +9,9 @@ use OCA\DAV\Command\RemoveInvalidShares; use OCA\DAV\Connector\Sabre\Principal; +use OCP\IDBConnection; use OCP\Migration\IOutput; +use OCP\Server; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; @@ -23,7 +25,7 @@ class RemoveInvalidSharesTest extends TestCase { protected function setUp(): void { parent::setUp(); - $db = \OC::$server->getDatabaseConnection(); + $db = Server::get(IDBConnection::class); $db->insertIfNotExist('*PREFIX*dav_shares', [ 'principaluri' => 'principal:unknown', @@ -34,7 +36,7 @@ protected function setUp(): void { } public function test(): void { - $db = \OC::$server->getDatabaseConnection(); + $db = Server::get(IDBConnection::class); /** @var Principal | \PHPUnit\Framework\MockObject\MockObject $principal */ $principal = $this->createMock(Principal::class); diff --git a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php index 72d5e7198a304..eb3f291e9c06a 100644 --- a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php @@ -11,7 +11,9 @@ use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\File; use OCA\DAV\DAV\CustomPropertiesBackend; +use OCP\IDBConnection; use OCP\IUser; +use OCP\Server; use PHPUnit\Framework\MockObject\MockObject; use Sabre\DAV\Tree; @@ -68,14 +70,14 @@ protected function setUp(): void { $this->plugin = new CustomPropertiesBackend( $this->server, $this->tree, - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->user, $this->defaultCalendarValidator, ); } protected function tearDown(): void { - $connection = \OC::$server->getDatabaseConnection(); + $connection = Server::get(IDBConnection::class); $deleteStatement = $connection->prepare( 'DELETE FROM `*PREFIX*properties`' . ' WHERE `userid` = ?' diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php index df48cd611148b..836766b366d76 100644 --- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php +++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php @@ -7,6 +7,8 @@ */ namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest; +use OCP\IUserSession; +use OCP\Server; use Sabre\DAV\Auth\Backend\BackendInterface; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; @@ -53,7 +55,7 @@ public function __construct( * @return array */ public function check(RequestInterface $request, ResponseInterface $response) { - $userSession = \OC::$server->getUserSession(); + $userSession = Server::get(IUserSession::class); $result = $userSession->login($this->user, $this->password); if ($result) { //we need to pass the user name, which may differ from login name diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionMasterKeyUploadTest.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionMasterKeyUploadTest.php index cbaa0c3101b57..92d89d7753aa2 100644 --- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionMasterKeyUploadTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionMasterKeyUploadTest.php @@ -8,6 +8,9 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest; use OC\Files\View; +use OCP\IConfig; +use OCP\ITempManager; +use OCP\Server; use Test\Traits\EncryptionTrait; /** @@ -22,10 +25,10 @@ class EncryptionMasterKeyUploadTest extends UploadTest { protected function setupUser($name, $password) { $this->createUser($name, $password); - $tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder(); + $tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder(); $this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]); // we use the master key - \OC::$server->getConfig()->setAppValue('encryption', 'useMasterKey', '1'); + Server::get(IConfig::class)->setAppValue('encryption', 'useMasterKey', '1'); $this->setupForUser($name, $password); $this->loginWithEncryption($name); return new View('/' . $name . '/files'); diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionUploadTest.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionUploadTest.php index f830c54fd0d29..935ef6d9464f1 100644 --- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionUploadTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionUploadTest.php @@ -8,6 +8,9 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest; use OC\Files\View; +use OCP\IConfig; +use OCP\ITempManager; +use OCP\Server; use Test\Traits\EncryptionTrait; /** @@ -22,10 +25,10 @@ class EncryptionUploadTest extends UploadTest { protected function setupUser($name, $password) { $this->createUser($name, $password); - $tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder(); + $tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder(); $this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]); // we use per-user keys - \OC::$server->getConfig()->setAppValue('encryption', 'useMasterKey', '0'); + Server::get(IConfig::class)->setAppValue('encryption', 'useMasterKey', '0'); $this->setupForUser($name, $password); $this->loginWithEncryption($name); return new View('/' . $name . '/files'); diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php index 11a44f26942cb..5f3dc6f4e32de 100644 --- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php @@ -9,6 +9,7 @@ use OC\AllConfig; use OCP\IConfig; +use OCP\Server; /** * Class PartFileInRootUploadTest @@ -19,7 +20,7 @@ */ class PartFileInRootUploadTest extends UploadTest { protected function setUp(): void { - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); $mockConfig = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php index 4085bc93c7854..a04aedb4e57fb 100644 --- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php +++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php @@ -11,9 +11,15 @@ use OCA\DAV\Connector\Sabre\Server; use OCA\DAV\Connector\Sabre\ServerFactory; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Mount\IMountManager; use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IPreview; use OCP\IRequest; use OCP\IRequestId; +use OCP\ITagManager; +use OCP\ITempManager; +use OCP\IUserSession; use Psr\Log\LoggerInterface; use Sabre\HTTP\Request; use Test\TestCase; @@ -40,24 +46,24 @@ protected function setUp(): void { parent::setUp(); $this->serverFactory = new ServerFactory( - \OC::$server->getConfig(), - \OC::$server->get(LoggerInterface::class), - \OC::$server->getDatabaseConnection(), - \OC::$server->getUserSession(), - \OC::$server->getMountManager(), - \OC::$server->getTagManager(), + \OCP\Server::get(IConfig::class), + \OCP\Server::get(LoggerInterface::class), + \OCP\Server::get(IDBConnection::class), + \OCP\Server::get(IUserSession::class), + \OCP\Server::get(IMountManager::class), + \OCP\Server::get(ITagManager::class), $this->getMockBuilder(IRequest::class) ->disableOriginalConstructor() ->getMock(), - \OC::$server->getPreviewManager(), - \OC::$server->get(IEventDispatcher::class), + \OCP\Server::get(IPreview::class), + \OCP\Server::get(IEventDispatcher::class), \OC::$server->getL10N('dav') ); } protected function setupUser($name, $password) { $this->createUser($name, $password); - $tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder(); + $tmpFolder = \OCP\Server::get(ITempManager::class)->getTemporaryFolder(); $this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]); $this->loginAsUser($name); return new View('/' . $name . '/files'); @@ -79,7 +85,7 @@ protected function request($view, $user, $password, $method, $url, $body = null, $body = $this->getStream($body); } $this->logout(); - $exceptionPlugin = new ExceptionPlugin('webdav', \OC::$server->get(LoggerInterface::class)); + $exceptionPlugin = new ExceptionPlugin('webdav', \OCP\Server::get(LoggerInterface::class)); $server = $this->getSabreServer($view, $user, $password, $exceptionPlugin); $request = new Request($method, $url, $headers, $body); diff --git a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php index fa71fd8016bf0..5590e8c1ff064 100644 --- a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php +++ b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php @@ -57,7 +57,7 @@ protected function setUp(): void { $this->user->method('getUID') ->with() ->willReturn('dummy_user_42'); - $this->dbConnection = \OC::$server->getDatabaseConnection(); + $this->dbConnection = \OCP\Server::get(IDBConnection::class); $this->defaultCalendarValidator = $this->createMock(DefaultCalendarValidator::class); $this->backend = new CustomPropertiesBackend( diff --git a/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php b/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php index 1cebf199d2903..be2c64c47a4b3 100644 --- a/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php +++ b/apps/dav/tests/unit/Migration/CalDAVRemoveEmptyValueTest.php @@ -7,7 +7,9 @@ use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\Migration\CalDAVRemoveEmptyValue; +use OCP\IDBConnection; use OCP\Migration\IOutput; +use OCP\Server; use Psr\Log\LoggerInterface; use Sabre\VObject\InvalidDataException; use Test\TestCase; @@ -83,7 +85,7 @@ public function testRunAllValid(): void { /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->backend, $this->logger ]) @@ -107,7 +109,7 @@ public function testRunInvalid(): void { /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->backend, $this->logger ]) @@ -150,7 +152,7 @@ public function testRunValid(): void { /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->backend, $this->logger ]) @@ -192,7 +194,7 @@ public function testRunStillInvalid(): void { /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->backend, $this->logger ]) diff --git a/apps/encryption/templates/settings-admin.php b/apps/encryption/templates/settings-admin.php index 6d06f28ffe7a4..432ba2f11b049 100644 --- a/apps/encryption/templates/settings-admin.php +++ b/apps/encryption/templates/settings-admin.php @@ -7,7 +7,7 @@ */ /** @var array $_ */ /** @var \OCP\IL10N $l */ -script('encryption', 'settings-admin'); +\OCP\Util::addScript('encryption', 'settings-admin', 'core'); style('encryption', 'settings-admin'); ?>
diff --git a/apps/encryption/templates/settings-personal.php b/apps/encryption/templates/settings-personal.php index 5aa227e7354f5..6fdc253f7d286 100644 --- a/apps/encryption/templates/settings-personal.php +++ b/apps/encryption/templates/settings-personal.php @@ -7,7 +7,7 @@ */ /** @var array $_ */ /** @var \OCP\IL10N $l */ -script('encryption', 'settings-personal'); +\OCP\Util::addScript('encryption', 'settings-personal', 'core'); ?>

t('Basic encryption module')); ?>

diff --git a/apps/encryption/tests/Command/FixEncryptedVersionTest.php b/apps/encryption/tests/Command/FixEncryptedVersionTest.php index e5079b9a8afb8..6c6a39df17561 100644 --- a/apps/encryption/tests/Command/FixEncryptedVersionTest.php +++ b/apps/encryption/tests/Command/FixEncryptedVersionTest.php @@ -11,6 +11,10 @@ use OC\Files\View; use OCA\Encryption\Command\FixEncryptedVersion; use OCA\Encryption\Util; +use OCP\Files\IRootFolder; +use OCP\IConfig; +use OCP\ITempManager; +use OCP\Server; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Tester\CommandTester; use Test\TestCase; @@ -43,7 +47,7 @@ class FixEncryptedVersionTest extends TestCase { public function setUp(): void { parent::setUp(); - \OC::$server->getConfig()->setAppValue('encryption', 'useMasterKey', '1'); + Server::get(IConfig::class)->setAppValue('encryption', 'useMasterKey', '1'); $this->util = $this->getMockBuilder(Util::class) ->disableOriginalConstructor()->getMock(); @@ -51,24 +55,24 @@ public function setUp(): void { $this->userId = $this->getUniqueId('user_'); $this->createUser($this->userId, 'foo12345678'); - $tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder(); + $tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder(); $this->registerMount($this->userId, '\OC\Files\Storage\Local', '/' . $this->userId, ['datadir' => $tmpFolder]); $this->setupForUser($this->userId, 'foo12345678'); $this->loginWithEncryption($this->userId); $this->fixEncryptedVersion = new FixEncryptedVersion( - \OC::$server->getConfig(), - \OC::$server->get(LoggerInterface::class), - \OC::$server->getRootFolder(), - \OC::$server->getUserManager(), + Server::get(IConfig::class), + Server::get(LoggerInterface::class), + Server::get(IRootFolder::class), + Server::get(\OCP\User\IManager::class), $this->util, new View('/') ); $this->commandTester = new CommandTester($this->fixEncryptedVersion); - $this->assertTrue(\OC::$server->getEncryptionManager()->isEnabled()); - $this->assertTrue(\OC::$server->getEncryptionManager()->isReady()); - $this->assertTrue(\OC::$server->getEncryptionManager()->isReadyForUser($this->userId)); + $this->assertTrue(Server::get(\OCP\Encryption\IManager::class)->isEnabled()); + $this->assertTrue(Server::get(\OCP\Encryption\IManager::class)->isReady()); + $this->assertTrue(Server::get(\OCP\Encryption\IManager::class)->isReadyForUser($this->userId)); } /** @@ -370,7 +374,7 @@ public function testExecuteWithNonExistentPath(): void { * Test commands without master key */ public function testExecuteWithNoMasterKey(): void { - \OC::$server->getConfig()->setAppValue('encryption', 'useMasterKey', '0'); + Server::get(IConfig::class)->setAppValue('encryption', 'useMasterKey', '0'); $this->util->expects($this->once())->method('isMasterKeyEnabled') ->willReturn(false); diff --git a/apps/encryption/tests/EncryptedStorageTest.php b/apps/encryption/tests/EncryptedStorageTest.php index 7671eab4992e8..59f419a7f7a1a 100644 --- a/apps/encryption/tests/EncryptedStorageTest.php +++ b/apps/encryption/tests/EncryptedStorageTest.php @@ -13,6 +13,7 @@ use OC\Files\View; use OCP\Files\Mount\IMountManager; use OCP\Files\Storage\IDisableEncryptionStorage; +use OCP\Server; use Test\TestCase; use Test\Traits\EncryptionTrait; use Test\Traits\MountProviderTrait; @@ -44,7 +45,7 @@ public function testMoveFromEncrypted(): void { $view = new View('/test1/files'); /** @var IMountManager $mountManager */ - $mountManager = \OC::$server->get(IMountManager::class); + $mountManager = Server::get(IMountManager::class); $encryptedMount = $mountManager->find('/test1/files/enc'); $unencryptedMount = $mountManager->find('/test1/files/unenc'); diff --git a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php index d5082eafc567b..996b363252a91 100644 --- a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php +++ b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php @@ -151,7 +151,7 @@ public function shareReceived(ICloudFederationShare $share) { try { $this->externalShareManager->addShare($remote, $token, '', $name, $owner, $shareType, false, $shareWith, $remoteId); - $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); + $shareId = Server::get(IDBConnection::class)->lastInsertId('*PREFIX*share_external'); // get DisplayName about the owner of the share $ownerDisplayName = $this->getUserDisplayName($ownerFederatedId); @@ -163,7 +163,7 @@ public function shareReceived(ICloudFederationShare $share) { ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/'), $ownerDisplayName]) ->setAffectedUser($shareWith) ->setObject('remote_share', $shareId, $name); - \OC::$server->getActivityManager()->publish($event); + Server::get(IActivityManager::class)->publish($event); $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName); // If auto-accept is enabled, accept the share @@ -179,7 +179,7 @@ public function shareReceived(ICloudFederationShare $share) { ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/'), $ownerDisplayName]) ->setAffectedUser($user->getUID()) ->setObject('remote_share', $shareId, $name); - \OC::$server->getActivityManager()->publish($event); + Server::get(IActivityManager::class)->publish($event); $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName); // If auto-accept is enabled, accept the share @@ -515,7 +515,7 @@ private function unshare($id, array $notification) { ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path, $ownerDisplayName]) ->setAffectedUser($user) ->setObject('remote_share', (int)$share['id'], $path); - \OC::$server->getActivityManager()->publish($event); + Server::get(IActivityManager::class)->publish($event); } } diff --git a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php index 77e10b7a61a5d..e2449dc34381b 100644 --- a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php +++ b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php @@ -25,6 +25,7 @@ use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUserManager; +use OCP\Server; use OCP\Share\IManager; use OCP\Share\IShare; use PHPUnit\Framework\MockObject\MockObject; @@ -74,7 +75,7 @@ class FederatedShareProviderTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = Server::get(IDBConnection::class); $this->notifications = $this->getMockBuilder('OCA\FederatedFileSharing\Notifications') ->disableOriginalConstructor() ->getMock(); @@ -121,7 +122,7 @@ protected function setUp(): void { $this->logger, ); - $this->shareManager = \OC::$server->getShareManager(); + $this->shareManager = Server::get(\OCP\Share\IManager::class); } protected function tearDown(): void { @@ -870,8 +871,8 @@ public function dataTestIsLookupServerUploadEnabled() { } public function testGetSharesInFolder(): void { - $userManager = \OC::$server->getUserManager(); - $rootFolder = \OC::$server->getRootFolder(); + $userManager = Server::get(\OCP\User\IManager::class); + $rootFolder = Server::get(IRootFolder::class); $u1 = $userManager->createUser('testFed', md5(time())); $u2 = $userManager->createUser('testFed2', md5(time())); @@ -924,8 +925,8 @@ public function testGetSharesInFolder(): void { } public function testGetAccessList(): void { - $userManager = \OC::$server->getUserManager(); - $rootFolder = \OC::$server->getRootFolder(); + $userManager = Server::get(\OCP\User\IManager::class); + $rootFolder = Server::get(IRootFolder::class); $u1 = $userManager->createUser('testFed', md5(time())); diff --git a/apps/federatedfilesharing/tests/TestCase.php b/apps/federatedfilesharing/tests/TestCase.php index a53025c5a6258..68abcc6339175 100644 --- a/apps/federatedfilesharing/tests/TestCase.php +++ b/apps/federatedfilesharing/tests/TestCase.php @@ -9,6 +9,8 @@ use OC\Files\Filesystem; use OC\Group\Database; +use OCP\IUserSession; +use OCP\Server; /** * Class Test_Files_Sharing_Base @@ -26,7 +28,7 @@ public static function setUpBeforeClass(): void { // reset backend \OC_User::clearBackends(); - \OC::$server->getGroupManager()->clearBackends(); + Server::get(\OCP\Group\IManager::class)->clearBackends(); // create users $backend = new \Test\Util\User\Dummy(); @@ -44,11 +46,11 @@ protected function setUp(): void { public static function tearDownAfterClass(): void { // cleanup users - $user = \OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER1); + $user = Server::get(\OCP\User\IManager::class)->get(self::TEST_FILES_SHARING_API_USER1); if ($user !== null) { $user->delete(); } - $user = \OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER2); + $user = Server::get(\OCP\User\IManager::class)->get(self::TEST_FILES_SHARING_API_USER2); if ($user !== null) { $user->delete(); } @@ -60,8 +62,8 @@ public static function tearDownAfterClass(): void { // reset backend \OC_User::clearBackends(); \OC_User::useBackend('database'); - \OC::$server->getGroupManager()->clearBackends(); - \OC::$server->getGroupManager()->addBackend(new Database()); + Server::get(\OCP\Group\IManager::class)->clearBackends(); + Server::get(\OCP\Group\IManager::class)->addBackend(new Database()); parent::tearDownAfterClass(); } @@ -77,8 +79,8 @@ protected static function loginHelper($user, $create = false, $password = false) } if ($create) { - $userManager = \OC::$server->getUserManager(); - $groupManager = \OC::$server->getGroupManager(); + $userManager = Server::get(\OCP\User\IManager::class); + $groupManager = Server::get(\OCP\Group\IManager::class); $userObject = $userManager->createUser($user, $password); $group = $groupManager->createGroup('group'); @@ -89,9 +91,9 @@ protected static function loginHelper($user, $create = false, $password = false) } \OC_Util::tearDownFS(); - \OC::$server->getUserSession()->setUser(null); + Server::get(IUserSession::class)->setUser(null); Filesystem::tearDown(); - \OC::$server->getUserSession()->login($user, $password); + Server::get(IUserSession::class)->login($user, $password); \OC::$server->getUserFolder($user); \OC_Util::setupFS($user); diff --git a/apps/federation/tests/DbHandlerTest.php b/apps/federation/tests/DbHandlerTest.php index aabbf1472e77c..1db9f7f2315bf 100644 --- a/apps/federation/tests/DbHandlerTest.php +++ b/apps/federation/tests/DbHandlerTest.php @@ -11,6 +11,7 @@ use OCA\Federation\TrustedServers; use OCP\IDBConnection; use OCP\IL10N; +use OCP\Server; use Test\TestCase; /** @@ -33,7 +34,7 @@ class DbHandlerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = Server::get(IDBConnection::class); $this->il10n = $this->getMockBuilder(IL10N::class)->getMock(); $this->dbHandler = new DbHandler( diff --git a/apps/files/lib/BackgroundJob/CleanupFileLocks.php b/apps/files/lib/BackgroundJob/CleanupFileLocks.php index a332c1434fcbe..91bb145884b03 100644 --- a/apps/files/lib/BackgroundJob/CleanupFileLocks.php +++ b/apps/files/lib/BackgroundJob/CleanupFileLocks.php @@ -10,6 +10,8 @@ use OC\Lock\DBLockingProvider; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; +use OCP\Lock\ILockingProvider; +use OCP\Server; /** * Clean up all file locks that are expired for the DB file locking provider @@ -30,7 +32,7 @@ public function __construct(ITimeFactory $time) { * @throws \Exception */ public function run($argument) { - $lockingProvider = \OC::$server->getLockingProvider(); + $lockingProvider = Server::get(ILockingProvider::class); if ($lockingProvider instanceof DBLockingProvider) { $lockingProvider->cleanExpiredLocks(); } diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php index cf1cb04b9afe3..9c57f4b29716a 100644 --- a/apps/files/lib/Command/Scan.php +++ b/apps/files/lib/Command/Scan.php @@ -24,6 +24,7 @@ use OCP\Files\StorageNotAvailableException; use OCP\FilesMetadata\IFilesMetadataManager; use OCP\IUserManager; +use OCP\Server; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; @@ -102,8 +103,8 @@ protected function scanFiles(string $user, string $path, ?string $scanMetadata, $scanner = new Scanner( $user, new ConnectionAdapter($connection), - \OC::$server->get(IEventDispatcher::class), - \OC::$server->get(LoggerInterface::class) + Server::get(IEventDispatcher::class), + Server::get(LoggerInterface::class) ); # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception @@ -310,7 +311,7 @@ protected function formatExecTime(): string { protected function reconnectToDatabase(OutputInterface $output): Connection { /** @var Connection $connection */ - $connection = \OC::$server->get(Connection::class); + $connection = Server::get(Connection::class); try { $connection->close(); } catch (\Exception $ex) { diff --git a/apps/files/lib/Command/ScanAppData.php b/apps/files/lib/Command/ScanAppData.php index 02f0977cba925..21974a279e67b 100644 --- a/apps/files/lib/Command/ScanAppData.php +++ b/apps/files/lib/Command/ScanAppData.php @@ -18,6 +18,7 @@ use OCP\Files\NotFoundException; use OCP\Files\StorageNotAvailableException; use OCP\IConfig; +use OCP\Server; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputArgument; @@ -71,7 +72,7 @@ protected function scanFiles(OutputInterface $output, string $folder): int { null, new ConnectionAdapter($connection), \OC::$server->query(IEventDispatcher::class), - \OC::$server->get(LoggerInterface::class) + Server::get(LoggerInterface::class) ); # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception @@ -213,7 +214,7 @@ protected function formatExecTime(): string { protected function reconnectToDatabase(OutputInterface $output): Connection { /** @var Connection $connection */ - $connection = \OC::$server->get(Connection::class); + $connection = Server::get(Connection::class); try { $connection->close(); } catch (\Exception $ex) { diff --git a/apps/files/lib/Helper.php b/apps/files/lib/Helper.php index b66dc9a205610..82d1cc9493492 100644 --- a/apps/files/lib/Helper.php +++ b/apps/files/lib/Helper.php @@ -9,8 +9,10 @@ use OC\Files\Filesystem; use OCP\Files\FileInfo; +use OCP\Files\IMimeTypeDetector; use OCP\Files\NotFoundException; use OCP\ITagManager; +use OCP\Server; use OCP\Util; /** @@ -53,15 +55,15 @@ public static function buildFileStorageStatistics($dir) { */ public static function determineIcon($file) { if ($file['type'] === 'dir') { - $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir'); + $icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon('dir'); // TODO: move this part to the client side, using mountType if ($file->isShared()) { - $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir-shared'); + $icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon('dir-shared'); } elseif ($file->isMounted()) { - $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon('dir-external'); + $icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon('dir-external'); } } else { - $icon = \OC::$server->getMimeTypeDetector()->mimeTypeIcon($file->getMimetype()); + $icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon($file->getMimetype()); } return substr($icon, 0, -3) . 'svg'; diff --git a/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php b/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php index 1ce2d7bd8f7a2..e31b157481536 100644 --- a/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php +++ b/apps/files/tests/BackgroundJob/DeleteOrphanedItemsJobTest.php @@ -11,6 +11,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +use OCP\Server; use Psr\Log\LoggerInterface; /** @@ -27,9 +28,9 @@ class DeleteOrphanedItemsJobTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->get(IDBConnection::class); + $this->connection = Server::get(IDBConnection::class); $this->timeFactory = $this->createMock(ITimeFactory::class); - $this->logger = \OC::$server->get(LoggerInterface::class); + $this->logger = Server::get(LoggerInterface::class); } protected function cleanMapping($table) { diff --git a/apps/files/tests/BackgroundJob/ScanFilesTest.php b/apps/files/tests/BackgroundJob/ScanFilesTest.php index c535ddb808cd9..ce602805aa25c 100644 --- a/apps/files/tests/BackgroundJob/ScanFilesTest.php +++ b/apps/files/tests/BackgroundJob/ScanFilesTest.php @@ -14,7 +14,9 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IUserMountCache; use OCP\IConfig; +use OCP\IDBConnection; use OCP\IUser; +use OCP\Server; use Psr\Log\LoggerInterface; use Test\TestCase; use Test\Traits\MountProviderTrait; @@ -41,8 +43,8 @@ protected function setUp(): void { $config = $this->createMock(IConfig::class); $dispatcher = $this->createMock(IEventDispatcher::class); $logger = $this->createMock(LoggerInterface::class); - $connection = \OC::$server->getDatabaseConnection(); - $this->mountCache = \OC::$server->getUserMountCache(); + $connection = Server::get(IDBConnection::class); + $this->mountCache = Server::get(IUserMountCache::class); $this->scanFiles = $this->getMockBuilder('\OCA\Files\BackgroundJob\ScanFiles') ->setConstructorArgs([ diff --git a/apps/files/tests/Command/DeleteOrphanedFilesTest.php b/apps/files/tests/Command/DeleteOrphanedFilesTest.php index e480f7b632ede..8e28b7400531e 100644 --- a/apps/files/tests/Command/DeleteOrphanedFilesTest.php +++ b/apps/files/tests/Command/DeleteOrphanedFilesTest.php @@ -37,14 +37,14 @@ protected function setUp(): void { $this->user1 = $this->getUniqueID('user1_'); - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(\OCP\User\IManager::class); $userManager->createUser($this->user1, 'pass'); $this->command = new DeleteOrphanedFiles($this->connection); } protected function tearDown(): void { - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(\OCP\User\IManager::class); $user1 = $userManager->get($this->user1); if ($user1) { $user1->delete(); diff --git a/apps/files/tests/Service/TagServiceTest.php b/apps/files/tests/Service/TagServiceTest.php index 0e0149cc71b64..8e5ab0a6f789f 100644 --- a/apps/files/tests/Service/TagServiceTest.php +++ b/apps/files/tests/Service/TagServiceTest.php @@ -11,9 +11,11 @@ use OCP\Activity\IManager; use OCP\Files\Folder; use OCP\Files\NotFoundException; +use OCP\ITagManager; use OCP\ITags; use OCP\IUser; use OCP\IUserSession; +use OCP\Server; /** * Class TagServiceTest @@ -54,7 +56,7 @@ protected function setUp(): void { parent::setUp(); $this->user = static::getUniqueID('user'); $this->activityManager = $this->createMock(IManager::class); - \OC::$server->getUserManager()->createUser($this->user, 'test'); + Server::get(\OCP\User\IManager::class)->createUser($this->user, 'test'); \OC_User::setUserId($this->user); \OC_Util::setupFS($this->user); $user = $this->createMock(IUser::class); @@ -69,7 +71,7 @@ protected function setUp(): void { $this->root = \OC::$server->getUserFolder(); - $this->tagger = \OC::$server->getTagManager()->load('files'); + $this->tagger = Server::get(ITagManager::class)->load('files'); $this->tagService = $this->getTagService(['addActivity']); } @@ -91,7 +93,7 @@ protected function getTagService(array $methods = []) { protected function tearDown(): void { \OC_User::setUserId(''); - $user = \OC::$server->getUserManager()->get($this->user); + $user = Server::get(\OCP\User\IManager::class)->get($this->user); if ($user !== null) { $user->delete(); } diff --git a/apps/files_external/ajax/applicable.php b/apps/files_external/ajax/applicable.php index c1b7748ad15d5..f48104830a6a6 100644 --- a/apps/files_external/ajax/applicable.php +++ b/apps/files_external/ajax/applicable.php @@ -1,4 +1,7 @@ getGroupManager()->search($pattern, $limit, $offset) as $group) { +foreach (Server::get(\OCP\Group\IManager::class)->search($pattern, $limit, $offset) as $group) { $groups[$group->getGID()] = $group->getDisplayName(); } $users = []; -foreach (\OC::$server->getUserManager()->searchDisplayName($pattern, $limit, $offset) as $user) { +foreach (Server::get(\OCP\User\IManager::class)->searchDisplayName($pattern, $limit, $offset) as $user) { $users[$user->getUID()] = $user->getDisplayName(); } diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index 1a866e8c22bf2..47967a3908d27 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -20,6 +20,7 @@ use OCP\Files\IMimeTypeDetector; use OCP\ICache; use OCP\ICacheFactory; +use OCP\ITempManager; use OCP\Server; use Psr\Log\LoggerInterface; @@ -451,7 +452,7 @@ public function fopen(string $path, string $mode) { } case 'w': case 'wb': - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile(); + $tmpFile = Server::get(ITempManager::class)->getTemporaryFile(); $handle = fopen($tmpFile, 'w'); return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile): void { @@ -472,7 +473,7 @@ public function fopen(string $path, string $mode) { } else { $ext = ''; } - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext); + $tmpFile = Server::get(ITempManager::class)->getTemporaryFile($ext); if ($this->file_exists($path)) { $source = $this->readObject($path); file_put_contents($tmpFile, $source); diff --git a/apps/files_external/lib/Lib/Storage/FTP.php b/apps/files_external/lib/Lib/Storage/FTP.php index 51b269b3eb060..e23fc7912974f 100644 --- a/apps/files_external/lib/Lib/Storage/FTP.php +++ b/apps/files_external/lib/Lib/Storage/FTP.php @@ -12,7 +12,10 @@ use OC\Files\Storage\PolyFill\CopyDirectory; use OCP\Constants; use OCP\Files\FileInfo; +use OCP\Files\IMimeTypeDetector; use OCP\Files\StorageNotAvailableException; +use OCP\ITempManager; +use OCP\Server; use Psr\Log\LoggerInterface; class FTP extends Common { @@ -101,7 +104,7 @@ public function filemtime(string $path): int|false { if ($this->is_dir($path)) { $list = $this->getConnection()->mlsd($this->buildPath($path)); if (!$list) { - \OC::$server->get(LoggerInterface::class)->warning("Unable to get last modified date for ftp folder ($path), failed to list folder contents"); + Server::get(LoggerInterface::class)->warning("Unable to get last modified date for ftp folder ($path), failed to list folder contents"); return time(); } $currentDir = current(array_filter($list, function ($item) { @@ -115,7 +118,7 @@ public function filemtime(string $path): int|false { } return $time->getTimestamp(); } else { - \OC::$server->get(LoggerInterface::class)->warning("Unable to get last modified date for ftp folder ($path), folder contents doesn't include current folder"); + Server::get(LoggerInterface::class)->warning("Unable to get last modified date for ftp folder ($path), folder contents doesn't include current folder"); return time(); } } else { @@ -270,7 +273,7 @@ public function fopen(string $path, string $mode) { if (!$this->isCreatable(dirname($path))) { return false; } - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile(); + $tmpFile = Server::get(ITempManager::class)->getTemporaryFile(); } $source = fopen($tmpFile, $mode); return CallbackWrapper::wrap($source, null, null, function () use ($tmpFile, $path): void { @@ -322,7 +325,7 @@ public function rename(string $source, string $target): bool { public function getDirectoryContent(string $directory): \Traversable { $files = $this->getConnection()->mlsd($this->buildPath($directory)); - $mimeTypeDetector = \OC::$server->getMimeTypeDetector(); + $mimeTypeDetector = Server::get(IMimeTypeDetector::class); foreach ($files as $file) { $name = $file['name']; diff --git a/apps/files_external/lib/Lib/Storage/SFTP.php b/apps/files_external/lib/Lib/Storage/SFTP.php index 44073beedecee..72ffc6b123dbe 100644 --- a/apps/files_external/lib/Lib/Storage/SFTP.php +++ b/apps/files_external/lib/Lib/Storage/SFTP.php @@ -14,6 +14,7 @@ use OCP\Constants; use OCP\Files\FileInfo; use OCP\Files\IMimeTypeDetector; +use OCP\Server; use phpseclib\Net\SFTP\Stream; /** @@ -87,7 +88,7 @@ public function __construct(array $parameters) { $this->root = '/' . ltrim($this->root, '/'); $this->root = rtrim($this->root, '/') . '/'; - $this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class); + $this->mimeTypeDetector = Server::get(IMimeTypeDetector::class); } /** diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index ef203021566b4..f08401f73c54d 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -31,12 +31,14 @@ use OCP\Cache\CappedMemoryCache; use OCP\Constants; use OCP\Files\EntityTooLargeException; +use OCP\Files\IMimeTypeDetector; use OCP\Files\Notify\IChange; use OCP\Files\Notify\IRenameChange; use OCP\Files\NotPermittedException; use OCP\Files\Storage\INotifyStorage; use OCP\Files\StorageAuthException; use OCP\Files\StorageNotAvailableException; +use OCP\ITempManager; use Psr\Log\LoggerInterface; class SMB extends Common implements INotifyStorage { @@ -458,7 +460,7 @@ public function fopen(string $path, string $mode) { if (!$this->isCreatable(dirname($path))) { return false; } - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext); + $tmpFile = \OCP\Server::get(ITempManager::class)->getTemporaryFile($ext); } $source = fopen($tmpFile, $mode); $share = $this->share; @@ -553,7 +555,7 @@ private function getMetaDataFromFileInfo(IFileInfo $fileInfo): array { if ($fileInfo->isDirectory()) { $data['mimetype'] = 'httpd/unix-directory'; } else { - $data['mimetype'] = \OC::$server->getMimeTypeDetector()->detectPath($fileInfo->getPath()); + $data['mimetype'] = \OCP\Server::get(IMimeTypeDetector::class)->detectPath($fileInfo->getPath()); } $data['mtime'] = $fileInfo->getMTime(); if ($fileInfo->isDirectory()) { diff --git a/apps/files_external/lib/Lib/Storage/Swift.php b/apps/files_external/lib/Lib/Storage/Swift.php index cb72ab8c070d2..a71331766d46b 100644 --- a/apps/files_external/lib/Lib/Storage/Swift.php +++ b/apps/files_external/lib/Lib/Storage/Swift.php @@ -21,6 +21,9 @@ use OCP\Files\StorageBadConfigException; use OCP\Files\StorageNotAvailableException; use OCP\ICache; +use OCP\ICacheFactory; +use OCP\ITempManager; +use OCP\Server; use OpenStack\Common\Error\BadResponseError; use OpenStack\ObjectStore\v1\Models\Container; use OpenStack\ObjectStore\v1\Models\StorageObject; @@ -101,7 +104,7 @@ private function fetchObject(string $path): StorageObject|false { } catch (BadResponseError $e) { // Expected response is "404 Not Found", so only log if it isn't if ($e->getResponse()->getStatusCode() !== 404) { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ + Server::get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, 'app' => 'files_external', ]); @@ -163,13 +166,13 @@ public function __construct(array $parameters) { // FIXME: private class... $this->objectCache = new CappedMemoryCache(); $this->connectionFactory = new SwiftFactory( - \OC::$server->getMemCacheFactory()->createDistributed('swift/'), + Server::get(ICacheFactory::class)->createDistributed('swift/'), $this->params, - \OC::$server->get(LoggerInterface::class) + Server::get(LoggerInterface::class) ); $this->objectStore = new \OC\Files\ObjectStore\Swift($this->params, $this->connectionFactory); $this->bucket = $parameters['bucket']; - $this->mimeDetector = \OC::$server->get(IMimeTypeDetector::class); + $this->mimeDetector = Server::get(IMimeTypeDetector::class); } public function mkdir(string $path): bool { @@ -193,7 +196,7 @@ public function mkdir(string $path): bool { // with all properties $this->objectCache->remove($path); } catch (BadResponseError $e) { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ + Server::get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, 'app' => 'files_external', ]); @@ -237,7 +240,7 @@ public function rmdir(string $path): bool { $this->objectStore->deleteObject($path . '/'); $this->objectCache->remove($path . '/'); } catch (BadResponseError $e) { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ + Server::get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, 'app' => 'files_external', ]); @@ -275,7 +278,7 @@ public function opendir(string $path) { return IteratorDirectory::wrap($files); } catch (\Exception $e) { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ + Server::get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, 'app' => 'files_external', ]); @@ -298,7 +301,7 @@ public function stat(string $path): array|false { return false; } } catch (BadResponseError $e) { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ + Server::get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, 'app' => 'files_external', ]); @@ -352,7 +355,7 @@ public function unlink(string $path): bool { $this->objectCache->remove($path . '/'); } catch (BadResponseError $e) { if ($e->getResponse()->getStatusCode() !== 404) { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ + Server::get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, 'app' => 'files_external', ]); @@ -376,7 +379,7 @@ public function fopen(string $path, string $mode) { try { return $this->objectStore->readObject($path); } catch (BadResponseError $e) { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ + Server::get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, 'app' => 'files_external', ]); @@ -396,7 +399,7 @@ public function fopen(string $path, string $mode) { } else { $ext = ''; } - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext); + $tmpFile = Server::get(ITempManager::class)->getTemporaryFile($ext); // Fetch existing file if required if ($mode[0] !== 'w' && $this->file_exists($path)) { if ($mode[0] === 'x') { @@ -463,7 +466,7 @@ public function copy(string $source, string $target): bool { $this->objectCache->remove($target); $this->objectCache->remove($target . '/'); } catch (BadResponseError $e) { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ + Server::get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, 'app' => 'files_external', ]); @@ -479,7 +482,7 @@ public function copy(string $source, string $target): bool { $this->objectCache->remove($target); $this->objectCache->remove($target . '/'); } catch (BadResponseError $e) { - \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ + Server::get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, 'app' => 'files_external', ]); diff --git a/apps/files_external/lib/MountConfig.php b/apps/files_external/lib/MountConfig.php index ca14275ab1350..2289a5008e53c 100644 --- a/apps/files_external/lib/MountConfig.php +++ b/apps/files_external/lib/MountConfig.php @@ -16,7 +16,10 @@ use OCA\Files_External\Service\UserStoragesService; use OCP\AppFramework\QueryException; use OCP\Files\StorageNotAvailableException; +use OCP\IConfig; use OCP\IL10N; +use OCP\Security\ISecureRandom; +use OCP\Server; use OCP\Util; use phpseclib\Crypt\AES; use Psr\Log\LoggerInterface; @@ -51,7 +54,7 @@ public function __construct( */ public static function substitutePlaceholdersInConfig($input, ?string $userId = null) { /** @var BackendService $backendService */ - $backendService = \OC::$server->get(BackendService::class); + $backendService = Server::get(BackendService::class); /** @var IConfigHandler[] $handlers */ $handlers = $backendService->getConfigHandlers(); foreach ($handlers as $handler) { @@ -99,7 +102,7 @@ public static function getBackendStatus($class, $options, $isPersonal, $testOnly throw $e; } } catch (\Exception $exception) { - \OC::$server->get(LoggerInterface::class)->error($exception->getMessage(), ['exception' => $exception, 'app' => 'files_external']); + Server::get(LoggerInterface::class)->error($exception->getMessage(), ['exception' => $exception, 'app' => 'files_external']); throw $exception; } } @@ -191,7 +194,7 @@ public static function decryptPasswords($options) { */ private static function encryptPassword($password) { $cipher = self::getCipher(); - $iv = \OC::$server->getSecureRandom()->generate(16); + $iv = Server::get(ISecureRandom::class)->generate(16); $cipher->setIV($iv); return base64_encode($iv . $cipher->encrypt($password)); } @@ -218,7 +221,7 @@ private static function decryptPassword($encryptedPassword) { */ private static function getCipher() { $cipher = new AES(AES::MODE_CBC); - $cipher->setKey(\OC::$server->getConfig()->getSystemValue('passwordsalt', null)); + $cipher->setKey(Server::get(IConfig::class)->getSystemValue('passwordsalt', null)); return $cipher; } diff --git a/apps/files_external/lib/Service/BackendService.php b/apps/files_external/lib/Service/BackendService.php index e37a0ab464965..b452b27e17503 100644 --- a/apps/files_external/lib/Service/BackendService.php +++ b/apps/files_external/lib/Service/BackendService.php @@ -8,13 +8,14 @@ use OCA\Files_External\Config\IConfigHandler; use OCA\Files_External\Lib\Auth\AuthMechanism; - use OCA\Files_External\Lib\Backend\Backend; + use OCA\Files_External\Lib\Config\IAuthMechanismProvider; use OCA\Files_External\Lib\Config\IBackendProvider; use OCP\EventDispatcher\GenericEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; +use OCP\Server; /** * Service class to manage backend definitions @@ -88,7 +89,7 @@ public function registerBackendProvider(IBackendProvider $provider) { private function callForRegistrations() { static $eventSent = false; if (!$eventSent) { - \OC::$server->get(IEventDispatcher::class)->dispatch( + Server::get(IEventDispatcher::class)->dispatch( 'OCA\\Files_External::loadAdditionalBackends', new GenericEvent() ); diff --git a/apps/files_external/lib/Service/LegacyStoragesService.php b/apps/files_external/lib/Service/LegacyStoragesService.php index 20a26a07e8b19..5be1a084b6697 100644 --- a/apps/files_external/lib/Service/LegacyStoragesService.php +++ b/apps/files_external/lib/Service/LegacyStoragesService.php @@ -8,6 +8,7 @@ use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\MountConfig; +use OCP\Server; use Psr\Log\LoggerInterface; /** @@ -124,7 +125,7 @@ public function getAllStorages() { $parts = explode('/', ltrim($rootMountPath, '/'), 3); if (count($parts) < 3) { // something went wrong, skip - \OC::$server->get(LoggerInterface::class)->error('Could not parse mount point "' . $rootMountPath . '"', ['app' => 'files_external']); + Server::get(LoggerInterface::class)->error('Could not parse mount point "' . $rootMountPath . '"', ['app' => 'files_external']); continue; } $relativeMountPath = rtrim($parts[2], '/'); @@ -172,7 +173,7 @@ public function getAllStorages() { } } catch (\UnexpectedValueException $e) { // don't die if a storage backend doesn't exist - \OC::$server->get(LoggerInterface::class)->error('Could not load storage.', [ + Server::get(LoggerInterface::class)->error('Could not load storage.', [ 'app' => 'files_external', 'exception' => $e, ]); diff --git a/apps/files_external/lib/Service/StoragesService.php b/apps/files_external/lib/Service/StoragesService.php index 67de6e8b6b8c1..73642d85f88e0 100644 --- a/apps/files_external/lib/Service/StoragesService.php +++ b/apps/files_external/lib/Service/StoragesService.php @@ -19,6 +19,7 @@ use OCP\Files\Config\IUserMountCache; use OCP\Files\Events\InvalidateMountCacheEvent; use OCP\Files\StorageNotAvailableException; +use OCP\Server; use OCP\Util; use Psr\Log\LoggerInterface; @@ -76,13 +77,13 @@ protected function getStorageConfigFromDBMount(array $mount) { return $config; } catch (\UnexpectedValueException $e) { // don't die if a storage backend doesn't exist - \OC::$server->get(LoggerInterface::class)->error('Could not load storage.', [ + Server::get(LoggerInterface::class)->error('Could not load storage.', [ 'app' => 'files_external', 'exception' => $e, ]); return null; } catch (\InvalidArgumentException $e) { - \OC::$server->get(LoggerInterface::class)->error('Could not load storage.', [ + Server::get(LoggerInterface::class)->error('Could not load storage.', [ 'app' => 'files_external', 'exception' => $e, ]); diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index c5af1bddaa72c..d1a8f78076a29 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -107,7 +107,7 @@ function writeParameterInput($parameter, $options, $classes = []) { getConfig()->getSystemValue('files_external_allow_create_new_local', true); + $canCreateNewLocalStorage = \OCP\Server::get(\OCP\IConfig::class)->getSystemValue('files_external_allow_create_new_local', true); ?>

t('External storage')); ?>

@@ -168,7 +168,7 @@ function writeParameterInput($parameter, $options, $classes = []) { continue; } // ignore deprecated backends?> - + '> diff --git a/apps/files_external/tests/Service/DBConfigServiceTest.php b/apps/files_external/tests/Service/DBConfigServiceTest.php index 968c166a50587..51051d6c9f24c 100644 --- a/apps/files_external/tests/Service/DBConfigServiceTest.php +++ b/apps/files_external/tests/Service/DBConfigServiceTest.php @@ -8,6 +8,8 @@ use OCA\Files_External\Service\DBConfigService; use OCP\IDBConnection; +use OCP\Security\ICrypto; +use OCP\Server; use Test\TestCase; /** @@ -28,8 +30,8 @@ class DBConfigServiceTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); - $this->dbConfig = new DBConfigService($this->connection, \OC::$server->getCrypto()); + $this->connection = Server::get(IDBConnection::class); + $this->dbConfig = new DBConfigService($this->connection, Server::get(ICrypto::class)); } protected function tearDown(): void { diff --git a/apps/files_external/tests/Service/StoragesServiceTest.php b/apps/files_external/tests/Service/StoragesServiceTest.php index 797d4382ae90f..8d24b98d6af61 100644 --- a/apps/files_external/tests/Service/StoragesServiceTest.php +++ b/apps/files_external/tests/Service/StoragesServiceTest.php @@ -10,9 +10,9 @@ use OC\Files\Filesystem; use OCA\Files_External\Lib\Auth\AuthMechanism; use OCA\Files_External\Lib\Auth\InvalidAuth; - use OCA\Files_External\Lib\Backend\Backend; use OCA\Files_External\Lib\Backend\InvalidBackend; + use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\MountConfig; use OCA\Files_External\NotFoundException; @@ -25,8 +25,10 @@ use OCP\Files\Config\IUserMountCache; use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage\IStorage; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IUser; +use OCP\Security\ICrypto; use OCP\Server; use OCP\Util; @@ -87,9 +89,9 @@ abstract class StoragesServiceTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->dbConfig = new CleaningDBConfig(\OC::$server->getDatabaseConnection(), \OC::$server->getCrypto()); + $this->dbConfig = new CleaningDBConfig(Server::get(IDBConnection::class), Server::get(ICrypto::class)); self::$hookCalls = []; - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); $this->dataDir = $config->getSystemValue( 'datadirectory', \OC::$SERVERROOT . '/data/' @@ -301,7 +303,7 @@ public function testDeleteStorage($backendOptions, $rustyStorageId): void { $storageCache = new Storage($rustyStorageId, true, Server::get(IDBConnection::class)); /** @var IUserMountCache $mountCache */ - $mountCache = \OC::$server->get(IUserMountCache::class); + $mountCache = Server::get(IUserMountCache::class); $mountCache->clear(); $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('test'); @@ -340,7 +342,7 @@ public function testDeleteStorage($backendOptions, $rustyStorageId): void { $this->assertTrue($caught); // storage id was removed from oc_storages - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = Server::get(IDBConnection::class)->getQueryBuilder(); $storageCheckQuery = $qb->select('*') ->from('storages') ->where($qb->expr()->eq('numeric_id', $qb->expr()->literal($numericId))); diff --git a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php index 571664b32c8f0..e3c5cd486e9a4 100644 --- a/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php +++ b/apps/files_external/tests/Service/UserGlobalStoragesServiceTest.php @@ -15,6 +15,7 @@ use OCP\IGroupManager; use OCP\IUser; use OCP\IUserSession; +use OCP\Server; use Test\Traits\UserTrait; /** @@ -47,7 +48,7 @@ protected function setUp(): void { $this->globalStoragesService = $this->service; - $this->user = new User(self::USER_ID, null, \OC::$server->get(IEventDispatcher::class)); + $this->user = new User(self::USER_ID, null, Server::get(IEventDispatcher::class)); /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */ $userSession = $this->createMock(IUserSession::class); $userSession diff --git a/apps/files_external/tests/Service/UserStoragesServiceTest.php b/apps/files_external/tests/Service/UserStoragesServiceTest.php index 7bf101ebfc4b3..6c797d7c55fed 100644 --- a/apps/files_external/tests/Service/UserStoragesServiceTest.php +++ b/apps/files_external/tests/Service/UserStoragesServiceTest.php @@ -9,12 +9,13 @@ use OC\Files\Filesystem; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\MountConfig; - use OCA\Files_External\NotFoundException; + use OCA\Files_External\Service\GlobalStoragesService; use OCA\Files_External\Service\StoragesService; use OCA\Files_External\Service\UserStoragesService; use OCP\IUserSession; +use OCP\Server; use Test\Traits\UserTrait; /** @@ -39,7 +40,7 @@ protected function setUp(): void { $this->userId = $this->getUniqueID('user_'); $this->createUser($this->userId, $this->userId); - $this->user = \OC::$server->getUserManager()->get($this->userId); + $this->user = Server::get(\OCP\User\IManager::class)->get($this->userId); /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */ $userSession = $this->createMock(IUserSession::class); diff --git a/apps/files_external/tests/Storage/WebdavTest.php b/apps/files_external/tests/Storage/WebdavTest.php index 872f1b5d0e295..f1d3415e91eaf 100644 --- a/apps/files_external/tests/Storage/WebdavTest.php +++ b/apps/files_external/tests/Storage/WebdavTest.php @@ -8,6 +8,8 @@ use OC\Files\Storage\DAV; use OC\Files\Type\Detection; +use OCP\Files\IMimeTypeDetector; +use OCP\Server; /** * Class WebdavTest @@ -45,7 +47,7 @@ public function testMimetypeFallback(): void { $this->instance->file_put_contents('foo.bar', 'asd'); /** @var Detection $mimeDetector */ - $mimeDetector = \OC::$server->getMimeTypeDetector(); + $mimeDetector = Server::get(IMimeTypeDetector::class); $mimeDetector->registerType('bar', 'application/x-bar'); $this->assertEquals('application/x-bar', $this->instance->getMimeType('foo.bar')); diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 1fb624800493c..76010ec0869f1 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -45,6 +45,7 @@ use OCP\IL10N; use OCP\IPreview; use OCP\IRequest; +use OCP\ITagManager; use OCP\IURLGenerator; use OCP\IUserManager; use OCP\Lock\ILockingProvider; @@ -327,7 +328,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra private function getDisplayNameFromAddressBook(string $query, string $property): string { // FIXME: If we inject the contacts manager it gets initialized before any address books are registered try { - $result = \OC::$server->getContactsManager()->search($query, [$property], [ + $result = Server::get(\OCP\Contacts\IManager::class)->search($query, [$property], [ 'limit' => 1, 'enumeration' => false, 'strict_search' => true, @@ -470,7 +471,7 @@ public function getShare(string $id, bool $include_tags = false): DataResponse { $share = $this->formatShare($share); if ($include_tags) { - $share = Helper::populateTags([$share], \OC::$server->getTagManager()); + $share = Helper::populateTags([$share], Server::get(ITagManager::class)); } else { $share = [$share]; } @@ -752,7 +753,7 @@ public function createShare( $share->setSharedWith($shareWith); $share->setPermissions($permissions); } elseif ($shareType === IShare::TYPE_CIRCLE) { - if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { + if (!Server::get(IAppManager::class)->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { throw new OCSNotFoundException($this->l->t('You cannot share to a Team if the app is not enabled')); } @@ -839,7 +840,7 @@ private function getSharedWithMe($node, bool $includeTags): array { } if ($includeTags) { - $formatted = Helper::populateTags($formatted, \OC::$server->getTagManager()); + $formatted = Helper::populateTags($formatted, Server::get(ITagManager::class)); } return $formatted; @@ -1093,7 +1094,7 @@ private function getFormattedShares( if ($includeTags) { $formatted = - Helper::populateTags($formatted, \OC::$server->getTagManager()); + Helper::populateTags($formatted, Server::get(ITagManager::class)); } return $formatted; @@ -1968,7 +1969,7 @@ private function shareProviderResharingRights(string $userId, IShare $share, $no return true; } - if ($share->getShareType() === IShare::TYPE_CIRCLE && \OC::$server->getAppManager()->isEnabledForUser('circles') + if ($share->getShareType() === IShare::TYPE_CIRCLE && Server::get(IAppManager::class)->isEnabledForUser('circles') && class_exists('\OCA\Circles\Api\v1\Circles')) { $hasCircleId = (str_ends_with($share->getSharedWith(), ']')); $shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0); diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php index 9a9e94a7ee2b0..d61dd7faf305a 100644 --- a/apps/files_sharing/lib/Controller/ShareesAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php @@ -12,6 +12,7 @@ use OC\Collaboration\Collaborators\SearchResult; use OC\Share\Share; use OCA\Files_Sharing\ResponseDefinitions; +use OCP\App\IAppManager; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\DataResponse; @@ -24,6 +25,7 @@ use OCP\IConfig; use OCP\IRequest; use OCP\IURLGenerator; +use OCP\Server; use OCP\Share\IManager; use OCP\Share\IShare; use function array_slice; @@ -155,7 +157,7 @@ public function search(string $search = '', ?string $itemType = null, int $page } // FIXME: DI - if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { + if (Server::get(IAppManager::class)->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { $shareTypes[] = IShare::TYPE_CIRCLE; } @@ -328,7 +330,7 @@ public function findRecommended(string $itemType, $shareType = null): DataRespon } // FIXME: DI - if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { + if (Server::get(IAppManager::class)->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { $shareTypes[] = IShare::TYPE_CIRCLE; } diff --git a/apps/files_sharing/lib/External/MountProvider.php b/apps/files_sharing/lib/External/MountProvider.php index a29fdd2d54498..ad6e2ef17795d 100644 --- a/apps/files_sharing/lib/External/MountProvider.php +++ b/apps/files_sharing/lib/External/MountProvider.php @@ -10,8 +10,10 @@ use OCP\Federation\ICloudIdManager; use OCP\Files\Config\IMountProvider; use OCP\Files\Storage\IStorageFactory; +use OCP\Http\Client\IClientService; use OCP\IDBConnection; use OCP\IUser; +use OCP\Server; class MountProvider implements IMountProvider { public const STORAGE = '\OCA\Files_Sharing\External\Storage'; @@ -42,7 +44,7 @@ public function getMount(IUser $user, $data, IStorageFactory $storageFactory) { $data['mountpoint'] = $mountPoint; $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']); $data['certificateManager'] = \OC::$server->getCertificateManager(); - $data['HttpClientService'] = \OC::$server->getHTTPClientService(); + $data['HttpClientService'] = Server::get(IClientService::class); return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory); } diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php index bacd2b3f7cf99..a9781b91a6cb6 100644 --- a/apps/files_sharing/lib/External/Storage.php +++ b/apps/files_sharing/lib/External/Storage.php @@ -53,7 +53,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, * @param array{HttpClientService: IClientService, manager: ExternalShareManager, cloudId: ICloudId, mountpoint: string, token: string, password: ?string}|array $options */ public function __construct($options) { - $this->memcacheFactory = \OC::$server->getMemCacheFactory(); + $this->memcacheFactory = Server::get(ICacheFactory::class); $this->httpClient = $options['HttpClientService']; $this->manager = $options['manager']; $this->cloudId = $options['cloudId']; @@ -304,7 +304,7 @@ public function getShareInfo(int $depth = -1) { $url = rtrim($remote, '/') . '/index.php/apps/files_sharing/shareinfo?t=' . $token; // TODO: DI - $client = \OC::$server->getHTTPClientService()->newClient(); + $client = Server::get(IClientService::class)->newClient(); try { $response = $client->post($url, array_merge($this->getDefaultRequestOptions(), [ 'body' => ['password' => $password, 'depth' => $depth], diff --git a/apps/files_sharing/lib/Helper.php b/apps/files_sharing/lib/Helper.php index 1e5c5c8abe5c3..fe0cc88ba5f6f 100644 --- a/apps/files_sharing/lib/Helper.php +++ b/apps/files_sharing/lib/Helper.php @@ -9,6 +9,8 @@ use OC\Files\Filesystem; use OC\Files\View; use OCA\Files_Sharing\AppInfo\Application; +use OCP\IConfig; +use OCP\Server; use OCP\Util; class Helper { @@ -52,7 +54,7 @@ public static function getShareFolder(?View $view = null, ?string $userId = null $view = Filesystem::getView(); } - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); $systemDefault = $config->getSystemValue('share_folder', '/'); $allowCustomShareFolder = $config->getSystemValueBool('sharing.allow_custom_share_folder', true); @@ -86,6 +88,6 @@ public static function getShareFolder(?View $view = null, ?string $userId = null * @param string $shareFolder */ public static function setShareFolder($shareFolder) { - \OC::$server->getConfig()->setSystemValue('share_folder', $shareFolder); + Server::get(IConfig::class)->setSystemValue('share_folder', $shareFolder); } } diff --git a/apps/files_sharing/lib/Hooks.php b/apps/files_sharing/lib/Hooks.php index 6a297f1e87589..7c8b80fb47a02 100644 --- a/apps/files_sharing/lib/Hooks.php +++ b/apps/files_sharing/lib/Hooks.php @@ -8,10 +8,11 @@ use OC\Files\Filesystem; use OC\Files\View; +use OCP\Server; class Hooks { public static function deleteUser($params) { - $manager = \OC::$server->get(External\Manager::class); + $manager = Server::get(External\Manager::class); $manager->removeUserShares($params['uid']); } diff --git a/apps/files_sharing/lib/Listener/LoadAdditionalListener.php b/apps/files_sharing/lib/Listener/LoadAdditionalListener.php index fc6516a83e2c9..b089c8309b78a 100644 --- a/apps/files_sharing/lib/Listener/LoadAdditionalListener.php +++ b/apps/files_sharing/lib/Listener/LoadAdditionalListener.php @@ -12,6 +12,7 @@ use OCA\Files_Sharing\AppInfo\Application; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\Server; use OCP\Share\IManager; use OCP\Util; @@ -26,7 +27,7 @@ public function handle(Event $event): void { Util::addScript(Application::APP_ID, 'additionalScripts', 'files'); Util::addStyle(Application::APP_ID, 'icons'); - $shareManager = \OC::$server->get(IManager::class); + $shareManager = Server::get(IManager::class); if ($shareManager->shareApiEnabled() && class_exists('\OCA\Files\App')) { Util::addInitScript(Application::APP_ID, 'init'); } diff --git a/apps/files_sharing/lib/ShareBackend/File.php b/apps/files_sharing/lib/ShareBackend/File.php index 56a4aa47e604c..052ea0ff1b3f5 100644 --- a/apps/files_sharing/lib/ShareBackend/File.php +++ b/apps/files_sharing/lib/ShareBackend/File.php @@ -12,6 +12,7 @@ use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Files_Sharing\Helper; use OCP\Files\NotFoundException; +use OCP\IDBConnection; use OCP\Server; use OCP\Share\IShare; use OCP\Share_Backend_File_Dependent; @@ -183,7 +184,7 @@ protected static function resolveReshares($source) { if (isset($source['parent'])) { $parent = $source['parent']; while (isset($parent)) { - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = Server::get(IDBConnection::class)->getQueryBuilder(); $qb->select('parent', 'uid_owner') ->from('share') ->where( diff --git a/apps/files_sharing/lib/ShareBackend/Folder.php b/apps/files_sharing/lib/ShareBackend/Folder.php index fefdd7f667ce8..9df0ed3bbd3c0 100644 --- a/apps/files_sharing/lib/ShareBackend/Folder.php +++ b/apps/files_sharing/lib/ShareBackend/Folder.php @@ -6,6 +6,8 @@ */ namespace OCA\Files_Sharing\ShareBackend; +use OCP\IDBConnection; +use OCP\Server; use OCP\Share_Backend_Collection; class Folder extends File implements Share_Backend_Collection { @@ -13,7 +15,7 @@ public function getChildren($itemSource) { $children = []; $parents = [$itemSource]; - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = Server::get(IDBConnection::class)->getQueryBuilder(); $qb->select('id') ->from('mimetypes') ->where( @@ -29,7 +31,7 @@ public function getChildren($itemSource) { $mimetype = -1; } while (!empty($parents)) { - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = Server::get(IDBConnection::class)->getQueryBuilder(); $parents = array_map(function ($parent) use ($qb) { return $qb->createNamedParameter($parent); diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index 5f7e8f376f150..fc5b533af6420 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -17,6 +17,7 @@ use OCP\Files\Events\InvalidateMountCacheEvent; use OCP\Files\Storage\IStorageFactory; use OCP\ICache; +use OCP\IDBConnection; use OCP\IUser; use OCP\Server; use OCP\Share\Events\VerifyMountPointEvent; @@ -121,7 +122,7 @@ private function updateFileTarget($newPath, &$share) { foreach ($this->groupedShares as $tmpShare) { $tmpShare->setTarget($newPath); - \OC::$server->getShareManager()->moveShare($tmpShare, $this->user->getUID()); + Server::get(\OCP\Share\IManager::class)->moveShare($tmpShare, $this->user->getUID()); } $this->eventDispatcher->dispatchTyped(new InvalidateMountCacheEvent($this->user)); @@ -249,7 +250,7 @@ public function getNumericStorageId() { if (!is_null($this->getShare()->getNodeCacheEntry())) { return $this->getShare()->getNodeCacheEntry()->getStorageId(); } else { - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $builder = Server::get(IDBConnection::class)->getQueryBuilder(); $query = $builder->select('storage') ->from('filecache') diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index f54252d0458df..249922a7c14ec 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -36,6 +36,7 @@ use OCP\Files\Storage\ISharedStorage; use OCP\Files\Storage\IStorage; use OCP\Lock\ILockingProvider; +use OCP\Server; use OCP\Share\IShare; use OCP\Util; use Psr\Log\LoggerInterface; @@ -90,7 +91,7 @@ class SharedStorage extends Jail implements LegacyISharedStorage, ISharedStorage public function __construct(array $parameters) { $this->ownerView = $parameters['ownerView']; - $this->logger = \OC::$server->get(LoggerInterface::class); + $this->logger = Server::get(LoggerInterface::class); $this->superShare = $parameters['superShare']; $this->groupedShares = $parameters['groupedShares']; @@ -150,7 +151,7 @@ private function init() { } /** @var IRootFolder $rootFolder */ - $rootFolder = \OC::$server->get(IRootFolder::class); + $rootFolder = Server::get(IRootFolder::class); $this->ownerUserFolder = $rootFolder->getUserFolder($this->superShare->getShareOwner()); $sourceId = $this->superShare->getNodeId(); $ownerNodes = $this->ownerUserFolder->getById($sourceId); @@ -412,7 +413,7 @@ public function getCache(string $path = '', ?IStorage $storage = null): ICache { $this->cache = new Cache( $storage, $sourceRoot, - \OC::$server->get(CacheDependencies::class), + Server::get(CacheDependencies::class), $this->getShare() ); return $this->cache; @@ -458,7 +459,7 @@ public function getWatcher(string $path = '', ?IStorage $storage = null): IWatch */ public function unshareStorage(): bool { foreach ($this->groupedShares as $share) { - \OC::$server->getShareManager()->deleteFromSelf($share, $this->user); + Server::get(\OCP\Share\IManager::class)->deleteFromSelf($share, $this->user); } return true; } diff --git a/apps/files_sharing/lib/Updater.php b/apps/files_sharing/lib/Updater.php index 226cf3e7fd489..998be54fc6132 100644 --- a/apps/files_sharing/lib/Updater.php +++ b/apps/files_sharing/lib/Updater.php @@ -11,6 +11,7 @@ use OC\Files\Mount\MountPoint; use OCP\Constants; use OCP\Files\Folder; +use OCP\Files\Mount\IMountManager; use OCP\Server; use OCP\Share\IShare; @@ -48,7 +49,7 @@ private static function moveShareInOrOutOfShare($path): void { $src = $userFolder->get($path); - $shareManager = \OC::$server->getShareManager(); + $shareManager = Server::get(\OCP\Share\IManager::class); // We intentionally include invalid shares, as they have been automatically invalidated due to the node no longer // being accessible for the user. Only in this case where we adjust the share after it was moved we want to ignore @@ -88,7 +89,7 @@ private static function moveShareInOrOutOfShare($path): void { } // Check if the destination is inside a share - $mountManager = \OC::$server->getMountManager(); + $mountManager = Server::get(IMountManager::class); $dstMount = $mountManager->find($src->getPath()); //Ownership is moved over diff --git a/apps/files_sharing/templates/Settings/personal.php b/apps/files_sharing/templates/Settings/personal.php index 1f51f69e7f741..5b4f9891b939b 100644 --- a/apps/files_sharing/templates/Settings/personal.php +++ b/apps/files_sharing/templates/Settings/personal.php @@ -5,7 +5,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -script(\OCA\Files_Sharing\AppInfo\Application::APP_ID, 'personal-settings'); +\OCP\Util::addScript(\OCA\Files_Sharing\AppInfo\Application::APP_ID, 'personal-settings', 'core'); ?>
diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 7620d309ff605..d328d57dee26e 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -24,13 +24,13 @@ - + get(\bantu\IniGetWrapper\IniGetWrapper::class)->getBytes('upload_max_filesize'); -$post_max_size = OC::$server->get(\bantu\IniGetWrapper\IniGetWrapper::class)->getBytes('post_max_size'); +$upload_max_filesize = \OCP\Server::get(\bantu\IniGetWrapper\IniGetWrapper::class)->getBytes('upload_max_filesize'); +$post_max_size = \OCP\Server::get(\bantu\IniGetWrapper\IniGetWrapper::class)->getBytes('post_max_size'); $maxUploadFilesize = min($upload_max_filesize, $post_max_size); ?> @@ -137,7 +137,7 @@ class="emptycontent has-note">
+ data-url="linkTo('files', 'ajax/upload.php')); ?>" />
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index c20644fc2fca3..fc44798a091e4 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -19,12 +19,15 @@ use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\Constants; use OCP\Files\Folder; +use OCP\Files\IRootFolder; use OCP\IConfig; use OCP\IDateTimeZone; use OCP\IL10N; use OCP\IPreview; use OCP\IRequest; +use OCP\IURLGenerator; use OCP\Mail\IMailer; +use OCP\Server; use OCP\Share\IProviderFactory; use OCP\Share\IShare; use OCP\UserStatus\IManager as IUserStatusManager; @@ -52,8 +55,8 @@ class ApiTest extends TestCase { protected function setUp(): void { parent::setUp(); - \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups', 'no'); - \OC::$server->getConfig()->setAppValue('core', 'shareapi_expire_after_n_days', '7'); + Server::get(IConfig::class)->setAppValue('core', 'shareapi_exclude_groups', 'no'); + Server::get(IConfig::class)->setAppValue('core', 'shareapi_expire_after_n_days', '7'); Filesystem::getLoader()->removeStorageWrapper('sharing_mask'); @@ -112,10 +115,10 @@ private function createOCS($userId) { self::APP_NAME, $this->getMockBuilder(IRequest::class)->getMock(), $this->shareManager, - \OC::$server->getGroupManager(), - \OC::$server->getUserManager(), - \OC::$server->getRootFolder(), - \OC::$server->getURLGenerator(), + Server::get(\OCP\Group\IManager::class), + Server::get(\OCP\User\IManager::class), + Server::get(IRootFolder::class), + Server::get(IURLGenerator::class), $l, $config, $appManager, @@ -212,7 +215,7 @@ public function testCreateShareLink(): void { $this->assertTrue(is_string($data['token'])); // check for correct link - $url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']); + $url = Server::get(IURLGenerator::class)->getAbsoluteURL('/index.php/s/' . $data['token']); $this->assertEquals($url, $data['url']); $this->shareManager->getShareById('ocinternal:' . $data['id']); @@ -243,7 +246,7 @@ public function testCreateShareLinkPublicUpload(): void { $this->assertTrue(is_string($data['token'])); // check for correct link - $url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']); + $url = Server::get(IURLGenerator::class)->getAbsoluteURL('/index.php/s/' . $data['token']); $this->assertEquals($url, $data['url']); $this->shareManager->getShareById('ocinternal:' . $data['id']); @@ -255,7 +258,7 @@ public function testCreateShareLinkPublicUpload(): void { public function testEnforceLinkPassword(): void { $password = md5(time()); - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); $config->setAppValue('core', 'shareapi_enforce_links_password', 'yes'); $ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1); @@ -310,7 +313,7 @@ public function testEnforceLinkPassword(): void { public function testSharePermissions(): void { // sharing file to a user should work if shareapi_exclude_groups is set // to no - \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups', 'no'); + Server::get(IConfig::class)->setAppValue('core', 'shareapi_exclude_groups', 'no'); $ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1); $result = $ocs->createShare($this->filename, Constants::PERMISSION_ALL, IShare::TYPE_USER, self::TEST_FILES_SHARING_API_USER2); @@ -325,8 +328,8 @@ public function testSharePermissions(): void { $ocs->cleanup(); // exclude groups, but not the group the user belongs to. Sharing should still work - \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups', 'yes'); - \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups_list', 'admin,group1,group2'); + Server::get(IConfig::class)->setAppValue('core', 'shareapi_exclude_groups', 'yes'); + Server::get(IConfig::class)->setAppValue('core', 'shareapi_exclude_groups_list', 'admin,group1,group2'); $ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1); $result = $ocs->createShare($this->filename, Constants::PERMISSION_ALL, IShare::TYPE_USER, self::TEST_FILES_SHARING_API_USER2); @@ -341,15 +344,15 @@ public function testSharePermissions(): void { $ocs->cleanup(); // now we exclude the group the user belongs to ('group'), sharing should fail now - \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups_list', 'admin,group'); + Server::get(IConfig::class)->setAppValue('core', 'shareapi_exclude_groups_list', 'admin,group'); $ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1); $ocs->createShare($this->filename, Constants::PERMISSION_ALL, IShare::TYPE_USER, self::TEST_FILES_SHARING_API_USER2); $ocs->cleanup(); // cleanup - \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups', 'no'); - \OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups_list', ''); + Server::get(IConfig::class)->setAppValue('core', 'shareapi_exclude_groups', 'no'); + Server::get(IConfig::class)->setAppValue('core', 'shareapi_exclude_groups_list', ''); $this->addToAssertionCount(1); } @@ -431,7 +434,7 @@ public function testPublicLinkUrl(): void { $id = $data['id']; // check for correct link - $url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']); + $url = Server::get(IURLGenerator::class)->getAbsoluteURL('/index.php/s/' . $data['token']); $this->assertEquals($url, $data['url']); // check for link in getall shares @@ -694,7 +697,7 @@ public function testGetShareFromSubFolderReShares(): void { $share1->setStatus(IShare::STATUS_ACCEPTED); $this->shareManager->updateShare($share1); - $node2 = \OC::$server->getRootFolder()->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get($this->subfolder); + $node2 = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get($this->subfolder); $share2 = $this->shareManager->newShare(); $share2->setNode($node2) ->setSharedBy(self::TEST_FILES_SHARING_API_USER2) @@ -1039,7 +1042,7 @@ public function testUpdateShareExpireDate(): void { $share1->setStatus(IShare::STATUS_ACCEPTED); $this->shareManager->updateShare($share1); - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); // enforce expire date, by default 7 days after the file was shared $config->setAppValue('core', 'shareapi_default_expire_date', 'yes'); @@ -1310,7 +1313,7 @@ public function testPublicLinkExpireDate($date, $valid): void { $this->assertEquals(substr($date, 0, 10), substr($data['expiration'], 0, 10)); // check for correct link - $url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']); + $url = Server::get(IURLGenerator::class)->getAbsoluteURL('/index.php/s/' . $data['token']); $this->assertEquals($url, $data['url']); $share = $this->shareManager->getShareById('ocinternal:' . $data['id']); @@ -1324,7 +1327,7 @@ public function testPublicLinkExpireDate($date, $valid): void { * @group RoutingWeirdness */ public function testCreatePublicLinkExpireDateValid(): void { - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); // enforce expire date, by default 7 days after the file was shared $config->setAppValue('core', 'shareapi_default_expire_date', 'yes'); @@ -1342,7 +1345,7 @@ public function testCreatePublicLinkExpireDateValid(): void { $this->assertEquals($date->format('Y-m-d 00:00:00'), $data['expiration']); // check for correct link - $url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']); + $url = Server::get(IURLGenerator::class)->getAbsoluteURL('/index.php/s/' . $data['token']); $this->assertEquals($url, $data['url']); $share = $this->shareManager->getShareById('ocinternal:' . $data['id']); @@ -1356,7 +1359,7 @@ public function testCreatePublicLinkExpireDateValid(): void { } public function testCreatePublicLinkExpireDateInvalidFuture(): void { - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); // enforce expire date, by default 7 days after the file was shared $config->setAppValue('core', 'shareapi_default_expire_date', 'yes'); @@ -1381,7 +1384,7 @@ public function testCreatePublicLinkExpireDateInvalidFuture(): void { } public function XtestCreatePublicLinkExpireDateInvalidPast() { - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); $date = new \DateTime(); $date->sub(new \DateInterval('P8D')); diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php index 6813accd9be1f..b9340ded68132 100644 --- a/apps/files_sharing/tests/CacheTest.php +++ b/apps/files_sharing/tests/CacheTest.php @@ -14,6 +14,7 @@ use OC\Files\View; use OCA\Files_Sharing\SharedStorage; use OCP\Constants; +use OCP\Server; use OCP\Share\IShare; /** @@ -46,10 +47,10 @@ class CacheTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->shareManager = \OC::$server->getShareManager(); + $this->shareManager = Server::get(\OCP\Share\IManager::class); - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(\OCP\User\IManager::class); $userManager->get(self::TEST_FILES_SHARING_API_USER1)->setDisplayName('User One'); $userManager->get(self::TEST_FILES_SHARING_API_USER2)->setDisplayName('User Two'); diff --git a/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php b/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php index 81e2de72ec12b..888b2cdd59663 100644 --- a/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php +++ b/apps/files_sharing/tests/Command/CleanupRemoteStoragesTest.php @@ -10,6 +10,7 @@ use OCP\Federation\ICloudId; use OCP\Federation\ICloudIdManager; use OCP\IDBConnection; +use OCP\Server; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; @@ -51,13 +52,13 @@ class CleanupRemoteStoragesTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = Server::get(IDBConnection::class); - $storageQuery = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $storageQuery = Server::get(IDBConnection::class)->getQueryBuilder(); $storageQuery->insert('storages') ->setValue('id', $storageQuery->createParameter('id')); - $shareExternalQuery = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $shareExternalQuery = Server::get(IDBConnection::class)->getQueryBuilder(); $shareExternalQuery->insert('share_external') ->setValue('share_token', $shareExternalQuery->createParameter('share_token')) ->setValue('remote', $shareExternalQuery->createParameter('remote')) @@ -67,7 +68,7 @@ protected function setUp(): void { ->setValue('mountpoint', $shareExternalQuery->createParameter('mountpoint')) ->setValue('mountpoint_hash', $shareExternalQuery->createParameter('mountpoint_hash')); - $filesQuery = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $filesQuery = Server::get(IDBConnection::class)->getQueryBuilder(); $filesQuery->insert('filecache') ->setValue('storage', $filesQuery->createParameter('storage')) ->setValue('path', $filesQuery->createParameter('path')) @@ -108,11 +109,11 @@ protected function setUp(): void { } protected function tearDown(): void { - $storageQuery = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $storageQuery = Server::get(IDBConnection::class)->getQueryBuilder(); $storageQuery->delete('storages') ->where($storageQuery->expr()->eq('id', $storageQuery->createParameter('id'))); - $shareExternalQuery = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $shareExternalQuery = Server::get(IDBConnection::class)->getQueryBuilder(); $shareExternalQuery->delete('share_external') ->where($shareExternalQuery->expr()->eq('share_token', $shareExternalQuery->createParameter('share_token'))) ->andWhere($shareExternalQuery->expr()->eq('remote', $shareExternalQuery->createParameter('remote'))); @@ -134,7 +135,7 @@ protected function tearDown(): void { } private function doesStorageExist($numericId) { - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = Server::get(IDBConnection::class)->getQueryBuilder(); $qb->select('*') ->from('storages') ->where($qb->expr()->eq('numeric_id', $qb->createNamedParameter($numericId))); @@ -146,7 +147,7 @@ private function doesStorageExist($numericId) { return true; } - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = Server::get(IDBConnection::class)->getQueryBuilder(); $qb->select('*') ->from('filecache') ->where($qb->expr()->eq('storage', $qb->createNamedParameter($numericId))); diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php index bc8e5dede63cb..2024e18e9184b 100644 --- a/apps/files_sharing/tests/Controller/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php @@ -142,9 +142,9 @@ protected function setUp(): void { $this->oldUser = \OC_User::getUser(); // Create a dummy user - $this->user = \OC::$server->getSecureRandom()->generate(12, ISecureRandom::CHAR_LOWER); + $this->user = Server::get(ISecureRandom::class)->generate(12, ISecureRandom::CHAR_LOWER); - \OC::$server->getUserManager()->createUser($this->user, $this->user); + Server::get(\OCP\User\IManager::class)->createUser($this->user, $this->user); \OC_Util::tearDownFS(); $this->loginAsUser($this->user); } @@ -153,13 +153,13 @@ protected function tearDown(): void { \OC_Util::tearDownFS(); \OC_User::setUserId(''); Filesystem::tearDown(); - $user = \OC::$server->getUserManager()->get($this->user); + $user = Server::get(\OCP\User\IManager::class)->get($this->user); if ($user !== null) { $user->delete(); } \OC_User::setIncognitoMode(false); - \OC::$server->getSession()->set('public_link_authenticated', ''); + Server::get(ISession::class)->set('public_link_authenticated', ''); // Set old user \OC_User::setUserId($this->oldUser); @@ -185,7 +185,7 @@ public function testShowShareInvalidToken(): void { public function testShowShareNotAuthenticated(): void { $this->shareController->setToken('validtoken'); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setPassword('password'); $this->shareManager @@ -637,7 +637,7 @@ public function testShowShareInvalid(): void { $file->method('isShareable')->willReturn(false); $file->method('isReadable')->willReturn(true); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setId(42); $share->setPassword('password') ->setShareOwner('ownerUID') @@ -702,7 +702,7 @@ public function testDisabledOwner(): void { /* @var MockObject|Folder $folder */ $folder = $this->createMock(Folder::class); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setId(42); $share->setPermissions(Constants::PERMISSION_CREATE) ->setShareOwner('ownerUID') @@ -743,7 +743,7 @@ public function testDisabledInitiator(): void { /* @var MockObject|Folder $folder */ $folder = $this->createMock(Folder::class); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setId(42); $share->setPermissions(Constants::PERMISSION_CREATE) ->setShareOwner('ownerUID') diff --git a/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php b/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php index ad3caa2d3f80b..d1076eeaaf60d 100644 --- a/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php +++ b/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php @@ -7,7 +7,9 @@ namespace OCA\Files_Sharing\Tests; use OC\Files\Filesystem; +use OC\SystemConfig; use OCA\Files_Sharing\DeleteOrphanedSharesJob; +use OCP\App\IAppManager; use OCP\Constants; use OCP\IDBConnection; use OCP\Server; @@ -47,7 +49,7 @@ class DeleteOrphanedSharesJobTest extends \Test\TestCase { private $user2; public static function setUpBeforeClass(): void { - $appManager = \OC::$server->getAppManager(); + $appManager = Server::get(IAppManager::class); self::$trashBinStatus = $appManager->isEnabledForUser('files_trashbin'); $appManager->disableApp('files_trashbin'); @@ -57,25 +59,25 @@ public static function setUpBeforeClass(): void { public static function tearDownAfterClass(): void { if (self::$trashBinStatus) { - \OC::$server->getAppManager()->enableApp('files_trashbin'); + Server::get(IAppManager::class)->enableApp('files_trashbin'); } } protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = Server::get(IDBConnection::class); // clear occasional leftover shares from other tests $this->connection->executeUpdate('DELETE FROM `*PREFIX*share`'); $this->user1 = $this->getUniqueID('user1_'); $this->user2 = $this->getUniqueID('user2_'); - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(\OCP\User\IManager::class); $userManager->createUser($this->user1, 'pass'); $userManager->createUser($this->user2, 'pass'); - \OC::registerShareHooks(\OC::$server->getSystemConfig()); + \OC::registerShareHooks(Server::get(SystemConfig::class)); $this->job = Server::get(DeleteOrphanedSharesJob::class); } @@ -83,7 +85,7 @@ protected function setUp(): void { protected function tearDown(): void { $this->connection->executeUpdate('DELETE FROM `*PREFIX*share`'); - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(\OCP\User\IManager::class); $user1 = $userManager->get($this->user1); if ($user1) { $user1->delete(); @@ -118,7 +120,7 @@ public function testClearShares(): void { $testFolder = $user1Folder->newFolder('test'); $testSubFolder = $testFolder->newFolder('sub'); - $shareManager = \OC::$server->getShareManager(); + $shareManager = Server::get(\OCP\Share\IManager::class); $share = $shareManager->newShare(); $share->setNode($testSubFolder) diff --git a/apps/files_sharing/tests/EncryptedSizePropagationTest.php b/apps/files_sharing/tests/EncryptedSizePropagationTest.php index af2cf379358e3..1430e5f17ac2f 100644 --- a/apps/files_sharing/tests/EncryptedSizePropagationTest.php +++ b/apps/files_sharing/tests/EncryptedSizePropagationTest.php @@ -7,6 +7,8 @@ namespace OCA\Files_Sharing\Tests; use OC\Files\View; +use OCP\ITempManager; +use OCP\Server; use Test\Traits\EncryptionTrait; /** @@ -17,7 +19,7 @@ class EncryptedSizePropagationTest extends SizePropagationTest { protected function setupUser($name, $password = '') { $this->createUser($name, $password); - $tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder(); + $tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder(); $this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]); $this->config->setAppValue('encryption', 'useMasterKey', '0'); $this->setupForUser($name, $password); diff --git a/apps/files_sharing/tests/EtagPropagationTest.php b/apps/files_sharing/tests/EtagPropagationTest.php index cca19e7afd966..930279a531cd8 100644 --- a/apps/files_sharing/tests/EtagPropagationTest.php +++ b/apps/files_sharing/tests/EtagPropagationTest.php @@ -9,6 +9,8 @@ use OC\Files\Filesystem; use OC\Files\View; use OCP\Constants; +use OCP\Files\IRootFolder; +use OCP\Server; use OCP\Share\IShare; /** @@ -33,8 +35,8 @@ protected function setUpShares() { $this->fileIds[self::TEST_FILES_SHARING_API_USER3] = []; $this->fileIds[self::TEST_FILES_SHARING_API_USER4] = []; - $rootFolder = \OC::$server->getRootFolder(); - $shareManager = \OC::$server->getShareManager(); + $rootFolder = Server::get(IRootFolder::class); + $shareManager = Server::get(\OCP\Share\IManager::class); $this->rootView = new View(''); $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); @@ -264,7 +266,7 @@ public function testOwnerUnshares(): void { $this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo); $node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder'); - $shareManager = \OC::$server->getShareManager(); + $shareManager = Server::get(\OCP\Share\IManager::class); $shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node, true); foreach ($shares as $share) { @@ -287,7 +289,7 @@ public function testOwnerUnsharesFlatReshares(): void { $this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo); $node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder/inside'); - $shareManager = \OC::$server->getShareManager(); + $shareManager = Server::get(\OCP\Share\IManager::class); $shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node, true); foreach ($shares as $share) { diff --git a/apps/files_sharing/tests/ExpireSharesJobTest.php b/apps/files_sharing/tests/ExpireSharesJobTest.php index b0f78d12eed26..779e4a9050073 100644 --- a/apps/files_sharing/tests/ExpireSharesJobTest.php +++ b/apps/files_sharing/tests/ExpireSharesJobTest.php @@ -6,10 +6,12 @@ */ namespace OCA\Files_Sharing\Tests; +use OC\SystemConfig; use OCA\Files_Sharing\ExpireSharesJob; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Constants; use OCP\IDBConnection; +use OCP\Server; use OCP\Share\IManager; use OCP\Share\IShare; @@ -37,26 +39,26 @@ class ExpireSharesJobTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = Server::get(IDBConnection::class); // clear occasional leftover shares from other tests $this->connection->executeUpdate('DELETE FROM `*PREFIX*share`'); $this->user1 = $this->getUniqueID('user1_'); $this->user2 = $this->getUniqueID('user2_'); - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(\OCP\User\IManager::class); $userManager->createUser($this->user1, 'longrandompassword'); $userManager->createUser($this->user2, 'longrandompassword'); - \OC::registerShareHooks(\OC::$server->getSystemConfig()); + \OC::registerShareHooks(Server::get(SystemConfig::class)); - $this->job = new ExpireSharesJob(\OC::$server->get(ITimeFactory::class), \OC::$server->get(IManager::class), $this->connection); + $this->job = new ExpireSharesJob(Server::get(ITimeFactory::class), Server::get(IManager::class), $this->connection); } protected function tearDown(): void { $this->connection->executeUpdate('DELETE FROM `*PREFIX*share`'); - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(\OCP\User\IManager::class); $user1 = $userManager->get($this->user1); if ($user1) { $user1->delete(); @@ -115,7 +117,7 @@ public function testExpireLinkShare($addExpiration, $interval, $addInterval, $sh $user1Folder = \OC::$server->getUserFolder($this->user1); $testFolder = $user1Folder->newFolder('test'); - $shareManager = \OC::$server->getShareManager(); + $shareManager = Server::get(\OCP\Share\IManager::class); $share = $shareManager->newShare(); $share->setNode($testFolder) @@ -172,7 +174,7 @@ public function testDoNotExpireOtherShares(): void { $user1Folder = \OC::$server->getUserFolder($this->user1); $testFolder = $user1Folder->newFolder('test'); - $shareManager = \OC::$server->getShareManager(); + $shareManager = Server::get(\OCP\Share\IManager::class); $share = $shareManager->newShare(); $share->setNode($testFolder) diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index 29a873a72eb79..11bda6cdd3292 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -22,6 +22,7 @@ use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\ICacheFactory; +use OCP\IDBConnection; use OCP\IGroup; use OCP\IGroupManager; use OCP\IURLGenerator; @@ -29,6 +30,7 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\OCS\IDiscoveryService; +use OCP\Server; use OCP\Share\IShare; use Psr\Log\LoggerInterface; use Test\Traits\UserTrait; @@ -105,7 +107,7 @@ protected function setUp(): void { $this->manager = $this->createManagerForUser($this->uid); - $this->testMountProvider = new MountProvider(\OC::$server->getDatabaseConnection(), function () { + $this->testMountProvider = new MountProvider(Server::get(IDBConnection::class), function () { return $this->manager; }, new CloudIdManager( $this->contactsManager, @@ -134,7 +136,7 @@ protected function setUp(): void { protected function tearDown(): void { // clear the share external table to avoid side effects - $query = \OC::$server->getDatabaseConnection()->prepare('DELETE FROM `*PREFIX*share_external`'); + $query = Server::get(IDBConnection::class)->prepare('DELETE FROM `*PREFIX*share_external`'); $result = $query->execute(); $result->closeCursor(); @@ -152,11 +154,11 @@ private function createManagerForUser($userId) { return $this->getMockBuilder(Manager::class) ->setConstructorArgs( [ - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->mountManager, new StorageFactory(), $this->clientService, - \OC::$server->getNotificationManager(), + Server::get(\OCP\Notification\IManager::class), \OC::$server->query(IDiscoveryService::class), $this->cloudFederationProviderManager, $this->cloudFederationFactory, diff --git a/apps/files_sharing/tests/HelperTest.php b/apps/files_sharing/tests/HelperTest.php index fcbfc41b603e5..d8b5b9a6f3f81 100644 --- a/apps/files_sharing/tests/HelperTest.php +++ b/apps/files_sharing/tests/HelperTest.php @@ -8,6 +8,8 @@ use OC\Files\Filesystem; use OCA\Files_Sharing\Helper; +use OCP\IConfig; +use OCP\Server; /** * Class HelperTest @@ -29,6 +31,6 @@ public function testSetGetShareFolder(): void { $this->assertTrue(Filesystem::is_dir($sharedFolder)); // cleanup - \OC::$server->getConfig()->deleteSystemValue('share_folder'); + Server::get(IConfig::class)->deleteSystemValue('share_folder'); } } diff --git a/apps/files_sharing/tests/LockingTest.php b/apps/files_sharing/tests/LockingTest.php index 1e822d6339ea8..4c0a4bcb11af2 100644 --- a/apps/files_sharing/tests/LockingTest.php +++ b/apps/files_sharing/tests/LockingTest.php @@ -11,6 +11,7 @@ use OCP\Constants; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; +use OCP\Server; use OCP\Share\IShare; /** @@ -33,7 +34,7 @@ protected function setUp(): void { parent::setUp(); $this->userBackend = new \Test\Util\User\Dummy(); - \OC::$server->getUserManager()->registerBackend($this->userBackend); + Server::get(\OCP\User\IManager::class)->registerBackend($this->userBackend); $this->ownerUid = $this->getUniqueID('owner_'); $this->recipientUid = $this->getUniqueID('recipient_'); @@ -58,7 +59,7 @@ protected function setUp(): void { } protected function tearDown(): void { - \OC::$server->getUserManager()->removeBackend($this->userBackend); + Server::get(\OCP\User\IManager::class)->removeBackend($this->userBackend); parent::tearDown(); } diff --git a/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php b/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php index 9e46232aa3960..9dccfd800252d 100644 --- a/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php +++ b/apps/files_sharing/tests/Migration/SetPasswordColumnTest.php @@ -11,6 +11,7 @@ use OCP\IConfig; use OCP\IDBConnection; use OCP\Migration\IOutput; +use OCP\Server; use OCP\Share\IShare; /** @@ -34,7 +35,7 @@ class SetPasswordColumnTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = Server::get(IDBConnection::class); $this->config = $this->createMock(IConfig::class); $this->migration = new SetPasswordColumn($this->connection, $this->config); diff --git a/apps/files_sharing/tests/PropagationTestCase.php b/apps/files_sharing/tests/PropagationTestCase.php index 04852e53e2113..1c67b1b9337b2 100644 --- a/apps/files_sharing/tests/PropagationTestCase.php +++ b/apps/files_sharing/tests/PropagationTestCase.php @@ -8,6 +8,8 @@ use OC\Files\View; use OCA\Files_Sharing\Helper; +use OCP\IUserSession; +use OCP\Server; abstract class PropagationTestCase extends TestCase { /** @@ -42,7 +44,7 @@ abstract protected function setUpShares(); * @param string $subPath */ protected function assertEtagsChanged($users, $subPath = '') { - $oldUser = \OC::$server->getUserSession()->getUser(); + $oldUser = Server::get(IUserSession::class)->getUser(); foreach ($users as $user) { $this->loginAsUser($user); $id = $this->fileIds[$user][$subPath]; @@ -59,7 +61,7 @@ protected function assertEtagsChanged($users, $subPath = '') { * @param string $subPath */ protected function assertEtagsNotChanged($users, $subPath = '') { - $oldUser = \OC::$server->getUserSession()->getUser(); + $oldUser = Server::get(IUserSession::class)->getUser(); foreach ($users as $user) { $this->loginAsUser($user); $id = $this->fileIds[$user][$subPath]; diff --git a/apps/files_sharing/tests/ShareTest.php b/apps/files_sharing/tests/ShareTest.php index b79235676e27a..f3ff71395d219 100644 --- a/apps/files_sharing/tests/ShareTest.php +++ b/apps/files_sharing/tests/ShareTest.php @@ -10,6 +10,8 @@ use OC\Files\Filesystem; use OCA\Files_Sharing\Helper; use OCP\Constants; +use OCP\IConfig; +use OCP\Server; use OCP\Share\IShare; /** @@ -53,8 +55,8 @@ protected function tearDown(): void { } public function testUnshareFromSelf(): void { - $groupManager = \OC::$server->getGroupManager(); - $userManager = \OC::$server->getUserManager(); + $groupManager = Server::get(\OCP\Group\IManager::class); + $userManager = Server::get(\OCP\User\IManager::class); $testGroup = $groupManager->createGroup('testGroup'); $user1 = $userManager->get(self::TEST_FILES_SHARING_API_USER2); @@ -140,7 +142,7 @@ public function testShareWithDifferentShareFolder(): void { $this->assertTrue(Filesystem::file_exists('/Shared/subfolder/' . $this->folder)); //cleanup - \OC::$server->getConfig()->deleteSystemValue('share_folder'); + Server::get(IConfig::class)->deleteSystemValue('share_folder'); } public function testShareWithGroupUniqueName(): void { diff --git a/apps/files_sharing/tests/SharedMountTest.php b/apps/files_sharing/tests/SharedMountTest.php index 241b708f07e0f..5d25a28d9a057 100644 --- a/apps/files_sharing/tests/SharedMountTest.php +++ b/apps/files_sharing/tests/SharedMountTest.php @@ -13,6 +13,7 @@ use OCA\Files_Sharing\SharedMount; use OCP\Constants; use OCP\ICacheFactory; +use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUserManager; use OCP\Server; @@ -50,8 +51,8 @@ protected function setUp(): void { $this->view->file_put_contents($this->folder . $this->filename, 'file in subfolder'); $this->view->file_put_contents($this->folder2 . $this->filename, 'file in subfolder2'); - $this->groupManager = \OC::$server->getGroupManager(); - $this->userManager = \OC::$server->getUserManager(); + $this->groupManager = Server::get(\OCP\Group\IManager::class); + $this->userManager = Server::get(\OCP\User\IManager::class); } protected function tearDown(): void { @@ -266,7 +267,7 @@ public function testPermissionUpgradeOnUserDeletedGroupShare(): void { $testGroup->addUser($user2); $testGroup->addUser($user3); - $connection = \OC::$server->getDatabaseConnection(); + $connection = Server::get(IDBConnection::class); // Share item with group $fileinfo = $this->view->getFileInfo($this->folder); diff --git a/apps/files_sharing/tests/SharedStorageTest.php b/apps/files_sharing/tests/SharedStorageTest.php index 39ffec0908b69..e00427d4cc61b 100644 --- a/apps/files_sharing/tests/SharedStorageTest.php +++ b/apps/files_sharing/tests/SharedStorageTest.php @@ -16,7 +16,9 @@ use OCA\Files_Trashbin\AppInfo\Application; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\Constants; +use OCP\Files\Config\IMountProviderCollection; use OCP\Files\NotFoundException; +use OCP\Server; use OCP\Share\IShare; /** @@ -389,8 +391,8 @@ public function testMountSharesOtherUser(): void { self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder)); - $mountConfigManager = \OC::$server->getMountProviderCollection(); - $mounts = $mountConfigManager->getMountsForUser(\OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER3)); + $mountConfigManager = Server::get(IMountProviderCollection::class); + $mounts = $mountConfigManager->getMountsForUser(Server::get(\OCP\User\IManager::class)->get(self::TEST_FILES_SHARING_API_USER3)); array_walk($mounts, [Filesystem::getMountManager(), 'addMount']); $this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER3 . '/files/' . $this->filename)); diff --git a/apps/files_sharing/tests/SharesReminderJobTest.php b/apps/files_sharing/tests/SharesReminderJobTest.php index d68a9d30182d3..7a480fccb234c 100644 --- a/apps/files_sharing/tests/SharesReminderJobTest.php +++ b/apps/files_sharing/tests/SharesReminderJobTest.php @@ -20,6 +20,7 @@ use OCP\L10N\IFactory; use OCP\Mail\IMailer; use OCP\Mail\IMessage; +use OCP\Server; use OCP\Share\IManager; use OCP\Share\IShare; use PHPUnit\Framework\MockObject\MockObject; @@ -44,9 +45,9 @@ class SharesReminderJobTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->db = \OC::$server->get(IDBConnection::class); - $this->shareManager = \OC::$server->get(IManager::class); - $this->userManager = \OC::$server->get(IUserManager::class); + $this->db = Server::get(IDBConnection::class); + $this->shareManager = Server::get(IManager::class); + $this->userManager = Server::get(IUserManager::class); $this->mailer = $this->createMock(IMailer::class); // Clear occasional leftover shares from other tests @@ -60,26 +61,26 @@ protected function setUp(): void { $user1->setSystemEMailAddress('user1@test.com'); $user2->setSystemEMailAddress('user2@test.com'); - \OC::registerShareHooks(\OC::$server->get(SystemConfig::class)); + \OC::registerShareHooks(Server::get(SystemConfig::class)); $this->job = new SharesReminderJob( - \OC::$server->get(ITimeFactory::class), + Server::get(ITimeFactory::class), $this->db, - \OC::$server->get(IManager::class), + Server::get(IManager::class), $this->userManager, - \OC::$server->get(LoggerInterface::class), - \OC::$server->get(IURLGenerator::class), - \OC::$server->get(IFactory::class), + Server::get(LoggerInterface::class), + Server::get(IURLGenerator::class), + Server::get(IFactory::class), $this->mailer, - \OC::$server->get(Defaults::class), - \OC::$server->get(IMimeTypeLoader::class), + Server::get(Defaults::class), + Server::get(IMimeTypeLoader::class), ); } protected function tearDown(): void { $this->db->executeUpdate('DELETE FROM `*PREFIX*share`'); - $userManager = \OC::$server->get(IUserManager::class); + $userManager = Server::get(IUserManager::class); $user1 = $userManager->get($this->user1); if ($user1) { $user1->delete(); @@ -156,7 +157,7 @@ public function testSharesReminder( ): void { $this->loginAsUser($this->user1); - $user1Folder = \OC::$server->get(IRootFolder::class)->getUserFolder($this->user1); + $user1Folder = Server::get(IRootFolder::class)->getUserFolder($this->user1); $testFolder = $user1Folder->newFolder('test'); if (!$isEmpty) { diff --git a/apps/files_sharing/tests/SizePropagationTest.php b/apps/files_sharing/tests/SizePropagationTest.php index 2c6eda0fb8e20..082348c31a05d 100644 --- a/apps/files_sharing/tests/SizePropagationTest.php +++ b/apps/files_sharing/tests/SizePropagationTest.php @@ -8,6 +8,8 @@ use OC\Files\View; use OCP\Constants; +use OCP\ITempManager; +use OCP\Server; use OCP\Share\IShare; use Test\Traits\UserTrait; @@ -23,7 +25,7 @@ class SizePropagationTest extends TestCase { protected function setupUser($name, $password = '') { $this->createUser($name, $password); - $tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder(); + $tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder(); $this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]); $this->loginAsUser($name); return new View('/' . $name . '/files'); diff --git a/apps/files_sharing/tests/TestCase.php b/apps/files_sharing/tests/TestCase.php index d12a6bf0ec2c3..2341fbcda72ab 100644 --- a/apps/files_sharing/tests/TestCase.php +++ b/apps/files_sharing/tests/TestCase.php @@ -10,12 +10,16 @@ use OC\Files\Filesystem; use OC\Files\View; use OC\Group\Database; +use OC\SystemConfig; use OC\User\DisplayNameCache; use OCA\Files_Sharing\AppInfo\Application; use OCA\Files_Sharing\External\MountProvider as ExternalMountProvider; use OCA\Files_Sharing\MountProvider; use OCP\Files\Config\IMountProviderCollection; use OCP\Files\IRootFolder; +use OCP\IDBConnection; +use OCP\IUserSession; +use OCP\Server; use OCP\Share\IShare; use Test\Traits\MountProviderTrait; @@ -59,18 +63,18 @@ public static function setUpBeforeClass(): void { $app = new Application(); $app->registerMountProviders( - \OC::$server->get(IMountProviderCollection::class), - \OC::$server->get(MountProvider::class), - \OC::$server->get(ExternalMountProvider::class), + Server::get(IMountProviderCollection::class), + Server::get(MountProvider::class), + Server::get(ExternalMountProvider::class), ); // reset backend \OC_User::clearBackends(); - \OC::$server->getGroupManager()->clearBackends(); + Server::get(\OCP\Group\IManager::class)->clearBackends(); // clear share hooks \OC_Hook::clear('OCP\\Share'); - \OC::registerShareHooks(\OC::$server->getSystemConfig()); + \OC::registerShareHooks(Server::get(SystemConfig::class)); // create users $backend = new \Test\Util\User\Dummy(); @@ -94,12 +98,12 @@ public static function setUpBeforeClass(): void { $groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER3, 'group2'); $groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER4, 'group3'); $groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_GROUP1); - \OC::$server->getGroupManager()->addBackend($groupBackend); + Server::get(\OCP\Group\IManager::class)->addBackend($groupBackend); } protected function setUp(): void { parent::setUp(); - \OC::$server->get(DisplayNameCache::class)->clear(); + Server::get(DisplayNameCache::class)->clear(); //login as user1 self::loginHelper(self::TEST_FILES_SHARING_API_USER1); @@ -108,20 +112,20 @@ protected function setUp(): void { $this->view = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); $this->view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); - $this->shareManager = \OC::$server->getShareManager(); - $this->rootFolder = \OC::$server->getRootFolder(); + $this->shareManager = Server::get(\OCP\Share\IManager::class); + $this->rootFolder = Server::get(IRootFolder::class); } protected function tearDown(): void { - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = Server::get(IDBConnection::class)->getQueryBuilder(); $qb->delete('share'); $qb->execute(); - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = Server::get(IDBConnection::class)->getQueryBuilder(); $qb->delete('mounts'); $qb->execute(); - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = Server::get(IDBConnection::class)->getQueryBuilder(); $qb->delete('filecache')->runAcrossAllShards(); $qb->execute(); @@ -130,21 +134,21 @@ protected function tearDown(): void { public static function tearDownAfterClass(): void { // cleanup users - $user = \OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER1); + $user = Server::get(\OCP\User\IManager::class)->get(self::TEST_FILES_SHARING_API_USER1); if ($user !== null) { $user->delete(); } - $user = \OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER2); + $user = Server::get(\OCP\User\IManager::class)->get(self::TEST_FILES_SHARING_API_USER2); if ($user !== null) { $user->delete(); } - $user = \OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER3); + $user = Server::get(\OCP\User\IManager::class)->get(self::TEST_FILES_SHARING_API_USER3); if ($user !== null) { $user->delete(); } // delete group - $group = \OC::$server->getGroupManager()->get(self::TEST_FILES_SHARING_API_GROUP1); + $group = Server::get(\OCP\Group\IManager::class)->get(self::TEST_FILES_SHARING_API_GROUP1); if ($group) { $group->delete(); } @@ -156,8 +160,8 @@ public static function tearDownAfterClass(): void { // reset backend \OC_User::clearBackends(); \OC_User::useBackend('database'); - \OC::$server->getGroupManager()->clearBackends(); - \OC::$server->getGroupManager()->addBackend(new Database()); + Server::get(\OCP\Group\IManager::class)->clearBackends(); + Server::get(\OCP\Group\IManager::class)->addBackend(new Database()); parent::tearDownAfterClass(); } @@ -173,8 +177,8 @@ protected static function loginHelper($user, $create = false, $password = false) } if ($create) { - $userManager = \OC::$server->getUserManager(); - $groupManager = \OC::$server->getGroupManager(); + $userManager = Server::get(\OCP\User\IManager::class); + $groupManager = Server::get(\OCP\Group\IManager::class); $userObject = $userManager->createUser($user, $password); $group = $groupManager->createGroup('group'); @@ -186,9 +190,9 @@ protected static function loginHelper($user, $create = false, $password = false) \OC_Util::tearDownFS(); Storage::getGlobalCache()->clearCache(); - \OC::$server->getUserSession()->setUser(null); + Server::get(IUserSession::class)->setUser(null); Filesystem::tearDown(); - \OC::$server->getUserSession()->login($user, $password); + Server::get(IUserSession::class)->login($user, $password); \OC::$server->getUserFolder($user); \OC_Util::setupFS($user); @@ -200,7 +204,7 @@ protected static function loginHelper($user, $create = false, $password = false) * @return array with: item_source, share_type, share_with, item_type, permissions */ protected function getShareFromId($shareID) { - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = Server::get(IDBConnection::class)->getQueryBuilder(); $qb->select('item_source', '`share_type', 'share_with', 'item_type', 'permissions') ->from('share') ->where( diff --git a/apps/files_sharing/tests/UpdaterTest.php b/apps/files_sharing/tests/UpdaterTest.php index 62dd731559199..70e644f920799 100644 --- a/apps/files_sharing/tests/UpdaterTest.php +++ b/apps/files_sharing/tests/UpdaterTest.php @@ -11,8 +11,11 @@ use OC\Files\View; use OCA\Files_Sharing\Helper; use OCA\Files_Trashbin\AppInfo\Application; +use OCP\App\IAppManager; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\Constants; +use OCP\IConfig; +use OCP\Server; use OCP\Share\IShare; /** @@ -56,7 +59,7 @@ protected function tearDown(): void { * that the mount point doesn't end up at the trash bin */ public function testDeleteParentFolder(): void { - $status = \OC::$server->getAppManager()->isEnabledForUser('files_trashbin'); + $status = Server::get(IAppManager::class)->isEnabledForUser('files_trashbin'); (new \OC_App())->enable('files_trashbin'); // register trashbin hooks @@ -113,7 +116,7 @@ public function testDeleteParentFolder(): void { $rootView->deleteAll('files_trashin'); if ($status === false) { - \OC::$server->getAppManager()->disableApp('files_trashbin'); + Server::get(IAppManager::class)->disableApp('files_trashbin'); } Filesystem::getLoader()->removeStorageWrapper('oc_trashbin'); @@ -134,7 +137,7 @@ public function shareFolderProvider() { * @param string $shareFolder share folder to use */ public function testShareFile($shareFolder): void { - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); $oldShareFolder = $config->getSystemValue('share_folder'); $config->setSystemValue('share_folder', $shareFolder); diff --git a/apps/files_trashbin/lib/Command/Expire.php b/apps/files_trashbin/lib/Command/Expire.php index f526438600eab..d1d9b3ce30b91 100644 --- a/apps/files_trashbin/lib/Command/Expire.php +++ b/apps/files_trashbin/lib/Command/Expire.php @@ -9,6 +9,7 @@ use OC\Command\FileAccess; use OCA\Files_Trashbin\Trashbin; use OCP\Command\ICommand; +use OCP\Server; class Expire implements ICommand { use FileAccess; @@ -22,7 +23,7 @@ public function __construct( } public function handle() { - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(\OCP\User\IManager::class); if (!$userManager->userExists($this->user)) { // User has been deleted already return; diff --git a/apps/files_trashbin/lib/Helper.php b/apps/files_trashbin/lib/Helper.php index 7aeb737a56c40..50107b3bf71b9 100644 --- a/apps/files_trashbin/lib/Helper.php +++ b/apps/files_trashbin/lib/Helper.php @@ -10,6 +10,8 @@ use OC\Files\View; use OCP\Constants; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\IMimeTypeDetector; +use OCP\Server; class Helper { /** @@ -63,7 +65,7 @@ public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDesc $i = [ 'name' => $name, 'mtime' => $timestamp, - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : Server::get(IMimeTypeDetector::class)->detectPath($name), 'type' => $type, 'directory' => ($dir === '/') ? '' : $dir, 'size' => $entry->getSize(), diff --git a/apps/files_trashbin/lib/Sabre/RootCollection.php b/apps/files_trashbin/lib/Sabre/RootCollection.php index 06b0ffbeba259..8886dae0895f1 100644 --- a/apps/files_trashbin/lib/Sabre/RootCollection.php +++ b/apps/files_trashbin/lib/Sabre/RootCollection.php @@ -10,6 +10,8 @@ use OCA\Files_Trashbin\Trash\ITrashManager; use OCP\IConfig; +use OCP\IUserSession; +use OCP\Server; use Sabre\DAV\INode; use Sabre\DAVACL\AbstractPrincipalCollection; use Sabre\DAVACL\PrincipalBackend; @@ -36,7 +38,7 @@ public function __construct( */ public function getChildForPrincipal(array $principalInfo): TrashHome { [, $name] = \Sabre\Uri\split($principalInfo['uri']); - $user = \OC::$server->getUserSession()->getUser(); + $user = Server::get(IUserSession::class)->getUser(); if (is_null($user) || $name !== $user->getUID()) { throw new \Sabre\DAV\Exception\Forbidden(); } diff --git a/apps/files_trashbin/lib/Storage.php b/apps/files_trashbin/lib/Storage.php index a2855a97ac9d8..9ddb8e791faf1 100644 --- a/apps/files_trashbin/lib/Storage.php +++ b/apps/files_trashbin/lib/Storage.php @@ -148,12 +148,12 @@ private function doDelete(string $path, string $method): bool { * Setup the storage wrapper callback */ public static function setupStorage(): void { - $trashManager = \OC::$server->get(ITrashManager::class); - $userManager = \OC::$server->get(IUserManager::class); - $logger = \OC::$server->get(LoggerInterface::class); - $eventDispatcher = \OC::$server->get(IEventDispatcher::class); - $rootFolder = \OC::$server->get(IRootFolder::class); - $request = \OC::$server->get(IRequest::class); + $trashManager = Server::get(ITrashManager::class); + $userManager = Server::get(IUserManager::class); + $logger = Server::get(LoggerInterface::class); + $eventDispatcher = Server::get(IEventDispatcher::class); + $rootFolder = Server::get(IRootFolder::class); + $request = Server::get(IRequest::class); Filesystem::addStorageWrapper( 'oc_trashbin', function (string $mountPoint, IStorage $storage) use ($trashManager, $userManager, $logger, $eventDispatcher, $rootFolder, $request) { diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 32fd81465fa62..f5cfbe4a98632 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -24,12 +24,14 @@ use OCA\Files_Versions\Storage; use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Command\IBus; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventListener; use OCP\Files\Events\Node\BeforeNodeDeletedEvent; use OCP\Files\File; use OCP\Files\Folder; +use OCP\Files\IMimeTypeLoader; use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; @@ -39,6 +41,7 @@ use OCP\FilesMetadata\IFilesMetadataManager; use OCP\IConfig; use OCP\IDBConnection; +use OCP\IURLGenerator; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; use OCP\Server; @@ -72,7 +75,7 @@ public static function ensureFileScannedHook(Node $node): void { */ public static function getUidAndFilename($filename) { $uid = Filesystem::getOwner($filename); - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(\OCP\User\IManager::class); // if the user with the UID doesn't exists, e.g. because the UID points // to a remote user with a federated cloud ID we use the current logged-in // user. We need a valid local user to move the file to the right trash bin @@ -103,7 +106,7 @@ public static function getUidAndFilename($filename) { * @return array> */ public static function getExtraData($user) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->select('id', 'timestamp', 'location', 'deleted_by') ->from('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($user))); @@ -128,7 +131,7 @@ public static function getExtraData($user) { * @return string|false original location */ public static function getLocation($user, $filename, $timestamp) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->select('location') ->from('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($user))) @@ -194,7 +197,7 @@ private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user, if ($view->file_exists($target)) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->insert('files_trash') ->setValue('id', $query->createNamedParameter($targetFilename)) ->setValue('timestamp', $query->createNamedParameter($timestamp)) @@ -203,7 +206,7 @@ private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user, ->setValue('deleted_by', $query->createNamedParameter($user)); $result = $query->executeStatement(); if (!$result) { - \OC::$server->get(LoggerInterface::class)->error('trash bin database couldn\'t be updated for the files owner', ['app' => 'files_trashbin']); + Server::get(LoggerInterface::class)->error('trash bin database couldn\'t be updated for the files owner', ['app' => 'files_trashbin']); } } } @@ -256,7 +259,7 @@ public static function move2trash($file_path, $ownerOnly = false) { $timeFactory = \OC::$server->query(ITimeFactory::class); $timestamp = $timeFactory->getTime(); - $lockingProvider = \OC::$server->getLockingProvider(); + $lockingProvider = Server::get(ILockingProvider::class); // disable proxy to prevent recursive calls $trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp); @@ -302,7 +305,7 @@ public static function move2trash($file_path, $ownerOnly = false) { if ($trashStorage->file_exists($trashInternalPath)) { $trashStorage->unlink($trashInternalPath); } - \OC::$server->get(LoggerInterface::class)->error('Couldn\'t move ' . $file_path . ' to the trash bin', ['app' => 'files_trashbin']); + Server::get(LoggerInterface::class)->error('Couldn\'t move ' . $file_path . ' to the trash bin', ['app' => 'files_trashbin']); } if ($sourceStorage->file_exists($sourceInternalPath)) { // failed to delete the original file, abort @@ -322,7 +325,7 @@ public static function move2trash($file_path, $ownerOnly = false) { } if ($moveSuccessful) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->insert('files_trash') ->setValue('id', $query->createNamedParameter($filename)) ->setValue('timestamp', $query->createNamedParameter($timestamp)) @@ -331,7 +334,7 @@ public static function move2trash($file_path, $ownerOnly = false) { ->setValue('deleted_by', $query->createNamedParameter($user)); $result = $query->executeStatement(); if (!$result) { - \OC::$server->get(LoggerInterface::class)->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']); + Server::get(LoggerInterface::class)->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']); } Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', ['filePath' => Filesystem::normalizePath($file_path), 'trashPath' => Filesystem::normalizePath(static::getTrashFilename($filename, $timestamp))]); @@ -357,7 +360,7 @@ public static function move2trash($file_path, $ownerOnly = false) { } private static function getConfiguredTrashbinSize(string $user): int|float { - $config = \OC::$server->get(IConfig::class); + $config = Server::get(IConfig::class); $userTrashbinSize = $config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1'); if (is_numeric($userTrashbinSize) && ($userTrashbinSize > -1)) { return Util::numericToNumber($userTrashbinSize); @@ -460,7 +463,7 @@ public static function restore($file, $filename, $timestamp) { if ($timestamp) { $location = self::getLocation($user, $filename, $timestamp); if ($location === false) { - \OC::$server->get(LoggerInterface::class)->error('trash bin database inconsistent! ($user: ' . $user . ' $filename: ' . $filename . ', $timestamp: ' . $timestamp . ')', ['app' => 'files_trashbin']); + Server::get(LoggerInterface::class)->error('trash bin database inconsistent! ($user: ' . $user . ' $filename: ' . $filename . ', $timestamp: ' . $timestamp . ')', ['app' => 'files_trashbin']); } else { // if location no longer exists, restore file in the root directory if ($location !== '/' && @@ -494,7 +497,7 @@ public static function restore($file, $filename, $timestamp) { $targetNode = self::getNodeForPath($targetPath); $run = true; $event = new BeforeNodeRestoredEvent($sourceNode, $targetNode, $run); - $dispatcher = \OC::$server->get(IEventDispatcher::class); + $dispatcher = Server::get(IEventDispatcher::class); $dispatcher->dispatchTyped($event); if (!$run) { @@ -514,13 +517,13 @@ public static function restore($file, $filename, $timestamp) { $sourceNode = self::getNodeForPath($sourcePath); $targetNode = self::getNodeForPath($targetPath); $event = new NodeRestoredEvent($sourceNode, $targetNode); - $dispatcher = \OC::$server->get(IEventDispatcher::class); + $dispatcher = Server::get(IEventDispatcher::class); $dispatcher->dispatchTyped($event); self::restoreVersions($view, $file, $filename, $uniqueFilename, $location, $timestamp); if ($timestamp) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->delete('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($user))) ->andWhere($query->expr()->eq('id', $query->createNamedParameter($filename))) @@ -612,7 +615,7 @@ public static function deleteAll() { // actual file deletion $trash->delete(); - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->delete('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($user))); $query->executeStatement(); @@ -664,7 +667,7 @@ public static function delete($filename, $user, $timestamp = null) { $size = 0; if ($timestamp) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->delete('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($user))) ->andWhere($query->expr()->eq('id', $query->createNamedParameter($filename))) @@ -749,7 +752,7 @@ public static function file_exists($filename, $timestamp = null) { * @return bool result of db delete operation */ public static function deleteUser($uid) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->delete('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($uid))); return (bool)$query->executeStatement(); @@ -768,7 +771,7 @@ private static function calculateFreeSpace(int|float $trashbinSize, string $user return $configuredTrashbinSize - $trashbinSize; } - $userObject = \OC::$server->getUserManager()->get($user); + $userObject = Server::get(\OCP\User\IManager::class)->get($user); if (is_null($userObject)) { return 0; } @@ -853,7 +856,7 @@ private static function scheduleExpire($user) { $application = \OC::$server->query(Application::class); $expiration = $application->getContainer()->query('Expiration'); if ($expiration->isEnabled()) { - \OC::$server->getCommandBus()->push(new Expire($user)); + Server::get(IBus::class)->push(new Expire($user)); } } @@ -876,7 +879,7 @@ protected static function deleteFiles(array $files, string $user, int|float $ava foreach ($files as $file) { if ($availableSpace < 0 && $expiration->isExpired($file['mtime'], true)) { $tmp = self::delete($file['name'], $user, $file['mtime']); - \OC::$server->get(LoggerInterface::class)->info('remove "' . $file['name'] . '" (' . $tmp . 'B) to meet the limit of trash bin size (50% of available quota)', ['app' => 'files_trashbin']); + Server::get(LoggerInterface::class)->info('remove "' . $file['name'] . '" (' . $tmp . 'B) to meet the limit of trash bin size (50% of available quota)', ['app' => 'files_trashbin']); $availableSpace += $tmp; $size += $tmp; } else { @@ -907,14 +910,14 @@ public static function deleteExpiredFiles($files, $user) { $size += self::delete($filename, $user, $timestamp); $count++; } catch (NotPermittedException $e) { - \OC::$server->get(LoggerInterface::class)->warning('Removing "' . $filename . '" from trashbin failed.', + Server::get(LoggerInterface::class)->warning('Removing "' . $filename . '" from trashbin failed.', [ 'exception' => $e, 'app' => 'files_trashbin', ] ); } - \OC::$server->get(LoggerInterface::class)->info( + Server::get(LoggerInterface::class)->info( 'Remove "' . $filename . '" from trashbin because it exceeds max retention obligation term.', ['app' => 'files_trashbin'] ); @@ -977,10 +980,10 @@ private static function getVersionsFromTrash($filename, $timestamp, string $user /** @var \OC\Files\Storage\Storage $storage */ [$storage,] = $view->resolvePath('/'); - $pattern = \OC::$server->getDatabaseConnection()->escapeLikeParameter(basename($filename)); + $pattern = Server::get(IDBConnection::class)->escapeLikeParameter(basename($filename)); if ($timestamp) { // fetch for old versions - $escapedTimestamp = \OC::$server->getDatabaseConnection()->escapeLikeParameter((string)$timestamp); + $escapedTimestamp = Server::get(IDBConnection::class)->escapeLikeParameter((string)$timestamp); $pattern .= '.v%.d' . $escapedTimestamp; $offset = -strlen($escapedTimestamp) - 2; } else { @@ -1010,7 +1013,7 @@ private static function getVersionsFromTrash($filename, $timestamp, string $user /** @var CacheEntry[] $matches */ $matches = array_map(function (array $data) { - return Cache::cacheEntryFromData($data, \OC::$server->getMimeTypeLoader()); + return Cache::cacheEntryFromData($data, Server::get(IMimeTypeLoader::class)); }, $entries); foreach ($matches as $ma) { @@ -1067,7 +1070,7 @@ private static function getUniqueFilename($location, $filename, View $view) { * @return int|float size of the folder */ private static function calculateSize(View $view): int|float { - $root = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . $view->getAbsolutePath(''); + $root = Server::get(IConfig::class)->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . $view->getAbsolutePath(''); if (!file_exists($root)) { return 0; } @@ -1126,7 +1129,7 @@ public static function isEmpty($user) { * @return string */ public static function preview_icon($path) { - return \OC::$server->getURLGenerator()->linkToRoute('core_ajax_trashbin_preview', ['x' => 32, 'y' => 32, 'file' => $path]); + return Server::get(IURLGenerator::class)->linkToRoute('core_ajax_trashbin_preview', ['x' => 32, 'y' => 32, 'file' => $path]); } /** @@ -1150,7 +1153,7 @@ public static function getTrashFilename(string $filename, int $timestamp): strin private static function getNodeForPath(string $path): Node { $user = OC_User::getUser(); - $rootFolder = \OC::$server->get(IRootFolder::class); + $rootFolder = Server::get(IRootFolder::class); if ($user !== false) { $userFolder = $rootFolder->getUserFolder($user); @@ -1162,7 +1165,7 @@ private static function getNodeForPath(string $path): Node { } } - $view = \OC::$server->get(View::class); + $view = Server::get(View::class); $fsView = Filesystem::getView(); if ($fsView === null) { throw new Exception('View should not be null'); diff --git a/apps/files_trashbin/tests/Command/CleanUpTest.php b/apps/files_trashbin/tests/Command/CleanUpTest.php index fef57f44f24e8..25d38752e918a 100644 --- a/apps/files_trashbin/tests/Command/CleanUpTest.php +++ b/apps/files_trashbin/tests/Command/CleanUpTest.php @@ -10,6 +10,7 @@ use OCA\Files_Trashbin\Command\CleanUp; use OCP\Files\IRootFolder; use OCP\IDBConnection; +use OCP\Server; use OCP\UserInterface; use Symfony\Component\Console\Exception\InvalidOptionException; use Symfony\Component\Console\Input\InputInterface; @@ -51,7 +52,7 @@ protected function setUp(): void { $this->userManager = $this->getMockBuilder('OC\User\Manager') ->disableOriginalConstructor()->getMock(); - $this->dbConnection = \OC::$server->getDatabaseConnection(); + $this->dbConnection = Server::get(IDBConnection::class); $this->cleanup = new CleanUp($this->rootFolder, $this->userManager, $this->dbConnection); } diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index ec01e16b16ab5..454f877cbb1d7 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -25,6 +25,7 @@ use OCP\Files\Storage\IStorage; use OCP\IUserManager; use OCP\Lock\ILockingProvider; +use OCP\Server; use OCP\Share\IShare; use Psr\Log\LoggerInterface; use Test\Traits\MountProviderTrait; @@ -80,7 +81,7 @@ protected function setUp(): void { $trashbinApp->boot($this->createMock(IBootContext::class)); $this->user = $this->getUniqueId('user'); - \OC::$server->getUserManager()->createUser($this->user, $this->user); + Server::get(\OCP\User\IManager::class)->createUser($this->user, $this->user); // this will setup the FS $this->loginAsUser($this->user); @@ -100,7 +101,7 @@ protected function setUp(): void { protected function tearDown(): void { Filesystem::getLoader()->removeStorageWrapper('oc_trashbin'); $this->logout(); - $user = \OC::$server->getUserManager()->get($this->user); + $user = Server::get(\OCP\User\IManager::class)->get($this->user); if ($user !== null) { $user->delete(); } @@ -316,17 +317,17 @@ public function testDeleteVersionsOfFileAsRecipient(): void { $this->assertEquals(1, count($results)); $recipientUser = $this->getUniqueId('recipient_'); - \OC::$server->getUserManager()->createUser($recipientUser, $recipientUser); + Server::get(\OCP\User\IManager::class)->createUser($recipientUser, $recipientUser); $node = \OC::$server->getUserFolder($this->user)->get('share'); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setNode($node) ->setShareType(IShare::TYPE_USER) ->setSharedBy($this->user) ->setSharedWith($recipientUser) ->setPermissions(Constants::PERMISSION_ALL); - $share = \OC::$server->getShareManager()->createShare($share); - \OC::$server->getShareManager()->acceptShare($share, $recipientUser); + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); + Server::get(\OCP\Share\IManager::class)->acceptShare($share, $recipientUser); $this->loginAsUser($recipientUser); @@ -368,17 +369,17 @@ public function testDeleteVersionsOfFolderAsRecipient(): void { $this->assertEquals(1, count($results)); $recipientUser = $this->getUniqueId('recipient_'); - \OC::$server->getUserManager()->createUser($recipientUser, $recipientUser); + Server::get(\OCP\User\IManager::class)->createUser($recipientUser, $recipientUser); $node = \OC::$server->getUserFolder($this->user)->get('share'); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setNode($node) ->setShareType(IShare::TYPE_USER) ->setSharedBy($this->user) ->setSharedWith($recipientUser) ->setPermissions(Constants::PERMISSION_ALL); - $share = \OC::$server->getShareManager()->createShare($share); - \OC::$server->getShareManager()->acceptShare($share, $recipientUser); + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); + Server::get(\OCP\Share\IManager::class)->acceptShare($share, $recipientUser); $this->loginAsUser($recipientUser); @@ -649,7 +650,7 @@ public function testTrashbinCollision(): void { $timeFactory->method('getTime') ->willReturn(1000); - $lockingProvider = \OC::$server->getLockingProvider(); + $lockingProvider = Server::get(ILockingProvider::class); $this->overwriteService(ITimeFactory::class, $timeFactory); diff --git a/apps/files_trashbin/tests/TrashbinTest.php b/apps/files_trashbin/tests/TrashbinTest.php index ea9abedd14489..aac4d96a82cd0 100644 --- a/apps/files_trashbin/tests/TrashbinTest.php +++ b/apps/files_trashbin/tests/TrashbinTest.php @@ -11,15 +11,19 @@ use OC\Files\Filesystem; use OC\Files\Storage\Local; use OC\Files\View; +use OC\SystemConfig; use OCA\Files_Sharing\AppInfo\Application; use OCA\Files_Trashbin\AppInfo\Application as TrashbinApplication; use OCA\Files_Trashbin\Expiration; use OCA\Files_Trashbin\Helper; use OCA\Files_Trashbin\Trashbin; +use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Constants; use OCP\Files\FileInfo; use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Server; use OCP\Share\IShare; /** @@ -49,7 +53,7 @@ class TrashbinTest extends \Test\TestCase { public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - $appManager = \OC::$server->getAppManager(); + $appManager = Server::get(IAppManager::class); self::$trashBinStatus = $appManager->isEnabledForUser('files_trashbin'); // reset backend @@ -58,15 +62,15 @@ public static function setUpBeforeClass(): void { // clear share hooks \OC_Hook::clear('OCP\\Share'); - \OC::registerShareHooks(\OC::$server->getSystemConfig()); + \OC::registerShareHooks(Server::get(SystemConfig::class)); // init files sharing new Application(); //disable encryption - \OC::$server->getAppManager()->disableApp('encryption'); + Server::get(IAppManager::class)->disableApp('encryption'); - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); //configure trashbin self::$rememberRetentionObligation = $config->getSystemValue('trashbin_retention_obligation', Expiration::DEFAULT_RETENTION_OBLIGATION); /** @var Expiration $expiration */ @@ -85,7 +89,7 @@ public static function setUpBeforeClass(): void { public static function tearDownAfterClass(): void { // cleanup test user - $user = \OC::$server->getUserManager()->get(self::TEST_TRASHBIN_USER1); + $user = Server::get(\OCP\User\IManager::class)->get(self::TEST_TRASHBIN_USER1); if ($user !== null) { $user->delete(); } @@ -99,7 +103,7 @@ public static function tearDownAfterClass(): void { Filesystem::getLoader()->removeStorageWrapper('oc_trashbin'); if (self::$trashBinStatus) { - \OC::$server->getAppManager()->enableApp('files_trashbin'); + Server::get(IAppManager::class)->enableApp('files_trashbin'); } parent::tearDownAfterClass(); @@ -108,8 +112,8 @@ public static function tearDownAfterClass(): void { protected function setUp(): void { parent::setUp(); - \OC::$server->getAppManager()->enableApp('files_trashbin'); - $config = \OC::$server->getConfig(); + Server::get(IAppManager::class)->enableApp('files_trashbin'); + $config = Server::get(IConfig::class); $mockConfig = $this->createMock(IConfig::class); $mockConfig ->method('getSystemValue') @@ -141,7 +145,7 @@ protected function setUp(): void { protected function tearDown(): void { $this->restoreService(AllConfig::class); // disable trashbin to be able to properly clean up - \OC::$server->getAppManager()->disableApp('files_trashbin'); + Server::get(IAppManager::class)->disableApp('files_trashbin'); $this->rootView->deleteAll('/' . self::TEST_TRASHBIN_USER1 . '/files'); $this->rootView->deleteAll('/' . self::TEST_TRASHBIN_USER2 . '/files'); @@ -149,7 +153,7 @@ protected function tearDown(): void { $this->rootView->deleteAll($this->trashRoot2); // clear trash table - $connection = \OC::$server->getDatabaseConnection(); + $connection = Server::get(IDBConnection::class); $connection->executeUpdate('DELETE FROM `*PREFIX*files_trash`'); parent::tearDown(); @@ -224,14 +228,14 @@ public function testExpireOldFilesShared(): void { //share user1-4.txt with user2 $node = \OC::$server->getUserFolder(self::TEST_TRASHBIN_USER1)->get($folder); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setShareType(IShare::TYPE_USER) ->setNode($node) ->setSharedBy(self::TEST_TRASHBIN_USER1) ->setSharedWith(self::TEST_TRASHBIN_USER2) ->setPermissions(Constants::PERMISSION_ALL); - $share = \OC::$server->getShareManager()->createShare($share); - \OC::$server->getShareManager()->acceptShare($share, self::TEST_TRASHBIN_USER2); + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_TRASHBIN_USER2); // delete them so that they end up in the trash bin Filesystem::unlink($folder . 'user1-1.txt'); @@ -671,7 +675,7 @@ public function testRestoreFileIntoReadOnlySourceFolder(): void { public static function loginHelper($user, $create = false) { if ($create) { try { - \OC::$server->getUserManager()->createUser($user, $user); + Server::get(\OCP\User\IManager::class)->createUser($user, $user); } catch (\Exception $e) { // catch username is already being used from previous aborted runs } } diff --git a/apps/files_versions/lib/AppInfo/Application.php b/apps/files_versions/lib/AppInfo/Application.php index a31e9823efdaa..a12c097cfa847 100644 --- a/apps/files_versions/lib/AppInfo/Application.php +++ b/apps/files_versions/lib/AppInfo/Application.php @@ -42,6 +42,7 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\Server; use OCP\Share\IManager as IShareManager; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -68,7 +69,7 @@ public function register(IRegistrationContext $context): void { return new Principal( $server->get(IUserManager::class), $server->get(IGroupManager::class), - \OC::$server->get(IAccountManager::class), + Server::get(IAccountManager::class), $server->get(IShareManager::class), $server->get(IUserSession::class), $server->get(IAppManager::class), diff --git a/apps/files_versions/lib/Command/Expire.php b/apps/files_versions/lib/Command/Expire.php index 6ec7a4fd32a24..d11810871505e 100644 --- a/apps/files_versions/lib/Command/Expire.php +++ b/apps/files_versions/lib/Command/Expire.php @@ -11,6 +11,7 @@ use OCP\Command\ICommand; use OCP\Files\StorageNotAvailableException; use OCP\IUserManager; +use OCP\Server; use Psr\Log\LoggerInterface; class Expire implements ICommand { @@ -24,7 +25,7 @@ public function __construct( public function handle(): void { /** @var IUserManager $userManager */ - $userManager = \OC::$server->get(IUserManager::class); + $userManager = Server::get(IUserManager::class); if (!$userManager->userExists($this->user)) { // User has been deleted already return; @@ -36,7 +37,7 @@ public function handle(): void { // In case of external storage and session credentials, the expiration // fails because the command does not have those credentials - $logger = \OC::$server->get(LoggerInterface::class); + $logger = Server::get(LoggerInterface::class); $logger->warning($e->getMessage(), [ 'exception' => $e, 'uid' => $this->user, diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index 11e6bff6b6b12..70aca1e0ffd52 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -84,7 +84,7 @@ class Storage { */ public static function getUidAndFilename($filename) { $uid = Filesystem::getOwner($filename); - $userManager = \OC::$server->get(IUserManager::class); + $userManager = Server::get(IUserManager::class); // if the user with the UID doesn't exists, e.g. because the UID points // to a remote user with a federated cloud ID we use the current logged-in // user. We need a valid local user to create the versions @@ -167,10 +167,10 @@ public static function store($filename) { $uid = Filesystem::getView()->getOwner(''); /** @var IRootFolder $rootFolder */ - $rootFolder = \OC::$server->get(IRootFolder::class); + $rootFolder = Server::get(IRootFolder::class); $userFolder = $rootFolder->getUserFolder($uid); - $eventDispatcher = \OC::$server->get(IEventDispatcher::class); + $eventDispatcher = Server::get(IEventDispatcher::class); try { $file = $userFolder->get($filename); } catch (NotFoundException $e) { @@ -188,7 +188,7 @@ public static function store($filename) { } /** @var IUserManager $userManager */ - $userManager = \OC::$server->get(IUserManager::class); + $userManager = Server::get(IUserManager::class); $user = $userManager->get($uid); if (!$user) { @@ -207,7 +207,7 @@ public static function store($filename) { } /** @var IVersionManager $versionManager */ - $versionManager = \OC::$server->get(IVersionManager::class); + $versionManager = Server::get(IVersionManager::class); $versionManager->createVersion($user, $file); } @@ -345,7 +345,7 @@ public static function rollback(string $file, int $revision, IUser $user) { $filename = '/' . ltrim($file, '/'); // Fetch the userfolder to trigger view hooks - $root = \OC::$server->get(IRootFolder::class); + $root = Server::get(IRootFolder::class); $userFolder = $root->getUserFolder($user->getUID()); $users_view = new View('/' . $user->getUID()); @@ -475,7 +475,7 @@ public static function getVersions($uid, $filename, $userFullPath = '') { $pathparts = pathinfo($entryName); $timestamp = substr($pathparts['extension'] ?? '', 1); if (!is_numeric($timestamp)) { - \OC::$server->get(LoggerInterface::class)->error( + Server::get(LoggerInterface::class)->error( 'Version file {path} has incorrect name format', [ 'path' => $entryName, @@ -492,14 +492,14 @@ public static function getVersions($uid, $filename, $userFullPath = '') { $versions[$key]['preview'] = ''; } else { /** @var IURLGenerator $urlGenerator */ - $urlGenerator = \OC::$server->get(IURLGenerator::class); + $urlGenerator = Server::get(IURLGenerator::class); $versions[$key]['preview'] = $urlGenerator->linkToRoute('files_version.Preview.getPreview', ['file' => $userFullPath, 'version' => $timestamp]); } $versions[$key]['path'] = Filesystem::normalizePath($pathinfo['dirname'] . '/' . $filename); $versions[$key]['name'] = $versionedFile; $versions[$key]['size'] = $view->filesize($dir . '/' . $entryName); - $versions[$key]['mimetype'] = \OC::$server->get(IMimeTypeDetector::class)->detectPath($versionedFile); + $versions[$key]['mimetype'] = Server::get(IMimeTypeDetector::class)->detectPath($versionedFile); } } } @@ -519,7 +519,7 @@ public static function getVersions($uid, $filename, $userFullPath = '') { */ public static function expireOlderThanMaxForUser($uid) { /** @var IRootFolder $root */ - $root = \OC::$server->get(IRootFolder::class); + $root = Server::get(IRootFolder::class); try { /** @var Folder $versionsRoot */ $versionsRoot = $root->get('/' . $uid . '/files_versions'); @@ -543,7 +543,7 @@ public static function expireOlderThanMaxForUser($uid) { )); /** @var VersionsMapper $versionsMapper */ - $versionsMapper = \OC::$server->get(VersionsMapper::class); + $versionsMapper = Server::get(VersionsMapper::class); $userFolder = $root->getUserFolder($uid); $versionEntities = []; @@ -704,7 +704,7 @@ protected static function getExpireList($time, $versions, $quotaExceeded = false foreach ($versions as $key => $version) { if (!is_numeric($version['version'])) { - \OC::$server->get(LoggerInterface::class)->error( + Server::get(LoggerInterface::class)->error( 'Found a non-numeric timestamp version: ' . json_encode($version), ['app' => 'files_versions']); continue; @@ -755,7 +755,7 @@ protected static function getAutoExpireList($time, $versions) { //distance between two version too small, mark to delete $toDelete[$key] = $version['path'] . '.v' . $version['version']; $size += $version['size']; - \OC::$server->get(LoggerInterface::class)->info('Mark to expire ' . $version['path'] . ' next version should be ' . $nextVersion . ' or smaller. (prevTimestamp: ' . $prevTimestamp . '; step: ' . $step, ['app' => 'files_versions']); + Server::get(LoggerInterface::class)->info('Mark to expire ' . $version['path'] . ' next version should be ' . $nextVersion . ' or smaller. (prevTimestamp: ' . $prevTimestamp . '; step: ' . $step, ['app' => 'files_versions']); } else { $nextVersion = $version['version'] - $step; $prevTimestamp = $version['version']; @@ -790,7 +790,7 @@ public static function scheduleExpire($uid, $fileName) { if ($expiration->isEnabled()) { $command = new Expire($uid, $fileName); /** @var IBus $bus */ - $bus = \OC::$server->get(IBus::class); + $bus = Server::get(IBus::class); $bus->push($command); } } @@ -809,11 +809,11 @@ public static function expire($filename, $uid) { $expiration = self::getExpiration(); /** @var LoggerInterface $logger */ - $logger = \OC::$server->get(LoggerInterface::class); + $logger = Server::get(LoggerInterface::class); if ($expiration->isEnabled()) { // get available disk space for user - $user = \OC::$server->get(IUserManager::class)->get($uid); + $user = Server::get(IUserManager::class)->get($uid); if (is_null($user)) { $logger->error('Backends provided no user object for ' . $uid, ['app' => 'files_versions']); throw new NoUserException('Backends provided no user object for ' . $uid); @@ -853,7 +853,7 @@ public static function expire($filename, $uid) { // subtract size of files and current versions size from quota if ($quota >= 0) { if ($softQuota) { - $root = \OC::$server->get(IRootFolder::class); + $root = Server::get(IRootFolder::class); $userFolder = $root->getUserFolder($uid); if (is_null($userFolder)) { $availableSpace = 0; @@ -898,8 +898,8 @@ public static function expire($filename, $uid) { // Make sure to cleanup version table relations as expire does not pass deleteVersion try { /** @var VersionsMapper $versionsMapper */ - $versionsMapper = \OC::$server->get(VersionsMapper::class); - $file = \OC::$server->get(IRootFolder::class)->getUserFolder($uid)->get($filename); + $versionsMapper = Server::get(VersionsMapper::class); + $file = Server::get(IRootFolder::class)->getUserFolder($uid)->get($filename); $pathparts = pathinfo($path); $timestamp = (int)substr($pathparts['extension'] ?? '', 1); $versionEntity = $versionsMapper->findVersionForFileId($file->getId(), $timestamp); @@ -969,7 +969,7 @@ public static function createMissingDirectories($filename, $view) { */ protected static function getExpiration() { if (self::$application === null) { - self::$application = \OC::$server->get(Application::class); + self::$application = Server::get(Application::class); } return self::$application->getContainer()->get(Expiration::class); } diff --git a/apps/files_versions/lib/Versions/VersionManager.php b/apps/files_versions/lib/Versions/VersionManager.php index b7dcd7d3a029a..2bf7f5241fe90 100644 --- a/apps/files_versions/lib/Versions/VersionManager.php +++ b/apps/files_versions/lib/Versions/VersionManager.php @@ -18,6 +18,7 @@ use OCP\Files\Storage\IStorage; use OCP\IUser; use OCP\Lock\ManuallyLockedException; +use OCP\Server; class VersionManager implements IVersionManager, IDeletableVersionBackend, INeedSyncVersionBackend, IMetadataVersionBackend { /** @var (IVersionBackend[])[] */ @@ -176,9 +177,9 @@ private static function handleAppLocks(callable $callback): ?bool { // when checking the lock against the current scope. // So we do not need to get the actual node here // and use the root node instead. - $root = \OC::$server->get(IRootFolder::class); + $root = Server::get(IRootFolder::class); $lockContext = new LockContext($root, ILock::TYPE_APP, $owner); - $lockManager = \OC::$server->get(ILockManager::class); + $lockManager = Server::get(ILockManager::class); $result = null; $lockManager->runInScope($lockContext, function () use ($callback, &$result): void { $result = $callback(); diff --git a/apps/files_versions/tests/StorageTest.php b/apps/files_versions/tests/StorageTest.php index e085729eddd67..dd5b94c7a22d2 100644 --- a/apps/files_versions/tests/StorageTest.php +++ b/apps/files_versions/tests/StorageTest.php @@ -12,6 +12,7 @@ use OCA\Files_Versions\Storage; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; +use OCP\Server; use Test\TestCase; use Test\Traits\UserTrait; @@ -40,7 +41,7 @@ protected function setUp(): void { $this->createUser('version_test', ''); $this->loginAsUser('version_test'); /** @var IRootFolder $root */ - $root = \OC::$server->get(IRootFolder::class); + $root = Server::get(IRootFolder::class); $this->userFolder = $root->getUserFolder('version_test'); } diff --git a/apps/files_versions/tests/VersioningTest.php b/apps/files_versions/tests/VersioningTest.php index 20a0a783ecc87..20ad45966c9c1 100644 --- a/apps/files_versions/tests/VersioningTest.php +++ b/apps/files_versions/tests/VersioningTest.php @@ -11,6 +11,7 @@ use OC\Files\Filesystem; use OC\Files\Storage\Temporary; use OC\Files\View; +use OC\SystemConfig; use OC\User\NoUserException; use OCA\Files_Sharing\AppInfo\Application; use OCA\Files_Versions\Db\VersionEntity; @@ -63,11 +64,11 @@ public static function setUpBeforeClass(): void { public static function tearDownAfterClass(): void { // cleanup test user - $user = \OC::$server->getUserManager()->get(self::TEST_VERSIONS_USER); + $user = Server::get(\OCP\User\IManager::class)->get(self::TEST_VERSIONS_USER); if ($user !== null) { $user->delete(); } - $user = \OC::$server->getUserManager()->get(self::TEST_VERSIONS_USER2); + $user = Server::get(\OCP\User\IManager::class)->get(self::TEST_VERSIONS_USER2); if ($user !== null) { $user->delete(); } @@ -78,7 +79,7 @@ public static function tearDownAfterClass(): void { protected function setUp(): void { parent::setUp(); - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); $mockConfig = $this->createMock(IConfig::class); $mockConfig->expects($this->any()) ->method('getSystemValue') @@ -93,7 +94,7 @@ protected function setUp(): void { // clear hooks \OC_Hook::clear(); - \OC::registerShareHooks(\OC::$server->getSystemConfig()); + \OC::registerShareHooks(Server::get(SystemConfig::class)); \OC::$server->boot(); self::loginHelper(self::TEST_VERSIONS_USER); @@ -329,14 +330,14 @@ public function testRenameInSharedFolder(): void { $this->rootView->file_put_contents($v2, 'version2'); $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1'); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setNode($node) ->setShareType(IShare::TYPE_USER) ->setSharedBy(self::TEST_VERSIONS_USER) ->setSharedWith(self::TEST_VERSIONS_USER2) ->setPermissions(Constants::PERMISSION_ALL); - $share = \OC::$server->getShareManager()->createShare($share); - \OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2); + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); self::loginHelper(self::TEST_VERSIONS_USER2); @@ -355,7 +356,7 @@ public function testRenameInSharedFolder(): void { $this->assertTrue($this->rootView->file_exists($v1Renamed), 'version 1 of renamed file exists'); $this->assertTrue($this->rootView->file_exists($v2Renamed), 'version 2 of renamed file exists'); - \OC::$server->getShareManager()->deleteShare($share); + Server::get(\OCP\Share\IManager::class)->deleteShare($share); } public function testMoveFolder(): void { @@ -396,14 +397,14 @@ public function testMoveFileIntoSharedFolderAsRecipient(): void { $fileInfo = Filesystem::getFileInfo('folder1'); $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1'); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setNode($node) ->setShareType(IShare::TYPE_USER) ->setSharedBy(self::TEST_VERSIONS_USER) ->setSharedWith(self::TEST_VERSIONS_USER2) ->setPermissions(Constants::PERMISSION_ALL); - $share = \OC::$server->getShareManager()->createShare($share); - \OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2); + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); self::loginHelper(self::TEST_VERSIONS_USER2); $versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions'; @@ -438,21 +439,21 @@ public function testMoveFileIntoSharedFolderAsRecipient(): void { $this->assertTrue($this->rootView->file_exists($v1Renamed)); $this->assertTrue($this->rootView->file_exists($v2Renamed)); - \OC::$server->getShareManager()->deleteShare($share); + Server::get(\OCP\Share\IManager::class)->deleteShare($share); } public function testMoveFolderIntoSharedFolderAsRecipient(): void { Filesystem::mkdir('folder1'); $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1'); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setNode($node) ->setShareType(IShare::TYPE_USER) ->setSharedBy(self::TEST_VERSIONS_USER) ->setSharedWith(self::TEST_VERSIONS_USER2) ->setPermissions(Constants::PERMISSION_ALL); - $share = \OC::$server->getShareManager()->createShare($share); - \OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2); + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); self::loginHelper(self::TEST_VERSIONS_USER2); $versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions'; @@ -489,7 +490,7 @@ public function testMoveFolderIntoSharedFolderAsRecipient(): void { $this->assertTrue($this->rootView->file_exists($v1Renamed)); $this->assertTrue($this->rootView->file_exists($v2Renamed)); - \OC::$server->getShareManager()->deleteShare($share); + Server::get(\OCP\Share\IManager::class)->deleteShare($share); } public function testRenameSharedFile(): void { @@ -512,14 +513,14 @@ public function testRenameSharedFile(): void { $this->rootView->file_put_contents($v2, 'version2'); $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('test.txt'); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setNode($node) ->setShareType(IShare::TYPE_USER) ->setSharedBy(self::TEST_VERSIONS_USER) ->setSharedWith(self::TEST_VERSIONS_USER2) ->setPermissions(Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE); - $share = \OC::$server->getShareManager()->createShare($share); - \OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2); + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); self::loginHelper(self::TEST_VERSIONS_USER2); @@ -538,7 +539,7 @@ public function testRenameSharedFile(): void { $this->assertFalse($this->rootView->file_exists($v1Renamed)); $this->assertFalse($this->rootView->file_exists($v2Renamed)); - \OC::$server->getShareManager()->deleteShare($share); + Server::get(\OCP\Share\IManager::class)->deleteShare($share); } public function testCopy(): void { @@ -655,14 +656,14 @@ public function testRestoreNoPermission(): void { $node = $userHome->newFolder('folder'); $file = $node->newFile('test.txt'); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setNode($node) ->setShareType(IShare::TYPE_USER) ->setSharedBy(self::TEST_VERSIONS_USER) ->setSharedWith(self::TEST_VERSIONS_USER2) ->setPermissions(Constants::PERMISSION_READ); - $share = \OC::$server->getShareManager()->createShare($share); - \OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2); + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); $versions = $this->createAndCheckVersions( Filesystem::getView(), @@ -679,7 +680,7 @@ public function testRestoreNoPermission(): void { $this->loginAsUser(self::TEST_VERSIONS_USER); - \OC::$server->getShareManager()->deleteShare($share); + Server::get(\OCP\Share\IManager::class)->deleteShare($share); $this->assertEquals('test file', $file->getContent(), 'File content has not changed'); } @@ -694,14 +695,14 @@ public function testRestoreMovedShare(): void { $userHome2 = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER2); $userHome2->newFolder('subfolder'); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setNode($node) ->setShareType(IShare::TYPE_USER) ->setSharedBy(self::TEST_VERSIONS_USER) ->setSharedWith(self::TEST_VERSIONS_USER2) ->setPermissions(Constants::PERMISSION_ALL); - $share = \OC::$server->getShareManager()->createShare($share); - $shareManager = \OC::$server->getShareManager(); + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); + $shareManager = Server::get(\OCP\Share\IManager::class); $shareManager->acceptShare($share, self::TEST_VERSIONS_USER2); $share->setTarget('subfolder/folder'); @@ -722,7 +723,7 @@ public function testRestoreMovedShare(): void { $this->loginAsUser(self::TEST_VERSIONS_USER); - \OC::$server->getShareManager()->deleteShare($share); + Server::get(\OCP\Share\IManager::class)->deleteShare($share); $this->assertEquals('version 2', $file->getContent(), 'File content has not changed'); } @@ -893,14 +894,14 @@ public function testStoreVersionAsRecipient(): void { Filesystem::file_put_contents('folder/test.txt', 'test file'); $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder'); - $share = \OC::$server->getShareManager()->newShare(); + $share = Server::get(\OCP\Share\IManager::class)->newShare(); $share->setNode($node) ->setShareType(IShare::TYPE_USER) ->setSharedBy(self::TEST_VERSIONS_USER) ->setSharedWith(self::TEST_VERSIONS_USER2) ->setPermissions(Constants::PERMISSION_ALL); - $share = \OC::$server->getShareManager()->createShare($share); - \OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2); + $share = Server::get(\OCP\Share\IManager::class)->createShare($share); + Server::get(\OCP\Share\IManager::class)->acceptShare($share, self::TEST_VERSIONS_USER2); $this->loginAsUser(self::TEST_VERSIONS_USER2); @@ -909,7 +910,7 @@ public function testStoreVersionAsRecipient(): void { 'folder/test.txt' ); - \OC::$server->getShareManager()->deleteShare($share); + Server::get(\OCP\Share\IManager::class)->deleteShare($share); } /** @@ -967,7 +968,7 @@ public static function loginHelper($user, $create = false) { if ($create) { $backend = new \Test\Util\User\Dummy(); $backend->createUser($user, $user); - \OC::$server->getUserManager()->registerBackend($backend); + Server::get(\OCP\User\IManager::class)->registerBackend($backend); } \OC_Util::tearDownFS(); diff --git a/apps/oauth2/templates/admin.php b/apps/oauth2/templates/admin.php index 3f6f879b7e156..844eeee2c0801 100644 --- a/apps/oauth2/templates/admin.php +++ b/apps/oauth2/templates/admin.php @@ -4,7 +4,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -script('oauth2', 'oauth2'); +\OCP\Util::addScript('oauth2', 'oauth2', 'core'); ?> diff --git a/apps/oauth2/tests/Controller/SettingsControllerTest.php b/apps/oauth2/tests/Controller/SettingsControllerTest.php index 5b8a57a4062ab..9173aa88e2dcd 100644 --- a/apps/oauth2/tests/Controller/SettingsControllerTest.php +++ b/apps/oauth2/tests/Controller/SettingsControllerTest.php @@ -18,6 +18,7 @@ use OCP\IUserManager; use OCP\Security\ICrypto; use OCP\Security\ISecureRandom; +use OCP\Server; use Test\TestCase; /** @@ -119,7 +120,7 @@ public function testAddClient(): void { public function testDeleteClient(): void { - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(\OCP\User\IManager::class); // count other users in the db before adding our own $count = 0; $function = function (IUser $user) use (&$count): void { diff --git a/apps/oauth2/tests/Db/AccessTokenMapperTest.php b/apps/oauth2/tests/Db/AccessTokenMapperTest.php index d1d595ef00317..1ed282dae1dcc 100644 --- a/apps/oauth2/tests/Db/AccessTokenMapperTest.php +++ b/apps/oauth2/tests/Db/AccessTokenMapperTest.php @@ -9,6 +9,8 @@ use OCA\OAuth2\Db\AccessTokenMapper; use OCA\OAuth2\Exceptions\AccessTokenNotFoundException; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\IDBConnection; +use OCP\Server; use Test\TestCase; /** @@ -20,7 +22,7 @@ class AccessTokenMapperTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->accessTokenMapper = new AccessTokenMapper(\OC::$server->getDatabaseConnection(), \OC::$server->get(ITimeFactory::class)); + $this->accessTokenMapper = new AccessTokenMapper(Server::get(IDBConnection::class), Server::get(ITimeFactory::class)); } public function testGetByCode(): void { diff --git a/apps/oauth2/tests/Db/ClientMapperTest.php b/apps/oauth2/tests/Db/ClientMapperTest.php index 7c11470d09668..fccc0cd96fe50 100644 --- a/apps/oauth2/tests/Db/ClientMapperTest.php +++ b/apps/oauth2/tests/Db/ClientMapperTest.php @@ -8,6 +8,8 @@ use OCA\OAuth2\Db\Client; use OCA\OAuth2\Db\ClientMapper; use OCA\OAuth2\Exceptions\ClientNotFoundException; +use OCP\IDBConnection; +use OCP\Server; use Test\TestCase; /** @@ -19,11 +21,11 @@ class ClientMapperTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->clientMapper = new ClientMapper(\OC::$server->getDatabaseConnection()); + $this->clientMapper = new ClientMapper(Server::get(IDBConnection::class)); } protected function tearDown(): void { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->delete('oauth2_clients')->execute(); parent::tearDown(); diff --git a/apps/profile/templates/404-profile.php b/apps/profile/templates/404-profile.php index 3f2d8731347d7..8a1084b3911dd 100644 --- a/apps/profile/templates/404-profile.php +++ b/apps/profile/templates/404-profile.php @@ -10,7 +10,7 @@ if (!isset($_)) { //standalone page is not supported anymore - redirect to / require_once '../../lib/base.php'; - $urlGenerator = \OC::$server->getURLGenerator(); + $urlGenerator = \OCP\Server::get(\OCP\IURLGenerator::class); header('Location: ' . $urlGenerator->getAbsoluteURL('/')); exit; } @@ -23,7 +23,7 @@

t('Profile not found')); ?>

t('The profile does not exist.')); ?>

-

+

t('Back to %s', [$theme->getName()])); ?>

diff --git a/apps/provisioning_api/lib/Controller/AUserDataOCSController.php b/apps/provisioning_api/lib/Controller/AUserDataOCSController.php index 4db3528f8d3c7..8840bb09403fe 100644 --- a/apps/provisioning_api/lib/Controller/AUserDataOCSController.php +++ b/apps/provisioning_api/lib/Controller/AUserDataOCSController.php @@ -28,6 +28,7 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\Server; use OCP\User\Backend\ISetDisplayNameBackend; use OCP\User\Backend\ISetPasswordBackend; use OCP\Util; @@ -307,7 +308,7 @@ protected function fillStorageInfo(IUser $user): array { 'used' => 0 ]; } catch (\Exception $e) { - \OC::$server->get(\Psr\Log\LoggerInterface::class)->error( + Server::get(\Psr\Log\LoggerInterface::class)->error( 'Could not load storage info for {user}', [ 'app' => 'provisioning_api', diff --git a/apps/provisioning_api/tests/Controller/AppsControllerTest.php b/apps/provisioning_api/tests/Controller/AppsControllerTest.php index 51980ce7ed201..91ca9ff548400 100644 --- a/apps/provisioning_api/tests/Controller/AppsControllerTest.php +++ b/apps/provisioning_api/tests/Controller/AppsControllerTest.php @@ -13,6 +13,7 @@ use OCP\AppFramework\OCS\OCSException; use OCP\IRequest; use OCP\IUserSession; +use OCP\Server; /** * Class AppsTest @@ -32,9 +33,9 @@ class AppsControllerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->appManager = \OC::$server->getAppManager(); - $this->groupManager = \OC::$server->getGroupManager(); - $this->userSession = \OC::$server->getUserSession(); + $this->appManager = Server::get(IAppManager::class); + $this->groupManager = Server::get(\OCP\Group\IManager::class); + $this->userSession = Server::get(IUserSession::class); $request = $this->getMockBuilder(IRequest::class) ->disableOriginalConstructor() diff --git a/apps/provisioning_api/tests/TestCase.php b/apps/provisioning_api/tests/TestCase.php index de2a01201848c..ffb0962e5939b 100644 --- a/apps/provisioning_api/tests/TestCase.php +++ b/apps/provisioning_api/tests/TestCase.php @@ -10,6 +10,7 @@ use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; +use OCP\Server; abstract class TestCase extends \Test\TestCase { @@ -25,8 +26,8 @@ abstract class TestCase extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->userManager = \OC::$server->getUserManager(); - $this->groupManager = \OC::$server->getGroupManager(); + $this->userManager = Server::get(\OCP\User\IManager::class); + $this->groupManager = Server::get(\OCP\Group\IManager::class); $this->groupManager->createGroup('admin'); } diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php index 2841b181d1ad9..98d0ba9d967e2 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -88,6 +88,7 @@ use OCP\Group\Events\UserAddedEvent; use OCP\Group\Events\UserRemovedEvent; use OCP\IServerContainer; +use OCP\IUserSession; use OCP\Settings\Events\DeclarativeSettingsGetValueEvent; use OCP\Settings\Events\DeclarativeSettingsSetValueEvent; use OCP\Settings\IManager; @@ -133,10 +134,10 @@ public function register(IRegistrationContext $context): void { */ /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ $context->registerService('isSubAdmin', function () { - $userObject = \OC::$server->getUserSession()->getUser(); + $userObject = \OCP\Server::get(IUserSession::class)->getUser(); $isSubAdmin = false; if ($userObject !== null) { - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); + $isSubAdmin = \OCP\Server::get(\OCP\Group\IManager::class)->getSubAdmin()->isSubAdmin($userObject); } return $isSubAdmin; }); diff --git a/apps/settings/lib/Controller/AppSettingsController.php b/apps/settings/lib/Controller/AppSettingsController.php index 85fe76fff5060..3673e9cfc1ec2 100644 --- a/apps/settings/lib/Controller/AppSettingsController.php +++ b/apps/settings/lib/Controller/AppSettingsController.php @@ -520,7 +520,7 @@ public function enableApps(array $appIds, array $groups = []): JSONResponse { // Check if app is already downloaded /** @var Installer $installer */ - $installer = \OC::$server->get(Installer::class); + $installer = Server::get(Installer::class); $isDownloaded = $installer->isDownloaded($appId); if (!$isDownloaded) { @@ -546,7 +546,7 @@ public function enableApps(array $appIds, array $groups = []): JSONResponse { } private function getGroupList(array $groups) { - $groupManager = \OC::$server->getGroupManager(); + $groupManager = Server::get(\OCP\Group\IManager::class); $groupsList = []; foreach ($groups as $group) { $groupItem = $groupManager->get($group); diff --git a/apps/settings/lib/Controller/UsersController.php b/apps/settings/lib/Controller/UsersController.php index 5af16878e8eeb..da79b3fefe1c0 100644 --- a/apps/settings/lib/Controller/UsersController.php +++ b/apps/settings/lib/Controller/UsersController.php @@ -42,11 +42,13 @@ use OCP\IConfig; use OCP\IGroupManager; use OCP\IL10N; +use OCP\INavigationManager; use OCP\IRequest; use OCP\IUser; use OCP\IUserSession; use OCP\L10N\IFactory; use OCP\Mail\IMailer; +use OCP\Server; use OCP\Util; use function in_array; @@ -100,7 +102,7 @@ public function usersList(): TemplateResponse { $isAdmin = $this->groupManager->isAdmin($uid); $isDelegatedAdmin = $this->groupManager->isDelegatedAdmin($uid); - \OC::$server->getNavigationManager()->setActiveEntry('core_users'); + Server::get(INavigationManager::class)->setActiveEntry('core_users'); /* SORT OPTION: SORT_USERCOUNT or SORT_GROUPNAME */ $sortGroupsBy = MetaData::SORT_USERCOUNT; diff --git a/apps/settings/templates/settings/admin/delegation.php b/apps/settings/templates/settings/admin/delegation.php index 80298a6672597..757226be67637 100644 --- a/apps/settings/templates/settings/admin/delegation.php +++ b/apps/settings/templates/settings/admin/delegation.php @@ -5,7 +5,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -script('settings', 'vue-settings-admin-delegation'); +\OCP\Util::addScript('settings', 'vue-settings-admin-delegation', 'core'); ?>
diff --git a/apps/settings/templates/settings/admin/overview.php b/apps/settings/templates/settings/admin/overview.php index 1844216bbbb86..c2758305cfc08 100644 --- a/apps/settings/templates/settings/admin/overview.php +++ b/apps/settings/templates/settings/admin/overview.php @@ -45,7 +45,7 @@ class="icon-info"

diff --git a/apps/settings/templates/settings/frame.php b/apps/settings/templates/settings/frame.php index 4a49ab17ae843..2b3e67aa687b9 100644 --- a/apps/settings/templates/settings/frame.php +++ b/apps/settings/templates/settings/frame.php @@ -5,9 +5,9 @@ */ style('settings', 'settings'); -script('settings', 'settings'); +\OCP\Util::addScript('settings', 'settings', 'core'); \OCP\Util::addScript('settings', 'legacy-admin'); -script('core', 'setupchecks'); +\OCP\Util::addScript('core', 'setupchecks', 'core'); ?> @@ -19,7 +19,7 @@

    getURLGenerator()->linkToRoute('settings.PersonalSettings.index', ['section' => $form['anchor']]); + $anchor = \OCP\Server::get(\OCP\IURLGenerator::class)->linkToRoute('settings.PersonalSettings.index', ['section' => $form['anchor']]); $class = 'nav-icon-' . $form['anchor']; $sectionName = $form['section-name']; ?>
  • data-section-id="" data-section-type="personal"> @@ -46,7 +46,7 @@
      getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]); + $anchor = \OCP\Server::get(\OCP\IURLGenerator::class)->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]); $class = 'nav-icon-' . $form['anchor']; $sectionName = $form['section-name']; ?>
    • data-section-id="" data-section-type="admin"> diff --git a/apps/settings/templates/settings/personal/security/authtokens.php b/apps/settings/templates/settings/personal/security/authtokens.php index 3bc00c80e51a0..e59266695bf7a 100644 --- a/apps/settings/templates/settings/personal/security/authtokens.php +++ b/apps/settings/templates/settings/personal/security/authtokens.php @@ -5,7 +5,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -script('settings', 'vue-settings-personal-security'); +\OCP\Util::addScript('settings', 'vue-settings-personal-security', 'core'); ?> diff --git a/apps/settings/templates/settings/personal/security/webauthn.php b/apps/settings/templates/settings/personal/security/webauthn.php index 0bcf063bd9608..33611b5399c25 100644 --- a/apps/settings/templates/settings/personal/security/webauthn.php +++ b/apps/settings/templates/settings/personal/security/webauthn.php @@ -5,7 +5,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -script('settings', 'vue-settings-personal-webauthn'); +\OCP\Util::addScript('settings', 'vue-settings-personal-webauthn', 'core'); ?> diff --git a/apps/settings/tests/Settings/Admin/ServerTest.php b/apps/settings/tests/Settings/Admin/ServerTest.php index a49dcc98bf89b..f9c10d864e428 100644 --- a/apps/settings/tests/Settings/Admin/ServerTest.php +++ b/apps/settings/tests/Settings/Admin/ServerTest.php @@ -46,7 +46,7 @@ class ServerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OCP\Server::get(IDBConnection::class); $this->initialStateService = $this->createMock(IInitialState::class); $this->profileManager = $this->createMock(ProfileManager::class); $this->timeFactory = $this->createMock(ITimeFactory::class); diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index 05435b835e095..38a4a3af4a266 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -1145,8 +1145,8 @@ private function createDummyShare($itemType, $itemSource, $shareWith, $sharedBy, } public function testGetSharesInFolder(): void { - $userManager = \OC::$server->getUserManager(); - $rootFolder = \OC::$server->getRootFolder(); + $userManager = Server::get(\OCP\User\IManager::class); + $rootFolder = Server::get(IRootFolder::class); $this->shareManager->expects($this->any()) ->method('newShare') @@ -1192,8 +1192,8 @@ public function testGetSharesInFolder(): void { } public function testGetAccessList(): void { - $userManager = \OC::$server->getUserManager(); - $rootFolder = \OC::$server->getRootFolder(); + $userManager = Server::get(\OCP\User\IManager::class); + $rootFolder = Server::get(IRootFolder::class); $this->shareManager->expects($this->any()) ->method('newShare') diff --git a/apps/testing/lib/AlternativeHomeUserBackend.php b/apps/testing/lib/AlternativeHomeUserBackend.php index 730b11bcf74b7..549209652b4fc 100644 --- a/apps/testing/lib/AlternativeHomeUserBackend.php +++ b/apps/testing/lib/AlternativeHomeUserBackend.php @@ -6,6 +6,8 @@ namespace OCA\Testing; use OC\User\Database; +use OCP\IConfig; +use OCP\Server; /** * Alternative home user backend. @@ -34,7 +36,7 @@ public function getHome($uid) { if ($uid !== 'admin') { $uid = md5($uid); } - return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid; + return Server::get(IConfig::class)->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid; } return false; diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php index fbb465505ac0a..c4e1c6b210705 100644 --- a/apps/theming/lib/Util.php +++ b/apps/theming/lib/Util.php @@ -13,6 +13,7 @@ use OCP\Files\SimpleFS\ISimpleFile; use OCP\IConfig; use OCP\IUserSession; +use OCP\Server; use OCP\ServerVersion; class Util { @@ -302,7 +303,7 @@ public function isLogoThemed() { } public function getCacheBuster(): string { - $userSession = \OC::$server->get(IUserSession::class); + $userSession = Server::get(IUserSession::class); $userId = ''; $user = $userSession->getUser(); if (!is_null($user)) { diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 3c283fcb697ab..e31fecfad5450 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -25,7 +25,9 @@ use OCP\IL10N; use OCP\INavigationManager; use OCP\IRequest; +use OCP\ITempManager; use OCP\IURLGenerator; +use OCP\Server; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; @@ -355,8 +357,8 @@ public function dataUpdateImages() { /** @dataProvider dataUpdateImages */ public function testUpdateLogoNormalLogoUpload($mimeType, $folderExists = true): void { - $tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg'; - $destination = \OC::$server->getTempManager()->getTemporaryFolder(); + $tmpLogo = Server::get(ITempManager::class)->getTemporaryFolder() . '/logo.svg'; + $destination = Server::get(ITempManager::class)->getTemporaryFolder(); touch($tmpLogo); copy(__DIR__ . '/../../../../tests/data/testimage.png', $tmpLogo); @@ -407,7 +409,7 @@ public function testUpdateLogoNormalLogoUpload($mimeType, $folderExists = true): /** @dataProvider dataUpdateImages */ public function testUpdateLogoLoginScreenUpload($folderExists): void { - $tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . 'logo.png'; + $tmpLogo = Server::get(ITempManager::class)->getTemporaryFolder() . 'logo.png'; touch($tmpLogo); copy(__DIR__ . '/../../../../tests/data/desktopapp.png', $tmpLogo); @@ -455,7 +457,7 @@ public function testUpdateLogoLoginScreenUpload($folderExists): void { } public function testUpdateLogoLoginScreenUploadWithInvalidImage(): void { - $tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg'; + $tmpLogo = Server::get(ITempManager::class)->getTemporaryFolder() . '/logo.svg'; touch($tmpLogo); file_put_contents($tmpLogo, file_get_contents(__DIR__ . '/../../../../tests/data/data.zip')); diff --git a/apps/twofactor_backupcodes/templates/personal.php b/apps/twofactor_backupcodes/templates/personal.php index 37036cee12282..838e2016777f7 100644 --- a/apps/twofactor_backupcodes/templates/personal.php +++ b/apps/twofactor_backupcodes/templates/personal.php @@ -5,7 +5,7 @@ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -script('twofactor_backupcodes', 'settings'); +\OCP\Util::addScript('twofactor_backupcodes', 'settings', 'core'); ?> diff --git a/apps/twofactor_backupcodes/tests/Db/BackupCodeMapperTest.php b/apps/twofactor_backupcodes/tests/Db/BackupCodeMapperTest.php index 5cde4c5a7184f..1bc78aadda332 100644 --- a/apps/twofactor_backupcodes/tests/Db/BackupCodeMapperTest.php +++ b/apps/twofactor_backupcodes/tests/Db/BackupCodeMapperTest.php @@ -12,6 +12,7 @@ use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper; use OCP\IDBConnection; use OCP\IUser; +use OCP\Server; use Test\TestCase; /** @@ -38,7 +39,7 @@ private function resetDB() { protected function setUp(): void { parent::setUp(); - $this->db = \OC::$server->getDatabaseConnection(); + $this->db = Server::get(IDBConnection::class); $this->mapper = \OC::$server->query(BackupCodeMapper::class); $this->resetDB(); diff --git a/apps/user_ldap/ajax/clearMappings.php b/apps/user_ldap/ajax/clearMappings.php index 7df622f5e377d..1058c7bb8ebde 100644 --- a/apps/user_ldap/ajax/clearMappings.php +++ b/apps/user_ldap/ajax/clearMappings.php @@ -8,6 +8,7 @@ use OCA\User_LDAP\Mapping\GroupMapping; use OCA\User_LDAP\Mapping\UserMapping; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IDBConnection; use OCP\Server; use OCP\User\Events\BeforeUserIdUnassignedEvent; use OCP\User\Events\UserIdUnassignedEvent; @@ -28,15 +29,15 @@ $result = $mapping->clearCb( function (string $uid) use ($dispatcher): void { $dispatcher->dispatchTyped(new BeforeUserIdUnassignedEvent($uid)); - \OC::$server->getUserManager()->emit('\OC\User', 'preUnassignedUserId', [$uid]); + Server::get(\OCP\User\IManager::class)->emit('\OC\User', 'preUnassignedUserId', [$uid]); }, function (string $uid) use ($dispatcher): void { $dispatcher->dispatchTyped(new UserIdUnassignedEvent($uid)); - \OC::$server->getUserManager()->emit('\OC\User', 'postUnassignedUserId', [$uid]); + Server::get(\OCP\User\IManager::class)->emit('\OC\User', 'postUnassignedUserId', [$uid]); } ); } elseif ($subject === 'group') { - $mapping = new GroupMapping(\OC::$server->getDatabaseConnection()); + $mapping = new GroupMapping(Server::get(IDBConnection::class)); $result = $mapping->clear(); } diff --git a/apps/user_ldap/ajax/deleteConfiguration.php b/apps/user_ldap/ajax/deleteConfiguration.php index 09899a7c6c642..f09295355aca2 100644 --- a/apps/user_ldap/ajax/deleteConfiguration.php +++ b/apps/user_ldap/ajax/deleteConfiguration.php @@ -1,6 +1,9 @@ getConfig(), \OC::$server->getDatabaseConnection()); +$helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); if ($helper->deleteServerConfiguration($prefix)) { \OC_JSON::success(); } else { diff --git a/apps/user_ldap/ajax/getNewServerConfigPrefix.php b/apps/user_ldap/ajax/getNewServerConfigPrefix.php index a91c3c516ab8f..e8746a7c1b11b 100644 --- a/apps/user_ldap/ajax/getNewServerConfigPrefix.php +++ b/apps/user_ldap/ajax/getNewServerConfigPrefix.php @@ -2,6 +2,9 @@ use OCA\User_LDAP\Configuration; use OCA\User_LDAP\Helper; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Server; /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors @@ -13,7 +16,7 @@ \OC_JSON::checkAppEnabled('user_ldap'); \OC_JSON::callCheck(); -$helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); +$helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); $serverConnections = $helper->getServerConfigurationPrefixes(); sort($serverConnections); $lk = array_pop($serverConnections); diff --git a/apps/user_ldap/ajax/testConfiguration.php b/apps/user_ldap/ajax/testConfiguration.php index 16f0c583ae0d2..b91eab8fd92b4 100644 --- a/apps/user_ldap/ajax/testConfiguration.php +++ b/apps/user_ldap/ajax/testConfiguration.php @@ -1,6 +1,8 @@ getSession()->close(); + Server::get(ISession::class)->close(); if ($connection->bind()) { /* * This shiny if block is an ugly hack to find out whether anonymous diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php index fa6ed9d3a5ac7..19980bf492150 100644 --- a/apps/user_ldap/ajax/wizard.php +++ b/apps/user_ldap/ajax/wizard.php @@ -4,6 +4,7 @@ use OCA\User_LDAP\Configuration; use OCA\User_LDAP\LDAP; use OCA\User_LDAP\Wizard; +use OCP\Server; use OCP\Util; /** @@ -36,7 +37,7 @@ $con->ldapConfigurationActive = (string)true; $con->setIgnoreValidation(true); -$factory = \OC::$server->get(AccessFactory::class); +$factory = Server::get(AccessFactory::class); $access = $factory->get($con); $wizard = new Wizard($configuration, $ldapWrapper, $access); diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index 88d34297bbdb5..31a926170673b 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -20,6 +20,7 @@ use OCP\IAppConfig; use OCP\IConfig; use OCP\IUserManager; +use OCP\Server; use OCP\User\Events\UserIdAssignedEvent; use OCP\Util; use Psr\Log\LoggerInterface; @@ -594,7 +595,7 @@ public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped $this->connection->setConfiguration(['ldapCacheTTL' => 0]); if ($intName !== '' && (($isUser && !$this->ncUserManager->userExists($intName)) - || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName)) + || (!$isUser && !Server::get(\OCP\Group\IManager::class)->groupExists($intName)) ) ) { $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]); @@ -828,7 +829,7 @@ private function _createAltInternalOwnCloudNameForGroups(string $name) { // Check to be really sure it is unique // while loop is just a precaution. If a name is not generated within // 20 attempts, something else is very wrong. Avoids infinite loop. - if (!\OC::$server->getGroupManager()->groupExists($altName)) { + if (!Server::get(\OCP\Group\IManager::class)->groupExists($altName)) { return $altName; } $altName = $name . '_' . ($lastNo + $attempts); @@ -1586,7 +1587,7 @@ private function getFilterPartForSearch(string $search, $searchAttributes, strin * a * */ private function prepareSearchTerm(string $term): string { - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); $allowEnum = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'); diff --git a/apps/user_ldap/lib/Command/Search.php b/apps/user_ldap/lib/Command/Search.php index fe1b9f3498835..ad13c94c84a56 100644 --- a/apps/user_ldap/lib/Command/Search.php +++ b/apps/user_ldap/lib/Command/Search.php @@ -12,6 +12,8 @@ use OCA\User_LDAP\LDAP; use OCA\User_LDAP\User_Proxy; use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Server; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -81,7 +83,7 @@ protected function validateOffsetAndLimit(int $offset, int $limit): void { } protected function execute(InputInterface $input, OutputInterface $output): int { - $helper = new Helper($this->ocConfig, \OC::$server->getDatabaseConnection()); + $helper = new Helper($this->ocConfig, Server::get(IDBConnection::class)); $configPrefixes = $helper->getServerConfigurationPrefixes(true); $ldapWrapper = new LDAP(); diff --git a/apps/user_ldap/lib/Command/SetConfig.php b/apps/user_ldap/lib/Command/SetConfig.php index 3a2bc4437e302..5a0b65a2c3e27 100644 --- a/apps/user_ldap/lib/Command/SetConfig.php +++ b/apps/user_ldap/lib/Command/SetConfig.php @@ -11,6 +11,9 @@ use OCA\User_LDAP\ConnectionFactory; use OCA\User_LDAP\Helper; use OCA\User_LDAP\LDAP; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Server; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -40,7 +43,7 @@ protected function configure(): void { } protected function execute(InputInterface $input, OutputInterface $output): int { - $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); + $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); $availableConfigs = $helper->getServerConfigurationPrefixes(); $configID = $input->getArgument('configID'); if (!in_array($configID, $availableConfigs)) { diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php index 77f8ed0575f1f..b4a5b84720421 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -7,6 +7,7 @@ */ namespace OCA\User_LDAP; +use OCP\IConfig; use OCP\Server; use Psr\Log\LoggerInterface; @@ -439,7 +440,7 @@ protected function getLcValue(string $varName): string { protected function getSystemValue(string $varName): string { //FIXME: if another system value is added, softcode the default value - return \OC::$server->getConfig()->getSystemValue($varName, false); + return Server::get(IConfig::class)->getSystemValue($varName, false); } protected function getValue(string $varName): string { @@ -447,7 +448,7 @@ protected function getValue(string $varName): string { if (is_null($defaults)) { $defaults = $this->getDefaults(); } - return \OC::$server->getConfig()->getAppValue('user_ldap', + return Server::get(IConfig::class)->getAppValue('user_ldap', $this->configPrefix . $varName, $defaults[$varName]); } @@ -476,7 +477,7 @@ protected function setRawValue(string $varName, $value): void { } protected function saveValue(string $varName, string $value): bool { - \OC::$server->getConfig()->setAppValue( + Server::get(IConfig::class)->setAppValue( 'user_ldap', $this->configPrefix . $varName, $value diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php index 93a83709055dc..e7f2a41364326 100644 --- a/apps/user_ldap/lib/Connection.php +++ b/apps/user_ldap/lib/Connection.php @@ -9,6 +9,10 @@ use OC\ServerNotAvailableException; use OCP\ICache; +use OCP\ICacheFactory; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Server; use Psr\Log\LoggerInterface; /** @@ -145,14 +149,14 @@ public function __construct( ) { parent::__construct($ldap); $this->configuration = new Configuration($this->configPrefix, !is_null($this->configID)); - $memcache = \OC::$server->getMemCacheFactory(); + $memcache = Server::get(ICacheFactory::class); if ($memcache->isAvailable()) { $this->cache = $memcache->createDistributed(); } - $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); + $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); $this->doNotValidate = !in_array($this->configPrefix, $helper->getServerConfigurationPrefixes()); - $this->logger = \OC::$server->get(LoggerInterface::class); + $this->logger = Server::get(LoggerInterface::class); } public function __destruct() { diff --git a/apps/user_ldap/lib/Helper.php b/apps/user_ldap/lib/Helper.php index 09be9e081e584..27c19e6c4f59c 100644 --- a/apps/user_ldap/lib/Helper.php +++ b/apps/user_ldap/lib/Helper.php @@ -11,6 +11,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IConfig; use OCP\IDBConnection; +use OCP\Server; class Helper { /** @var CappedMemoryCache */ @@ -269,7 +270,7 @@ public static function loginName2UserName($param): void { throw new \Exception('key uid is expected to be set in $param'); } - $userBackend = \OC::$server->get(User_Proxy::class); + $userBackend = Server::get(User_Proxy::class); $uid = $userBackend->loginName2UserName($param['uid']); if ($uid !== false) { $param['uid'] = $uid; diff --git a/apps/user_ldap/lib/Jobs/CleanUp.php b/apps/user_ldap/lib/Jobs/CleanUp.php index 6e62441942468..7cfc473c9509a 100644 --- a/apps/user_ldap/lib/Jobs/CleanUp.php +++ b/apps/user_ldap/lib/Jobs/CleanUp.php @@ -49,7 +49,7 @@ public function __construct( protected DeletedUsersIndex $dui, ) { parent::__construct($timeFactory); - $minutes = \OC::$server->getConfig()->getSystemValue( + $minutes = Server::get(IConfig::class)->getSystemValue( 'ldapUserCleanupInterval', (string)$this->defaultIntervalMin); $this->setInterval((int)$minutes * 60); } @@ -67,13 +67,13 @@ public function setArguments($arguments): void { if (isset($arguments['helper'])) { $this->ldapHelper = $arguments['helper']; } else { - $this->ldapHelper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); + $this->ldapHelper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); } if (isset($arguments['ocConfig'])) { $this->ocConfig = $arguments['ocConfig']; } else { - $this->ocConfig = \OC::$server->getConfig(); + $this->ocConfig = Server::get(IConfig::class); } if (isset($arguments['userBackend'])) { @@ -83,7 +83,7 @@ public function setArguments($arguments): void { if (isset($arguments['db'])) { $this->db = $arguments['db']; } else { - $this->db = \OC::$server->getDatabaseConnection(); + $this->db = Server::get(IDBConnection::class); } if (isset($arguments['mapping'])) { diff --git a/apps/user_ldap/lib/LDAP.php b/apps/user_ldap/lib/LDAP.php index 44d8493b925c5..50af2556c7201 100644 --- a/apps/user_ldap/lib/LDAP.php +++ b/apps/user_ldap/lib/LDAP.php @@ -25,7 +25,7 @@ public function __construct( protected string $logFile = '', ) { /** @var IProfiler $profiler */ - $profiler = \OC::$server->get(IProfiler::class); + $profiler = Server::get(IProfiler::class); if ($profiler->isEnabled()) { $this->dataCollector = new LdapDataCollector(); $profiler->add($this->dataCollector); diff --git a/apps/user_ldap/lib/Proxy.php b/apps/user_ldap/lib/Proxy.php index ab8b9f451f050..e2f5c9ebf5923 100644 --- a/apps/user_ldap/lib/Proxy.php +++ b/apps/user_ldap/lib/Proxy.php @@ -10,6 +10,7 @@ use OCA\User_LDAP\Mapping\GroupMapping; use OCA\User_LDAP\Mapping\UserMapping; use OCP\ICache; +use OCP\ICacheFactory; use OCP\Server; abstract class Proxy { @@ -22,7 +23,7 @@ public function __construct( private ILDAPWrapper $ldap, private AccessFactory $accessFactory, ) { - $memcache = \OC::$server->getMemCacheFactory(); + $memcache = Server::get(ICacheFactory::class); if ($memcache->isAvailable()) { $this->cache = $memcache->createDistributed(); } diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php index 80d1e6437f7e3..bf75d3ce378f3 100644 --- a/apps/user_ldap/lib/Settings/Admin.php +++ b/apps/user_ldap/lib/Settings/Admin.php @@ -8,7 +8,10 @@ use OCA\User_LDAP\Configuration; use OCA\User_LDAP\Helper; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\IDBConnection; use OCP\IL10N; +use OCP\Server; use OCP\Settings\IDelegatedSettings; use OCP\Template; @@ -25,7 +28,7 @@ public function __construct( * @return TemplateResponse */ public function getForm() { - $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); + $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); $prefixes = $helper->getServerConfigurationPrefixes(); if (count($prefixes) === 0) { $newPrefix = $helper->getNextServerConfigurationPrefix(); diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index ec06d1d86363a..f97867e98d440 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -18,6 +18,7 @@ use OCP\IAvatarManager; use OCP\IConfig; use OCP\Image; +use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\Notification\IManager as INotificationManager; @@ -769,10 +770,10 @@ public function handlePasswordExpiry(array $params): void { if (!empty($pwdGraceAuthNLimit) && count($pwdGraceUseTime) < (int)$pwdGraceAuthNLimit[0]) { //at least one more grace login available? $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true'); - header('Location: ' . \OC::$server->getURLGenerator()->linkToRouteAbsolute( + header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute( 'user_ldap.renewPassword.showRenewPasswordForm', ['user' => $uid])); } else { //no more grace login available - header('Location: ' . \OC::$server->getURLGenerator()->linkToRouteAbsolute( + header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute( 'user_ldap.renewPassword.showLoginFormInvalidPassword', ['user' => $uid])); } exit(); @@ -780,7 +781,7 @@ public function handlePasswordExpiry(array $params): void { //handle pwdReset attribute if (!empty($pwdReset) && $pwdReset[0] === 'TRUE') { //user must change their password $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true'); - header('Location: ' . \OC::$server->getURLGenerator()->linkToRouteAbsolute( + header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute( 'user_ldap.renewPassword.showRenewPasswordForm', ['user' => $uid])); exit(); } diff --git a/apps/user_ldap/lib/Wizard.php b/apps/user_ldap/lib/Wizard.php index 6df5aba4cac80..6fe6c0c2906cb 100644 --- a/apps/user_ldap/lib/Wizard.php +++ b/apps/user_ldap/lib/Wizard.php @@ -11,6 +11,7 @@ use OC\ServerNotAvailableException; use OCP\IL10N; use OCP\L10N\IFactory as IL10NFactory; +use OCP\Server; use OCP\Util; use Psr\Log\LoggerInterface; @@ -40,10 +41,10 @@ public function __construct( ) { parent::__construct($ldap); if (is_null(static::$l)) { - static::$l = \OC::$server->get(IL10NFactory::class)->get('user_ldap'); + static::$l = Server::get(IL10NFactory::class)->get('user_ldap'); } $this->result = new WizardResult(); - $this->logger = \OC::$server->get(LoggerInterface::class); + $this->logger = Server::get(LoggerInterface::class); } public function __destruct() { @@ -709,7 +710,7 @@ public function guessBaseDN() { //this did not help :( //Let's see whether we can parse the Host URL and convert the domain to //a base DN - $helper = \OC::$server->get(Helper::class); + $helper = Server::get(Helper::class); $domain = $helper->getDomainFromURL($this->configuration->ldapHost); if (!$domain) { return false; diff --git a/apps/user_ldap/templates/renewpassword.php b/apps/user_ldap/templates/renewpassword.php index 6f09230a88c6d..3345be29c13dc 100644 --- a/apps/user_ldap/templates/renewpassword.php +++ b/apps/user_ldap/templates/renewpassword.php @@ -6,11 +6,11 @@ */ /** @var \OCP\IL10N $l */ -script('user_ldap', 'renewPassword'); +\OCP\Util::addScript('user_ldap', 'renewPassword', 'core'); style('user_ldap', 'renewPassword'); ?> - +
      t('Please renew your password.')); ?>
      diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php index 1ecc5565bed53..5b824a89e9688 100644 --- a/apps/user_ldap/tests/AccessTest.php +++ b/apps/user_ldap/tests/AccessTest.php @@ -23,9 +23,11 @@ use OCP\IAppConfig; use OCP\IAvatarManager; use OCP\IConfig; +use OCP\IDBConnection; use OCP\Image; use OCP\IUserManager; use OCP\Notification\IManager as INotificationManager; +use OCP\Server; use OCP\Share\IManager; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -117,7 +119,7 @@ private function getConnectorAndLdapMock() { $this->createMock(INotificationManager::class), $this->shareManager]) ->getMock(); - $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); + $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); return [$lw, $connector, $um, $helper]; } diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php index 13c5d35dce4aa..ad97d5024b152 100644 --- a/apps/user_ldap/tests/Group_LDAPTest.php +++ b/apps/user_ldap/tests/Group_LDAPTest.php @@ -21,6 +21,8 @@ use OCP\IConfig; use OCP\IUser; use OCP\IUserManager; +use OCP\Security\ISecureRandom; +use OCP\Server; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; @@ -155,7 +157,7 @@ public function testCountWithSearchString(): void { $this->access->expects($this->any()) ->method('dn2username') ->willReturnCallback(function () { - return 'foobar' . \OC::$server->getSecureRandom()->generate(7); + return 'foobar' . Server::get(ISecureRandom::class)->generate(7); }); $this->access->expects($this->any()) ->method('isDNPartOfBase') diff --git a/apps/user_ldap/tests/HelperTest.php b/apps/user_ldap/tests/HelperTest.php index 38c6a6393406c..eee5c162b53e8 100644 --- a/apps/user_ldap/tests/HelperTest.php +++ b/apps/user_ldap/tests/HelperTest.php @@ -7,6 +7,8 @@ use OCA\User_LDAP\Helper; use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Server; /** * @group DB @@ -23,7 +25,7 @@ protected function setUp(): void { parent::setUp(); $this->config = $this->createMock(IConfig::class); - $this->helper = new Helper($this->config, \OC::$server->getDatabaseConnection()); + $this->helper = new Helper($this->config, Server::get(IDBConnection::class)); } public function testGetServerConfigurationPrefixes(): void { diff --git a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php index 12f9763761810..807ace1ff0fe5 100644 --- a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php +++ b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php @@ -15,6 +15,8 @@ use OCA\User_LDAP\User\Manager; use OCA\User_LDAP\UserPluginManager; use OCP\IAvatarManager; +use OCP\IConfig; +use OCP\IDBConnection; use OCP\Image; use OCP\Server; use OCP\Share\IManager; @@ -108,13 +110,13 @@ protected function initConnection() { */ protected function initUserManager() { $this->userManager = new Manager( - \OC::$server->getConfig(), - \OC::$server->get(LoggerInterface::class), - \OC::$server->get(IAvatarManager::class), + Server::get(IConfig::class), + Server::get(LoggerInterface::class), + Server::get(IAvatarManager::class), new Image(), - \OC::$server->getUserManager(), - \OC::$server->getNotificationManager(), - \OC::$server->get(IManager::class) + Server::get(\OCP\User\IManager::class), + Server::get(\OCP\Notification\IManager::class), + Server::get(IManager::class) ); } @@ -122,14 +124,14 @@ protected function initUserManager() { * initializes the test Helper */ protected function initHelper() { - $this->helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); + $this->helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); } /** * initializes the Access test instance */ protected function initAccess() { - $this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, \OC::$server->getConfig(), Server::get(LoggerInterface::class)); + $this->access = new Access($this->connection, $this->ldap, $this->userManager, $this->helper, Server::get(IConfig::class), Server::get(LoggerInterface::class)); } /** diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php index 27d088617239a..e1399cd18bc8e 100644 --- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php +++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestAttributeDetection.php @@ -14,6 +14,8 @@ use OCA\User_LDAP\User_LDAP; use OCA\User_LDAP\UserPluginManager; use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Server; use Psr\Log\LoggerInterface; require_once __DIR__ . '/../Bootstrap.php'; @@ -28,28 +30,28 @@ public function init() { $this->connection->setConfiguration(['ldapGroupFilter' => 'objectClass=groupOfNames']); $this->connection->setConfiguration(['ldapGroupMemberAssocAttr' => 'member']); - $userMapper = new UserMapping(\OC::$server->getDatabaseConnection()); + $userMapper = new UserMapping(Server::get(IDBConnection::class)); $userMapper->clear(); $this->access->setUserMapper($userMapper); - $groupMapper = new GroupMapping(\OC::$server->getDatabaseConnection()); + $groupMapper = new GroupMapping(Server::get(IDBConnection::class)); $groupMapper->clear(); $this->access->setGroupMapper($groupMapper); - $userBackend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class)); - $userManager = \OC::$server->getUserManager(); + $userBackend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class)); + $userManager = Server::get(\OCP\User\IManager::class); $userManager->clearBackends(); $userManager->registerBackend($userBackend); - $groupBackend = new Group_LDAP($this->access, \OC::$server->query(GroupPluginManager::class), \OC::$server->get(IConfig::class)); - $groupManger = \OC::$server->getGroupManager(); + $groupBackend = new Group_LDAP($this->access, \OC::$server->query(GroupPluginManager::class), Server::get(IConfig::class)); + $groupManger = Server::get(\OCP\Group\IManager::class); $groupManger->clearBackends(); $groupManger->addBackend($groupBackend); } protected function caseNativeUUIDAttributeUsers() { // trigger importing of users which also triggers UUID attribute detection - \OC::$server->getUserManager()->search('', 5, 0); + Server::get(\OCP\User\IManager::class)->search('', 5, 0); return $this->connection->ldapUuidUserAttribute === 'entryuuid'; } @@ -58,7 +60,7 @@ protected function caseNativeUUIDAttributeGroups() { // are similar, but we take no chances. // trigger importing of users which also triggers UUID attribute detection - \OC::$server->getGroupManager()->search('', 5, 0); + Server::get(\OCP\Group\IManager::class)->search('', 5, 0); return $this->connection->ldapUuidGroupAttribute === 'entryuuid'; } } diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php index fe7a3d2226a8c..1c2d7145ddfc7 100644 --- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php +++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php @@ -12,6 +12,8 @@ use OCA\User_LDAP\User\DeletedUsersIndex; use OCA\User_LDAP\User_LDAP; use OCA\User_LDAP\UserPluginManager; +use OCP\IDBConnection; +use OCP\Server; use Psr\Log\LoggerInterface; require_once __DIR__ . '/../Bootstrap.php'; @@ -31,10 +33,10 @@ public function init() { require(__DIR__ . '/../setup-scripts/createExplicitUsers.php'); parent::init(); - $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection()); + $this->mapping = new UserMapping(Server::get(IDBConnection::class)); $this->mapping->clear(); $this->access->setUserMapper($this->mapping); - $this->backend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class)); + $this->backend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class)); } /** diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php index e7b68735f6e52..3e21d22fca3fe 100644 --- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php +++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php @@ -12,6 +12,7 @@ use OCA\User_LDAP\User\DeletedUsersIndex; use OCA\User_LDAP\User_LDAP; use OCA\User_LDAP\UserPluginManager; +use OCP\Server; use Psr\Log\LoggerInterface; require_once __DIR__ . '/../Bootstrap.php'; @@ -34,7 +35,7 @@ public function init() { require(__DIR__ . '/../setup-scripts/createExplicitUsers.php'); parent::init(); - $this->backend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class)); + $this->backend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class)); } public function initConnection() { diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php index 75ce42e299c24..74e1f48dda82f 100644 --- a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php +++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php @@ -15,7 +15,10 @@ use OCA\User_LDAP\User_LDAP; use OCA\User_LDAP\UserPluginManager; use OCP\IAvatarManager; +use OCP\IConfig; +use OCP\IDBConnection; use OCP\Image; +use OCP\Server; use Psr\Log\LoggerInterface; require_once __DIR__ . '/../../Bootstrap.php'; @@ -31,10 +34,10 @@ class IntegrationTestUserAvatar extends AbstractIntegrationTest { public function init() { require(__DIR__ . '/../../setup-scripts/createExplicitUsers.php'); parent::init(); - $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection()); + $this->mapping = new UserMapping(Server::get(IDBConnection::class)); $this->mapping->clear(); $this->access->setUserMapper($this->mapping); - $userBackend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class)); + $userBackend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class)); \OC_User::useBackend($userBackend); } @@ -57,9 +60,9 @@ private function execFetchTest($dn, $username, $image) { \OC_Util::tearDownFS(); \OC_Util::setupFS($username); \OC::$server->getUserFolder($username); - \OC::$server->getConfig()->deleteUserValue($username, 'user_ldap', User::USER_PREFKEY_LASTREFRESH); - if (\OC::$server->get(IAvatarManager::class)->getAvatar($username)->exists()) { - \OC::$server->get(IAvatarManager::class)->getAvatar($username)->remove(); + Server::get(IConfig::class)->deleteUserValue($username, 'user_ldap', User::USER_PREFKEY_LASTREFRESH); + if (Server::get(IAvatarManager::class)->getAvatar($username)->exists()) { + Server::get(IAvatarManager::class)->getAvatar($username)->remove(); } // finally attempt to get the avatar set @@ -79,7 +82,7 @@ protected function case1() { $this->execFetchTest($dn, $username, $image); - return \OC::$server->get(IAvatarManager::class)->getAvatar($username)->exists(); + return Server::get(IAvatarManager::class)->getAvatar($username)->exists(); } /** @@ -96,7 +99,7 @@ protected function case2() { $this->execFetchTest($dn, $username, $image); - return !\OC::$server->get(IAvatarManager::class)->getAvatar($username)->exists(); + return !Server::get(IAvatarManager::class)->getAvatar($username)->exists(); } /** @@ -113,13 +116,13 @@ private function setJpegPhotoAttribute($dn, $image) { protected function initUserManager() { $this->userManager = new Manager( - \OC::$server->getConfig(), - \OC::$server->get(LoggerInterface::class), - \OC::$server->get(IAvatarManager::class), + Server::get(IConfig::class), + Server::get(LoggerInterface::class), + Server::get(IAvatarManager::class), new Image(), - \OC::$server->getDatabaseConnection(), - \OC::$server->getUserManager(), - \OC::$server->getNotificationManager() + Server::get(IDBConnection::class), + Server::get(\OCP\User\IManager::class), + Server::get(\OCP\Notification\IManager::class) ); } diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserCleanUp.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserCleanUp.php index ed637155e5a43..f5fcac7a90503 100644 --- a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserCleanUp.php +++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserCleanUp.php @@ -13,6 +13,8 @@ use OCA\User_LDAP\User\DeletedUsersIndex; use OCA\User_LDAP\User_LDAP; use OCA\User_LDAP\UserPluginManager; +use OCP\IDBConnection; +use OCP\Server; use Psr\Log\LoggerInterface; require_once __DIR__ . '/../../Bootstrap.php'; @@ -28,11 +30,11 @@ class IntegrationTestUserCleanUp extends AbstractIntegrationTest { public function init() { require(__DIR__ . '/../../setup-scripts/createExplicitUsers.php'); parent::init(); - $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection()); + $this->mapping = new UserMapping(Server::get(IDBConnection::class)); $this->mapping->clear(); $this->access->setUserMapper($this->mapping); - $userBackend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class)); + $userBackend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class)); \OC_User::useBackend($userBackend); } @@ -70,13 +72,13 @@ protected function case1() { // user instance must not be requested from global user manager, before // it is deleted from the LDAP server. The instance will be returned // from cache and may false-positively confirm the correctness. - $user = \OC::$server->getUserManager()->get($username); + $user = Server::get(\OCP\User\IManager::class)->get($username); if ($user === null) { return false; } $user->delete(); - return \OC::$server->getUserManager()->get($username) === null; + return Server::get(\OCP\User\IManager::class)->get($username) === null; } } diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php index e8f94dac4195f..417314ec4215e 100644 --- a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php +++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php @@ -12,6 +12,8 @@ use OCA\User_LDAP\User\DeletedUsersIndex; use OCA\User_LDAP\User_LDAP; use OCA\User_LDAP\UserPluginManager; +use OCP\IDBConnection; +use OCP\Server; use Psr\Log\LoggerInterface; require_once __DIR__ . '/../../Bootstrap.php'; @@ -27,10 +29,10 @@ class IntegrationTestUserDisplayName extends AbstractIntegrationTest { public function init() { require(__DIR__ . '/../../setup-scripts/createExplicitUsers.php'); parent::init(); - $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection()); + $this->mapping = new UserMapping(Server::get(IDBConnection::class)); $this->mapping->clear(); $this->access->setUserMapper($this->mapping); - $userBackend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class)); + $userBackend = new User_LDAP($this->access, Server::get(\OCP\Notification\IManager::class), Server::get(UserPluginManager::class), Server::get(LoggerInterface::class), Server::get(DeletedUsersIndex::class)); \OC_User::useBackend($userBackend); } @@ -54,7 +56,7 @@ protected function case1() { $username = 'alice1337'; $dn = 'uid=alice,ou=Users,' . $this->base; $this->prepareUser($dn, $username); - $displayName = \OC::$server->getUserManager()->get($username)->getDisplayName(); + $displayName = Server::get(\OCP\User\IManager::class)->get($username)->getDisplayName(); return str_contains($displayName, '(Alice@example.com)'); } @@ -71,7 +73,7 @@ protected function case2() { $username = 'boris23421'; $dn = 'uid=boris,ou=Users,' . $this->base; $this->prepareUser($dn, $username); - $displayName = \OC::$server->getUserManager()->get($username)->getDisplayName(); + $displayName = Server::get(\OCP\User\IManager::class)->get($username)->getDisplayName(); return !str_contains($displayName, '(Boris@example.com)'); } diff --git a/apps/user_ldap/tests/LDAPProviderTest.php b/apps/user_ldap/tests/LDAPProviderTest.php index 5888c6624f305..9b0830ae51330 100644 --- a/apps/user_ldap/tests/LDAPProviderTest.php +++ b/apps/user_ldap/tests/LDAPProviderTest.php @@ -18,7 +18,9 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\ICacheFactory; use OCP\IConfig; +use OCP\IDBConnection; use OCP\IServerContainer; +use OCP\Server; use Psr\Log\LoggerInterface; /** @@ -204,7 +206,7 @@ public function testDNasBaseParameter(): void { $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); + $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals( @@ -220,7 +222,7 @@ public function testSanitizeDN(): void { $server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock()); - $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()); + $helper = new Helper(Server::get(IConfig::class), Server::get(IDBConnection::class)); $ldapProvider = $this->getLDAPProvider($server); $this->assertEquals( diff --git a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php index b95856a0f4c09..f1e9b1b67bc95 100644 --- a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php +++ b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php @@ -9,6 +9,7 @@ use OCA\User_LDAP\Mapping\AbstractMapping; use OCP\IDBConnection; +use OCP\Server; abstract class AbstractMappingTest extends \Test\TestCase { abstract public function getMapper(IDBConnection $dbMock); @@ -70,7 +71,7 @@ protected function mapEntries($mapper, $data) { * users or groups */ private function initTest() { - $dbc = \OC::$server->getDatabaseConnection(); + $dbc = Server::get(IDBConnection::class); $mapper = $this->getMapper($dbc); $data = $this->getTestData(); // make sure DB is pristine, then fill it with test entries diff --git a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php index 0e77f5023d561..64e443a064fe3 100644 --- a/apps/user_ldap/tests/User/DeletedUsersIndexTest.php +++ b/apps/user_ldap/tests/User/DeletedUsersIndexTest.php @@ -9,6 +9,7 @@ use OCA\User_LDAP\User\DeletedUsersIndex; use OCP\IConfig; use OCP\IDBConnection; +use OCP\Server; use OCP\Share\IManager; /** @@ -37,8 +38,8 @@ protected function setUp(): void { parent::setUp(); // no mocks for those as tests go against DB - $this->config = \OC::$server->getConfig(); - $this->db = \OC::$server->getDatabaseConnection(); + $this->config = Server::get(IConfig::class); + $this->db = Server::get(IDBConnection::class); // ensure a clean database $this->config->deleteAppFromAllUsers('user_ldap'); diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index 5b01b25109f3d..870b9161715be 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -20,8 +20,10 @@ use OCA\User_LDAP\User_LDAP as UserLDAP; use OCA\User_LDAP\UserPluginManager; use OCP\HintException; +use OCP\IConfig; use OCP\IUser; use OCP\Notification\IManager as INotificationManager; +use OCP\Server; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -57,7 +59,7 @@ protected function setUp(): void { parent::setUp(); \OC_User::clearBackends(); - \OC::$server->getGroupManager()->clearBackends(); + Server::get(\OCP\Group\IManager::class)->clearBackends(); $this->connection = $this->createMock(Connection::class); $this->userManager = $this->createMock(Manager::class); @@ -236,7 +238,7 @@ public function testCheckPasswordPublicAPI(): void { $backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex); \OC_User::useBackend($backend); - $user = \OC::$server->getUserManager()->checkPassword('roland', 'dt19'); + $user = Server::get(\OCP\User\IManager::class)->checkPassword('roland', 'dt19'); $result = false; if ($user !== false) { $result = $user->getUID(); @@ -249,7 +251,7 @@ public function testCheckPasswordPublicAPIWrongPassword(): void { $backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex); \OC_User::useBackend($backend); - $user = \OC::$server->getUserManager()->checkPassword('roland', 'wrong'); + $user = Server::get(\OCP\User\IManager::class)->checkPassword('roland', 'wrong'); $result = false; if ($user !== false) { $result = $user->getUID(); @@ -262,7 +264,7 @@ public function testCheckPasswordPublicAPIWrongUser(): void { $backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex); \OC_User::useBackend($backend); - $user = \OC::$server->getUserManager()->checkPassword('mallory', 'evil'); + $user = Server::get(\OCP\User\IManager::class)->checkPassword('mallory', 'evil'); $result = false; if ($user !== false) { $result = $user->getUID(); @@ -436,7 +438,7 @@ public function testGetUsersSearchEmptyResult(): void { } private function getUsers($search = '', $limit = null, $offset = null) { - $users = \OC::$server->getUserManager()->search($search, $limit, $offset); + $users = Server::get(\OCP\User\IManager::class)->search($search, $limit, $offset); $uids = array_map(function (IUser $user) { return $user->getUID(); }, $users); @@ -583,7 +585,7 @@ public function testUserExistsPublicAPI(): void { ->willReturn($this->createMock(UserMapping::class)); //test for existing user - $result = \OC::$server->getUserManager()->userExists('gunslinger'); + $result = Server::get(\OCP\User\IManager::class)->userExists('gunslinger'); $this->assertTrue($result); } @@ -653,7 +655,7 @@ public function testGetHomeRelative(): void { $backend = new UserLDAP($this->access, $this->notificationManager, $this->pluginManager, $this->logger, $this->deletedUsersIndex); $this->prepareMockForUserExists(); - $dataDir = \OC::$server->getConfig()->getSystemValue( + $dataDir = Server::get(IConfig::class)->getSystemValue( 'datadirectory', \OC::$SERVERROOT . '/data'); $this->connection->expects($this->any()) @@ -1000,11 +1002,11 @@ public function testGetDisplayNamePublicAPI(): void { }); //with displayName - $result = \OC::$server->getUserManager()->get('gunslinger')?->getDisplayName(); + $result = Server::get(\OCP\User\IManager::class)->get('gunslinger')?->getDisplayName(); $this->assertEquals('Roland Deschain', $result); //empty displayname retrieved - $result = \OC::$server->getUserManager()->get('newyorker') === null ? 'newyorker' : \OC::$server->getUserManager()->get('newyorker')->getDisplayName(); + $result = Server::get(\OCP\User\IManager::class)->get('newyorker') === null ? 'newyorker' : Server::get(\OCP\User\IManager::class)->get('newyorker')->getDisplayName(); $this->assertEquals('newyorker', $result); } diff --git a/apps/workflowengine/lib/BackgroundJobs/Rotate.php b/apps/workflowengine/lib/BackgroundJobs/Rotate.php index fd3c76c524e1e..66ac19f425a96 100644 --- a/apps/workflowengine/lib/BackgroundJobs/Rotate.php +++ b/apps/workflowengine/lib/BackgroundJobs/Rotate.php @@ -8,7 +8,9 @@ use OCA\WorkflowEngine\AppInfo\Application; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; +use OCP\IConfig; use OCP\Log\RotationTrait; +use OCP\Server; class Rotate extends TimedJob { use RotationTrait; @@ -19,7 +21,7 @@ public function __construct(ITimeFactory $time) { } protected function run($argument) { - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/flow.log'; $this->filePath = trim((string)$config->getAppValue(Application::APP_ID, 'logfile', $default)); diff --git a/apps/workflowengine/tests/ManagerTest.php b/apps/workflowengine/tests/ManagerTest.php index 610a7c60f1e71..174c79cc3d3c7 100644 --- a/apps/workflowengine/tests/ManagerTest.php +++ b/apps/workflowengine/tests/ManagerTest.php @@ -24,6 +24,7 @@ use OCP\IURLGenerator; use OCP\IUserManager; use OCP\IUserSession; +use OCP\Server; use OCP\SystemTag\ISystemTagManager; use OCP\WorkflowEngine\Events\RegisterEntitiesEvent; use OCP\WorkflowEngine\ICheck; @@ -64,7 +65,7 @@ class ManagerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->db = \OC::$server->getDatabaseConnection(); + $this->db = Server::get(IDBConnection::class); $this->container = $this->createMock(IServerContainer::class); /** @var IL10N|MockObject $l */ $this->l = $this->createMock(IL10N::class); @@ -80,7 +81,7 @@ protected function setUp(): void { $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->manager = new Manager( - \OC::$server->getDatabaseConnection(), + Server::get(IDBConnection::class), $this->container, $this->l, $this->logger,