From c89df9726f1cc18b43df05a43fb932e6be39d5ac Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Sun, 22 Oct 2023 10:15:14 -0100 Subject: [PATCH] small improvement Signed-off-by: Maxence Lange --- core/Command/FilesMetadata/Get.php | 18 +++++++++++++----- .../FilesMetadata/FilesMetadataManager.php | 6 ++++-- .../FilesMetadata/IFilesMetadataManager.php | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/core/Command/FilesMetadata/Get.php b/core/Command/FilesMetadata/Get.php index 66cca520bc25c..cb99fbc818d61 100644 --- a/core/Command/FilesMetadata/Get.php +++ b/core/Command/FilesMetadata/Get.php @@ -26,8 +26,6 @@ namespace OC\Core\Command\FilesMetadata; -use OC\DB\ConnectionAdapter; -use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\FilesMetadata\IFilesMetadataManager; @@ -59,11 +57,17 @@ protected function configure() { 'file owner' ) ->addOption( - 'refresh', + 'as-array', '', InputOption::VALUE_NONE, - 'refresh metadata' + 'display metadata as a simple key=>value array' ) + ->addOption( + 'refresh', + '', + InputOption::VALUE_NONE, + 'refresh metadata' + ) ->addOption( 'reset', '', @@ -90,7 +94,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $metadata = $this->filesMetadataManager->getMetadata($fileId); } - $output->writeln(json_encode($metadata, JSON_PRETTY_PRINT)); + if ($input->getOption('as-array')) { + $output->writeln(json_encode($metadata->asArray(), JSON_PRETTY_PRINT)); + } else { + $output->writeln(json_encode($metadata, JSON_PRETTY_PRINT)); + } return 0; } diff --git a/lib/private/FilesMetadata/FilesMetadataManager.php b/lib/private/FilesMetadata/FilesMetadataManager.php index 8ec49013d5cf8..e1a267743a6b2 100644 --- a/lib/private/FilesMetadata/FilesMetadataManager.php +++ b/lib/private/FilesMetadata/FilesMetadataManager.php @@ -50,7 +50,7 @@ public function getMetadata(int $fileId, bool $generate = false): IFilesMetadata return $this->metadataRequestService->getMetadataFromFileId($fileId); } catch (FilesMetadataNotFoundException $e) { if ($generate) { - return new FilesMetadata($fileId, true); + return new FilesMetadata($fileId); } throw $e; @@ -71,7 +71,9 @@ public function refreshMetadata( } if (null === $metadata) { - $metadata = new FilesMetadata($node->getId(), true); + // if $fromScratch, we reset all and new empty FilesMetadata will + // erase the one stored in db even if it stays empty. + $metadata = new FilesMetadata($node->getId(), $fromScratch); } // is $process is LIVE, we enforce LIVE diff --git a/lib/public/FilesMetadata/IFilesMetadataManager.php b/lib/public/FilesMetadata/IFilesMetadataManager.php index 9bf3a7c20ec7e..f0fd1c07d135b 100644 --- a/lib/public/FilesMetadata/IFilesMetadataManager.php +++ b/lib/public/FilesMetadata/IFilesMetadataManager.php @@ -19,7 +19,7 @@ public function refreshMetadata( bool $fromScratch = false ): IFilesMetadata; - public function getMetadata(int $fileId): IFilesMetadata; + public function getMetadata(int $fileId, bool $generate = false): IFilesMetadata; public function saveMetadata(IFilesMetadata $filesMetadata): void;