diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2025-02-03 15:34:01 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2025-02-13 11:46:42 +0100 |
commit | 64863c9d4631c42d4ce3997d7033bca8f06ca66a (patch) | |
tree | b7e88154522cd827da8163719aeb91b51d5640cd /apps/files_external/lib | |
parent | 007335dadfcda18330bb853a73bf451ed41c8254 (diff) | |
download | nextcloud-server-64863c9d4631c42d4ce3997d7033bca8f06ca66a.tar.gz nextcloud-server-64863c9d4631c42d4ce3997d7033bca8f06ca66a.zip |
chore: Apply new rector configuration to apps folder
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r-- | apps/files_external/lib/Lib/Storage/AmazonS3.php | 5 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/FTP.php | 11 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/SFTP.php | 3 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/SMB.php | 6 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/Swift.php | 29 | ||||
-rw-r--r-- | apps/files_external/lib/MountConfig.php | 11 | ||||
-rw-r--r-- | apps/files_external/lib/Service/BackendService.php | 5 | ||||
-rw-r--r-- | apps/files_external/lib/Service/LegacyStoragesService.php | 5 | ||||
-rw-r--r-- | apps/files_external/lib/Service/StoragesService.php | 5 |
9 files changed, 48 insertions, 32 deletions
diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index 1a866e8c22b..47967a3908d 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\FileInfo; use OCP\Files\IMimeTypeDetector; use OCP\ICache; use OCP\ICacheFactory; +use OCP\ITempManager; use OCP\Server; use Psr\Log\LoggerInterface; @@ -451,7 +452,7 @@ class AmazonS3 extends Common { } 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 @@ class AmazonS3 extends Common { } 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 51b269b3eb0..e23fc791297 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\Common; 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 @@ class FTP extends Common { 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 @@ class FTP extends Common { } 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 @@ class FTP extends Common { 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 @@ class FTP extends Common { 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 9907acdc469..2619e678565 100644 --- a/apps/files_external/lib/Lib/Storage/SFTP.php +++ b/apps/files_external/lib/Lib/Storage/SFTP.php @@ -16,6 +16,7 @@ use OCP\Cache\CappedMemoryCache; use OCP\Constants; use OCP\Files\FileInfo; use OCP\Files\IMimeTypeDetector; +use OCP\Server; use phpseclib\Net\SFTP\Stream; /** @@ -94,7 +95,7 @@ class SFTP extends Common { $this->knownMTimes = new CappedMemoryCache(); - $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 ef203021566..f08401f73c5 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -31,12 +31,14 @@ use OCA\Files_External\Lib\Notify\SMBNotifyHandler; 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 @@ class SMB extends Common implements INotifyStorage { 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 @@ class SMB extends Common implements INotifyStorage { 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 cb72ab8c070..a71331766d4 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\StorageAuthException; 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 @@ class Swift extends Common { } 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 @@ class Swift extends Common { // 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 @@ class Swift extends Common { // 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 @@ class Swift extends Common { $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 @@ class Swift extends Common { 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 @@ class Swift extends Common { 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 @@ class Swift extends Common { $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 @@ class Swift extends Common { 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 @@ class Swift extends Common { } 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 @@ class Swift extends Common { $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 @@ class Swift extends Common { $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 ca14275ab13..2289a5008e5 100644 --- a/apps/files_external/lib/MountConfig.php +++ b/apps/files_external/lib/MountConfig.php @@ -16,7 +16,10 @@ use OCA\Files_External\Service\UserGlobalStoragesService; 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 @@ class MountConfig { */ 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 @@ class MountConfig { 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 @@ class MountConfig { */ 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 @@ class MountConfig { */ 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 e37a0ab4649..b452b27e175 100644 --- a/apps/files_external/lib/Service/BackendService.php +++ b/apps/files_external/lib/Service/BackendService.php @@ -8,13 +8,14 @@ namespace OCA\Files_External\Service; 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 @@ class BackendService { 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 20a26a07e8b..5be1a084b66 100644 --- a/apps/files_external/lib/Service/LegacyStoragesService.php +++ b/apps/files_external/lib/Service/LegacyStoragesService.php @@ -8,6 +8,7 @@ namespace OCA\Files_External\Service; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\MountConfig; +use OCP\Server; use Psr\Log\LoggerInterface; /** @@ -124,7 +125,7 @@ abstract class LegacyStoragesService { $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 @@ abstract class LegacyStoragesService { } } 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 67de6e8b6b8..73642d85f88 100644 --- a/apps/files_external/lib/Service/StoragesService.php +++ b/apps/files_external/lib/Service/StoragesService.php @@ -19,6 +19,7 @@ use OCP\EventDispatcher\IEventDispatcher; 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 @@ abstract class StoragesService { 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, ]); |