diff options
author | Faraz Samapoor <f.samapoor@gmail.com> | 2023-07-04 22:13:32 +0330 |
---|---|---|
committer | Faraz Samapoor <fsa@adlas.at> | 2023-07-12 18:29:32 +0330 |
commit | 5d242aa2f86f003bb5f0400188a440d2d5eea68f (patch) | |
tree | 514599caddf25a0b6d8414ce510f7b4c41f03b62 /apps/files/lib/Command/Object/ObjectUtil.php | |
parent | 706c141fffce928d344fe2f039da549fad065393 (diff) | |
download | nextcloud-server-5d242aa2f86f003bb5f0400188a440d2d5eea68f.tar.gz nextcloud-server-5d242aa2f86f003bb5f0400188a440d2d5eea68f.zip |
Refactors files app commands.
To improve code readability.
Signed-off-by: Faraz Samapoor <fsa@adlas.at>
Diffstat (limited to 'apps/files/lib/Command/Object/ObjectUtil.php')
-rw-r--r-- | apps/files/lib/Command/Object/ObjectUtil.php | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/apps/files/lib/Command/Object/ObjectUtil.php b/apps/files/lib/Command/Object/ObjectUtil.php index b7359dfa193..5d278cdf668 100644 --- a/apps/files/lib/Command/Object/ObjectUtil.php +++ b/apps/files/lib/Command/Object/ObjectUtil.php @@ -30,12 +30,10 @@ use OCP\IDBConnection; use Symfony\Component\Console\Output\OutputInterface; class ObjectUtil { - private IConfig $config; - private IDBConnection $connection; - - public function __construct(IConfig $config, IDBConnection $connection) { - $this->config = $config; - $this->connection = $connection; + public function __construct( + private IConfig $config, + private IDBConnection $connection, + ) { } private function getObjectStoreConfig(): ?array { @@ -50,9 +48,9 @@ class ObjectUtil { $config['multibucket'] = false; } return $config; - } else { - return null; } + + return null; } public function getObjectStore(?string $bucket, OutputInterface $output): ?IObjectStore { @@ -91,20 +89,21 @@ class ObjectUtil { * Check if an object is referenced in the database */ public function objectExistsInDb(string $object): int|false { - if (str_starts_with($object, 'urn:oid:')) { - $fileId = (int)substr($object, strlen('urn:oid:')); - $query = $this->connection->getQueryBuilder(); - $query->select('fileid') - ->from('filecache') - ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); - $result = $query->executeQuery(); - if ($result->fetchOne() !== false) { - return $fileId; - } else { - return false; - } - } else { + if (!str_starts_with($object, 'urn:oid:')) { return false; } + + $fileId = (int)substr($object, strlen('urn:oid:')); + $query = $this->connection->getQueryBuilder(); + $query->select('fileid') + ->from('filecache') + ->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); + $result = $query->executeQuery(); + + if ($result->fetchOne() === false) { + return false; + } + + return $fileId; } } |