aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Command/Object
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/lib/Command/Object')
-rw-r--r--apps/files/lib/Command/Object/Delete.php9
-rw-r--r--apps/files/lib/Command/Object/Get.php41
-rw-r--r--apps/files/lib/Command/Object/ObjectUtil.php41
-rw-r--r--apps/files/lib/Command/Object/Put.php14
4 files changed, 50 insertions, 55 deletions
diff --git a/apps/files/lib/Command/Object/Delete.php b/apps/files/lib/Command/Object/Delete.php
index 9742778e271..5000eeb6ee5 100644
--- a/apps/files/lib/Command/Object/Delete.php
+++ b/apps/files/lib/Command/Object/Delete.php
@@ -34,10 +34,9 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
class Delete extends Command {
- private ObjectUtil $objectUtils;
-
- public function __construct(ObjectUtil $objectUtils) {
- $this->objectUtils = $objectUtils;
+ public function __construct(
+ private ObjectUtil $objectUtils,
+ ) {
parent::__construct();
}
@@ -73,6 +72,6 @@ class Delete extends Command {
if ($helper->ask($input, $output, $question)) {
$objectStore->deleteObject($object);
}
- return 0;
+ return self::SUCCESS;
}
}
diff --git a/apps/files/lib/Command/Object/Get.php b/apps/files/lib/Command/Object/Get.php
index c07a64b20e2..cad1f3d98ac 100644
--- a/apps/files/lib/Command/Object/Get.php
+++ b/apps/files/lib/Command/Object/Get.php
@@ -31,10 +31,9 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Get extends Command {
- private ObjectUtil $objectUtils;
-
- public function __construct(ObjectUtil $objectUtils) {
- $this->objectUtils = $objectUtils;
+ public function __construct(
+ private ObjectUtil $objectUtils,
+ ) {
parent::__construct();
}
@@ -52,29 +51,29 @@ class Get extends Command {
$outputName = $input->getArgument('output');
$objectStore = $this->objectUtils->getObjectStore($input->getOption("bucket"), $output);
if (!$objectStore) {
- return 1;
+ return self::FAILURE;
}
if (!$objectStore->objectExists($object)) {
$output->writeln("<error>Object $object does not exist</error>");
- return 1;
- } else {
- try {
- $source = $objectStore->readObject($object);
- } catch (\Exception $e) {
- $msg = $e->getMessage();
- $output->writeln("<error>Failed to read $object from object store: $msg</error>");
- return 1;
- }
- $target = $outputName === '-' ? STDOUT : fopen($outputName, 'w');
- if (!$target) {
- $output->writeln("<error>Failed to open $outputName for writing</error>");
- return 1;
- }
+ return self::FAILURE;
+ }
- stream_copy_to_stream($source, $target);
- return 0;
+ try {
+ $source = $objectStore->readObject($object);
+ } catch (\Exception $e) {
+ $msg = $e->getMessage();
+ $output->writeln("<error>Failed to read $object from object store: $msg</error>");
+ return self::FAILURE;
}
+ $target = $outputName === '-' ? STDOUT : fopen($outputName, 'w');
+ if (!$target) {
+ $output->writeln("<error>Failed to open $outputName for writing</error>");
+ return self::FAILURE;
+ }
+
+ stream_copy_to_stream($source, $target);
+ return self::SUCCESS;
}
}
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;
}
}
diff --git a/apps/files/lib/Command/Object/Put.php b/apps/files/lib/Command/Object/Put.php
index dabc2b1ffc3..852d7c2225e 100644
--- a/apps/files/lib/Command/Object/Put.php
+++ b/apps/files/lib/Command/Object/Put.php
@@ -33,12 +33,10 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
class Put extends Command {
- private ObjectUtil $objectUtils;
- private IMimeTypeDetector $mimeTypeDetector;
-
- public function __construct(ObjectUtil $objectUtils, IMimeTypeDetector $mimeTypeDetector) {
- $this->objectUtils = $objectUtils;
- $this->mimeTypeDetector = $mimeTypeDetector;
+ public function __construct(
+ private ObjectUtil $objectUtils,
+ private IMimeTypeDetector $mimeTypeDetector,
+ ) {
parent::__construct();
}
@@ -75,10 +73,10 @@ class Put extends Command {
$source = $inputName === '-' ? STDIN : fopen($inputName, 'r');
if (!$source) {
$output->writeln("<error>Failed to open $inputName</error>");
- return 1;
+ return self::FAILURE;
}
$objectStore->writeObject($object, $source, $this->mimeTypeDetector->detectPath($inputName));
- return 0;
+ return self::SUCCESS;
}
}