aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Command/Object/ObjectUtil.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/lib/Command/Object/ObjectUtil.php')
-rw-r--r--apps/files/lib/Command/Object/ObjectUtil.php50
1 files changed, 28 insertions, 22 deletions
diff --git a/apps/files/lib/Command/Object/ObjectUtil.php b/apps/files/lib/Command/Object/ObjectUtil.php
index 5d278cdf668..5f053c2c42f 100644
--- a/apps/files/lib/Command/Object/ObjectUtil.php
+++ b/apps/files/lib/Command/Object/ObjectUtil.php
@@ -2,23 +2,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2023 Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files\Command\Object;
@@ -27,6 +12,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\ObjectStore\IObjectStore;
use OCP\IConfig;
use OCP\IDBConnection;
+use OCP\Util;
use Symfony\Component\Console\Output\OutputInterface;
class ObjectUtil {
@@ -56,19 +42,19 @@ class ObjectUtil {
public function getObjectStore(?string $bucket, OutputInterface $output): ?IObjectStore {
$config = $this->getObjectStoreConfig();
if (!$config) {
- $output->writeln("<error>Instance is not using primary object store</error>");
+ $output->writeln('<error>Instance is not using primary object store</error>');
return null;
}
if ($config['multibucket'] && !$bucket) {
- $output->writeln("<error>--bucket option required</error> because <info>multi bucket</info> is enabled.");
+ $output->writeln('<error>--bucket option required</error> because <info>multi bucket</info> is enabled.');
return null;
}
if (!isset($config['arguments'])) {
- throw new \Exception("no arguments configured for object store configuration");
+ throw new \Exception('no arguments configured for object store configuration');
}
if (!isset($config['class'])) {
- throw new \Exception("no class configured for object store configuration");
+ throw new \Exception('no class configured for object store configuration');
}
if ($bucket) {
@@ -80,7 +66,7 @@ class ObjectUtil {
$store = new $config['class']($config['arguments']);
if (!$store instanceof IObjectStore) {
- throw new \Exception("configured object store class is not an object store implementation");
+ throw new \Exception('configured object store class is not an object store implementation');
}
return $store;
}
@@ -106,4 +92,24 @@ class ObjectUtil {
return $fileId;
}
+
+ public function formatObjects(\Iterator $objects, bool $humanOutput): \Iterator {
+ foreach ($objects as $object) {
+ yield $this->formatObject($object, $humanOutput);
+ }
+ }
+
+ public function formatObject(array $object, bool $humanOutput): array {
+ $row = array_merge([
+ 'urn' => $object['urn'],
+ ], ($object['metadata'] ?? []));
+
+ if ($humanOutput && isset($row['size'])) {
+ $row['size'] = Util::humanFileSize($row['size']);
+ }
+ if (isset($row['mtime'])) {
+ $row['mtime'] = $row['mtime']->format(\DateTimeImmutable::ATOM);
+ }
+ return $row;
+ }
}