From 29d70d6b7571e7602c5e6854822d7345760b4b90 Mon Sep 17 00:00:00 2001 From: Andrew Summers <18727110+summersab@users.noreply.github.com> Date: Tue, 29 Aug 2023 17:28:27 -0500 Subject: [PATCH 1/7] Refactor `OC\Server::getContactsManager` Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com> --- lib/private/Share/Share.php | 3 ++- lib/public/Contacts/IManager.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 8d14f293e5a1e..86ef41a1c5c20 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -36,6 +36,7 @@ namespace OC\Share; use OCA\Files_Sharing\ShareBackend\File; +use OCP\Contacts\IManager as IContactsManager; use OCP\DB\Exception; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; @@ -596,7 +597,7 @@ public static function getItems($itemType, ?string $item = null, ?int $shareType $row['share_with_displayname'] = $shareWithUser === null ? $row['share_with'] : $shareWithUser->getDisplayName(); } elseif (isset($row['share_with']) && $row['share_with'] != '' && $row['share_type'] === IShare::TYPE_REMOTE) { - $addressBookEntries = \OC::$server->getContactsManager()->search($row['share_with'], ['CLOUD'], [ + $addressBookEntries = \OC::$server->get(IContactsManager::class)->search($row['share_with'], ['CLOUD'], [ 'limit' => 1, 'enumeration' => false, 'fullmatch' => false, diff --git a/lib/public/Contacts/IManager.php b/lib/public/Contacts/IManager.php index 6ca349b95d0ca..fce09a19a33c6 100644 --- a/lib/public/Contacts/IManager.php +++ b/lib/public/Contacts/IManager.php @@ -56,7 +56,7 @@ interface IManager { * Following function shows how to search for contacts for the name and the email address. * * public static function getMatchingRecipient($term) { - * $cm = \OC::$server->getContactsManager(); + * $cm = \OC::$server->get(\OCP\Contacts\IManager::class); * // The API is not active -> nothing to do * if (!$cm->isEnabled()) { * return array(); From 453602958966edc0d54b056e031f0acf6f247f0e Mon Sep 17 00:00:00 2001 From: Andrew Summers <18727110+summersab@users.noreply.github.com> Date: Tue, 29 Aug 2023 18:13:44 -0500 Subject: [PATCH 2/7] Refactor `OC\Server::getHTTPClientService` Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com> --- build/integration/features/bootstrap/RemoteContext.php | 5 +++-- lib/private/Files/Storage/DAV.php | 2 +- lib/private/Share20/ProviderFactory.php | 3 ++- lib/private/legacy/OC_Util.php | 5 +++-- tests/lib/InstallerTest.php | 6 +++--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/build/integration/features/bootstrap/RemoteContext.php b/build/integration/features/bootstrap/RemoteContext.php index a3e5e1b500745..1f5d837084fb6 100644 --- a/build/integration/features/bootstrap/RemoteContext.php +++ b/build/integration/features/bootstrap/RemoteContext.php @@ -23,6 +23,7 @@ * */ use Behat\Behat\Context\Context; +use OCP\Http\Client\IClientService; use PHPUnit\Framework\Assert; require __DIR__ . '/../../vendor/autoload.php'; @@ -50,7 +51,7 @@ public function __construct($remote) { } protected function getApiClient() { - return new \OC\Remote\Api\OCS($this->remoteInstance, $this->credentails, \OC::$server->getHTTPClientService()); + return new \OC\Remote\Api\OCS($this->remoteInstance, $this->credentails, \OC::$server->get(IClientService::class)); } /** @@ -66,7 +67,7 @@ public function selectRemoteInstance($remoteServer) { } $this->lastException = null; try { - $this->remoteInstance = new \OC\Remote\Instance($baseUri, \OC::$server->getMemCacheFactory()->createLocal(), \OC::$server->getHTTPClientService()); + $this->remoteInstance = new \OC\Remote\Instance($baseUri, \OC::$server->getMemCacheFactory()->createLocal(), \OC::$server->get(IClientService::class)); // trigger the status request $this->remoteInstance->getProtocol(); } catch (\Exception $e) { diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 70f22a1703400..abb2753775993 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -116,7 +116,7 @@ class DAV extends Common { */ public function __construct($params) { $this->statCache = new ArrayCache(); - $this->httpClientService = \OC::$server->getHTTPClientService(); + $this->httpClientService = \OC::$server->get(IClientService::class); if (isset($params['host']) && isset($params['user']) && isset($params['password'])) { $host = $params['host']; //remove leading http[s], will be generated in createBaseUri() diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 8c01d6609155c..2e02c4d597a7f 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -43,6 +43,7 @@ use OCA\Talk\Share\RoomShareProvider; use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Http\Client\IClientService; use OCP\IServerContainer; use OCP\Share\IManager; use OCP\Share\IProviderFactory; @@ -137,7 +138,7 @@ protected function federatedShareProvider() { ); $notifications = new Notifications( $addressHandler, - $this->serverContainer->getHTTPClientService(), + $this->serverContainer->get(IClientService::class), $this->serverContainer->query(\OCP\OCS\IDiscoveryService::class), $this->serverContainer->getJobList(), \OC::$server->getCloudFederationProviderManager(), diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 9d62c46137e61..9d06a4d2e618c 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -67,6 +67,7 @@ use bantu\IniGetWrapper\IniGetWrapper; use OC\Files\SetupManager; use OCP\Files\Template\ITemplateManager; +use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\IGroupManager; use OCP\IURLGenerator; @@ -942,7 +943,7 @@ public function isHtaccessWorking(\OCP\IConfig $config) { // accessing the file via http $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); try { - $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); + $content = \OC::$server->get(IClientService::class)->newClient()->get($url)->getBody(); } catch (\Exception $e) { $content = false; } @@ -954,7 +955,7 @@ public function isHtaccessWorking(\OCP\IConfig $config) { } try { - $fallbackContent = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); + $fallbackContent = \OC::$server->get(IClientService::class)->newClient()->get($url)->getBody(); } catch (\Exception $e) { $fallbackContent = false; } diff --git a/tests/lib/InstallerTest.php b/tests/lib/InstallerTest.php index 60c8ac1cc947a..0497076627ce3 100644 --- a/tests/lib/InstallerTest.php +++ b/tests/lib/InstallerTest.php @@ -52,7 +52,7 @@ protected function setUp(): void { $config->setSystemValue('appstoreenabled', true); $installer = new Installer( \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), + \OC::$server->get(IClientService::class), \OC::$server->getTempManager(), \OC::$server->get(LoggerInterface::class), $config, @@ -75,7 +75,7 @@ protected function getInstaller() { protected function tearDown(): void { $installer = new Installer( \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), + \OC::$server->get(IClientService::class), \OC::$server->getTempManager(), \OC::$server->get(LoggerInterface::class), \OC::$server->getConfig(), @@ -99,7 +99,7 @@ public function testInstallApp() { // Install app $installer = new Installer( \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), + \OC::$server->get(IClientService::class), \OC::$server->getTempManager(), \OC::$server->get(LoggerInterface::class), \OC::$server->getConfig(), From 7292a8d8fe7e4cf8667194f4af587f6923a0f884 Mon Sep 17 00:00:00 2001 From: Andrew Summers <18727110+summersab@users.noreply.github.com> Date: Tue, 29 Aug 2023 18:19:21 -0500 Subject: [PATCH 3/7] Refactor `OC\Server::getMailer` Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com> --- lib/private/Mail/Mailer.php | 2 +- lib/private/Share20/ProviderFactory.php | 5 +++-- lib/public/Mail/IMailer.php | 2 +- lib/public/Util.php | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index 9b7b3cf117b03..e4c3467f854d0 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -65,7 +65,7 @@ * * Example usage: * - * $mailer = \OC::$server->getMailer(); + * $mailer = \OC::$server->get(\OCP\Mail\IMailer::class); * $message = $mailer->createMessage(); * $message->setSubject('Your Subject'); * $message->setFrom(array('cloud@domain.org' => 'ownCloud Notifier')); diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 8c01d6609155c..ff6d9b0eacd75 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -44,6 +44,7 @@ use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; use OCP\IServerContainer; +use OCP\Mail\IMailer; use OCP\Share\IManager; use OCP\Share\IProviderFactory; use OCP\Share\IShare; @@ -100,7 +101,7 @@ protected function defaultShareProvider() { $this->serverContainer->getUserManager(), $this->serverContainer->getGroupManager(), $this->serverContainer->getLazyRootFolder(), - $this->serverContainer->getMailer(), + $this->serverContainer->get(IMailer::class), $this->serverContainer->query(Defaults::class), $this->serverContainer->getL10NFactory(), $this->serverContainer->getURLGenerator(), @@ -193,7 +194,7 @@ protected function getShareByMailProvider() { $this->serverContainer->getLazyRootFolder(), $this->serverContainer->getL10N('sharebymail'), $this->serverContainer->getLogger(), - $this->serverContainer->getMailer(), + $this->serverContainer->get(IMailer::class), $this->serverContainer->getURLGenerator(), $this->serverContainer->getActivityManager(), $settingsManager, diff --git a/lib/public/Mail/IMailer.php b/lib/public/Mail/IMailer.php index 94044f7c72093..8f4410bb3d5d1 100644 --- a/lib/public/Mail/IMailer.php +++ b/lib/public/Mail/IMailer.php @@ -33,7 +33,7 @@ * * Example usage: * - * $mailer = \OC::$server->getMailer(); + * $mailer = \OC::$server->get(\OCP\Mail\IMailer::class); * $message = $mailer->createMessage(); * $message->setSubject('Your Subject'); * $message->setFrom(['cloud@domain.org' => 'Nextcloud Notifier']); diff --git a/lib/public/Util.php b/lib/public/Util.php index bff8038b3dda5..12f76104a3fdd 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -48,6 +48,7 @@ use OC\AppScriptDependency; use OC\AppScriptSort; +use OCP\Mail\IMailer; use bantu\IniGetWrapper\IniGetWrapper; use Psr\Container\ContainerExceptionInterface; @@ -326,7 +327,7 @@ public static function getDefaultEmailAddress(string $user_part): string { $host_name = $config->getSystemValueString('mail_domain', $host_name); $defaultEmailAddress = $user_part.'@'.$host_name; - $mailer = \OC::$server->getMailer(); + $mailer = \OC::$server->get(IMailer::class); if ($mailer->validateMailAddress($defaultEmailAddress)) { return $defaultEmailAddress; } From 7a887b451396fbeed907ea93e2c0714610bee4df Mon Sep 17 00:00:00 2001 From: Andrew Summers <18727110+summersab@users.noreply.github.com> Date: Fri, 1 Sep 2023 16:11:24 -0500 Subject: [PATCH 4/7] Refactor `OC\Server::getAvatarManager` in dav app Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com> --- apps/dav/lib/Avatars/RootCollection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/dav/lib/Avatars/RootCollection.php b/apps/dav/lib/Avatars/RootCollection.php index 1f05274944c1c..d7cdb92c6be7d 100644 --- a/apps/dav/lib/Avatars/RootCollection.php +++ b/apps/dav/lib/Avatars/RootCollection.php @@ -6,6 +6,7 @@ */ namespace OCA\DAV\Avatars; +use OCP\IAvatarManager; use Sabre\DAVACL\AbstractPrincipalCollection; class RootCollection extends AbstractPrincipalCollection { @@ -21,7 +22,7 @@ class RootCollection extends AbstractPrincipalCollection { * @return AvatarHome */ public function getChildForPrincipal(array $principalInfo) { - $avatarManager = \OC::$server->getAvatarManager(); + $avatarManager = \OC::$server->get(IAvatarManager::class); return new AvatarHome($principalInfo, $avatarManager); } From d62eb333a7da9b3295dfa5b74a25454e020dbcd1 Mon Sep 17 00:00:00 2001 From: Andrew Summers <18727110+summersab@users.noreply.github.com> Date: Fri, 1 Sep 2023 16:07:49 -0500 Subject: [PATCH 5/7] Refactor `OC\Server::getAvatarManager` in user_ldap app Refactor `OC\Server::getAvatarManager` in user_ldap app (missed one) Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com> --- apps/user_ldap/lib/Jobs/Sync.php | 2 +- .../tests/Integration/AbstractIntegrationTest.php | 3 ++- .../Lib/User/IntegrationTestUserAvatar.php | 11 ++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/user_ldap/lib/Jobs/Sync.php b/apps/user_ldap/lib/Jobs/Sync.php index 16371df156285..0f9e8e3be93b6 100644 --- a/apps/user_ldap/lib/Jobs/Sync.php +++ b/apps/user_ldap/lib/Jobs/Sync.php @@ -319,7 +319,7 @@ public function setArgument($argument) { if (isset($argument['avatarManager'])) { $this->avatarManager = $argument['avatarManager']; } else { - $this->avatarManager = \OC::$server->getAvatarManager(); + $this->avatarManager = \OC::$server->get(IAvatarManager::class); } if (isset($argument['dbc'])) { diff --git a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php index 5ec04484bef8d..7cc1ab62a7de0 100644 --- a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php +++ b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php @@ -35,6 +35,7 @@ use OCA\User_LDAP\LDAP; use OCA\User_LDAP\User\Manager; use OCA\User_LDAP\UserPluginManager; +use OCP\IAvatarManager; use OCP\Share\IManager; use Psr\Log\LoggerInterface; @@ -124,7 +125,7 @@ protected function initUserManager() { \OC::$server->getConfig(), new FilesystemHelper(), \OC::$server->get(LoggerInterface::class), - \OC::$server->getAvatarManager(), + \OC::$server->get(IAvatarManager::class), new \OCP\Image(), \OC::$server->getUserManager(), \OC::$server->getNotificationManager(), diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php index c5b7f73bbcc0d..d6fb512010b46 100644 --- a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php +++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php @@ -35,6 +35,7 @@ use OCA\User_LDAP\User\User; use OCA\User_LDAP\User_LDAP; use OCA\User_LDAP\UserPluginManager; +use OCP\IAvatarManager; use OCP\Image; use Psr\Log\LoggerInterface; @@ -78,8 +79,8 @@ private function execFetchTest($dn, $username, $image) { \OC_Util::setupFS($username); \OC::$server->getUserFolder($username); \OC::$server->getConfig()->deleteUserValue($username, 'user_ldap', User::USER_PREFKEY_LASTREFRESH); - if (\OC::$server->getAvatarManager()->getAvatar($username)->exists()) { - \OC::$server->getAvatarManager()->getAvatar($username)->remove(); + if (\OC::$server->get(IAvatarManager::class)->getAvatar($username)->exists()) { + \OC::$server->get(IAvatarManager::class)->getAvatar($username)->remove(); } // finally attempt to get the avatar set @@ -99,7 +100,7 @@ protected function case1() { $this->execFetchTest($dn, $username, $image); - return \OC::$server->getAvatarManager()->getAvatar($username)->exists(); + return \OC::$server->get(IAvatarManager::class)->getAvatar($username)->exists(); } /** @@ -116,7 +117,7 @@ protected function case2() { $this->execFetchTest($dn, $username, $image); - return !\OC::$server->getAvatarManager()->getAvatar($username)->exists(); + return !\OC::$server->get(IAvatarManager::class)->getAvatar($username)->exists(); } /** @@ -136,7 +137,7 @@ protected function initUserManager() { \OC::$server->getConfig(), new FilesystemHelper(), \OC::$server->get(LoggerInterface::class), - \OC::$server->getAvatarManager(), + \OC::$server->get(IAvatarManager::class), new Image(), \OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), From 98666298c8d1ba8605c43ff70034073fe993c9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Thu, 30 May 2024 14:27:44 +0200 Subject: [PATCH 6/7] chore: fix duplicate php import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- lib/public/Util.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/public/Util.php b/lib/public/Util.php index 2ccc2105ab5db..885e2facc53ee 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -14,7 +14,6 @@ use OC\AppScriptDependency; use OC\AppScriptSort; use OCP\Mail\IMailer; -use bantu\IniGetWrapper\IniGetWrapper; use OCP\Share\IManager; use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; From 3aab6b23271fdbc8263228b599cc6e78af921b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Thu, 30 May 2024 15:01:15 +0200 Subject: [PATCH 7/7] chore: adjust php comment usage hint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: John Molakvoæ --- lib/public/Contacts/IManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/public/Contacts/IManager.php b/lib/public/Contacts/IManager.php index c94947e2a35c8..f19e72e076335 100644 --- a/lib/public/Contacts/IManager.php +++ b/lib/public/Contacts/IManager.php @@ -35,7 +35,7 @@ interface IManager { * Following function shows how to search for contacts for the name and the email address. * * public static function getMatchingRecipient($term) { - * $cm = \OC::$server->get(\OCP\Contacts\IManager::class); + * $cm = \OCP\Server::get(\OCP\Contacts\IManager::class); * // The API is not active -> nothing to do * if (!$cm->isEnabled()) { * return array();