Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(storage): refactor some code portions #47731

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 16 additions & 30 deletions lib/private/Files/Storage/DAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OCP\Http\Client\IClientService;
use OCP\ICertificateManager;
use OCP\IConfig;
use OCP\Server;
use OCP\Util;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -86,7 +87,7 @@ class DAV extends Common {
*/
public function __construct($params) {
$this->statCache = new ArrayCache();
$this->httpClientService = \OC::$server->get(IClientService::class);
$this->httpClientService = 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()
Expand Down Expand Up @@ -120,10 +121,10 @@ public function __construct($params) {
} else {
throw new \Exception('Invalid webdav storage configuration');
}
$this->logger = \OC::$server->get(LoggerInterface::class);
$this->eventLogger = \OC::$server->get(IEventLogger::class);
$this->logger = Server::get(LoggerInterface::class);
$this->eventLogger = Server::get(IEventLogger::class);
// This timeout value will be used for the download and upload of files
$this->timeout = \OC::$server->get(IConfig::class)->getSystemValueInt('davstorage.request_timeout', 30);
$this->timeout = Server::get(IConfig::class)->getSystemValueInt('davstorage.request_timeout', 30);
$this->mimeTypeDetector = \OC::$server->getMimeTypeDetector();
}

Expand All @@ -142,7 +143,7 @@ protected function init() {
$settings['authType'] = $this->authType;
}

$proxy = \OC::$server->getConfig()->getSystemValueString('proxy', '');
$proxy = Server::get(IConfig::class)->getSystemValueString('proxy', '');
if ($proxy !== '') {
$settings['proxy'] = $proxy;
}
Expand Down Expand Up @@ -287,7 +288,7 @@ public function filetype($path) {
/** @var ResourceType[] $response */
$responseType = $response['{DAV:}resourcetype']->getValue();
}
return (count($responseType) > 0 and $responseType[0] == '{DAV:}collection') ? 'dir' : 'file';
return (count($responseType) > 0 && $responseType[0] == '{DAV:}collection') ? 'dir' : 'file';
} catch (\Exception $e) {
$this->convertException($e, $path);
}
Expand Down Expand Up @@ -352,7 +353,7 @@ public function fopen($path, $mode) {
if ($response->getStatusCode() === Http::STATUS_LOCKED) {
throw new \OCP\Lock\LockedException($path);
} else {
\OC::$server->get(LoggerInterface::class)->error('Guzzle get returned status code ' . $response->getStatusCode(), ['app' => 'webdav client']);
Server::get(LoggerInterface::class)->error('Guzzle get returned status code ' . $response->getStatusCode(), ['app' => 'webdav client']);
}
}

Expand Down Expand Up @@ -380,7 +381,7 @@ public function fopen($path, $mode) {
if (!$this->isUpdatable($path)) {
return false;
}
if ($mode === 'w' or $mode === 'w+') {
if ($mode === 'w' || $mode === 'w+') {
$tmpFile = $tempManager->getTemporaryFile($ext);
} else {
$tmpFile = $this->getCachedFile($path);
Expand Down Expand Up @@ -586,7 +587,7 @@ private function getMetaFromPropfind(string $path, array $response): array {
/** @var ResourceType[] $response */
$responseType = $response['{DAV:}resourcetype']->getValue();
}
$type = (count($responseType) > 0 and $responseType[0] == '{DAV:}collection') ? 'dir' : 'file';
$type = (count($responseType) > 0 && $responseType[0] == '{DAV:}collection') ? 'dir' : 'file';
if ($type === 'dir') {
$mimeType = 'httpd/unix-directory';
} elseif (isset($response['{DAV:}getcontenttype'])) {
Expand Down Expand Up @@ -625,21 +626,14 @@ private function getMetaFromPropfind(string $path, array $response): array {
/** {@inheritdoc} */
public function stat($path) {
$meta = $this->getMetaData($path);
if (!$meta) {
return false;
} else {
return $meta;
}
return $meta ?: false;

}

/** {@inheritdoc} */
public function getMimeType($path) {
$meta = $this->getMetaData($path);
if ($meta) {
return $meta['mimetype'];
} else {
return false;
}
return $meta ? $meta['mimetype'] : false;
}

/**
Expand Down Expand Up @@ -724,21 +718,13 @@ public function isDeletable($path) {
/** {@inheritdoc} */
public function getPermissions($path) {
$stat = $this->getMetaData($path);
if ($stat) {
return $stat['permissions'];
} else {
return 0;
}
return $stat ? $stat['permissions'] : 0;
}

/** {@inheritdoc} */
public function getETag($path) {
$meta = $this->getMetaData($path);
if ($meta) {
return $meta['etag'];
} else {
return null;
}
return $meta ? $meta['etag'] : null;
}

/**
Expand Down Expand Up @@ -838,7 +824,7 @@ public function hasUpdated($path, $time) {
* @throws ForbiddenException if the action is not allowed
*/
protected function convertException(Exception $e, $path = '') {
\OC::$server->get(LoggerInterface::class)->debug($e->getMessage(), ['app' => 'files_external', 'exception' => $e]);
Server::get(LoggerInterface::class)->debug($e->getMessage(), ['app' => 'files_external', 'exception' => $e]);
if ($e instanceof ClientHttpException) {
if ($e->getHttpStatus() === Http::STATUS_LOCKED) {
throw new \OCP\Lock\LockedException($path);
Expand Down
Loading