Skip to content

Commit

Permalink
small improvement
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Oct 22, 2023
1 parent 754a1f7 commit c89df97
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
18 changes: 13 additions & 5 deletions core/Command/FilesMetadata/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
'',
Expand All @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/private/FilesMetadata/FilesMetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/public/FilesMetadata/IFilesMetadataManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 22 in lib/public/FilesMetadata/IFilesMetadataManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/FilesMetadata/IFilesMetadataManager.php:22:2: InvalidDocblock: PHPDoc is required for methods in OCP. (see https://psalm.dev/008)

public function saveMetadata(IFilesMetadata $filesMetadata): void;

Expand Down

0 comments on commit c89df97

Please sign in to comment.