add : allow to set multiple --source, the first not-empty meta is copied to destination (#4516)

This commit is contained in:
jygaulier
2024-06-06 15:19:01 +02:00
committed by GitHub
parent 5769be7799
commit 45e8f29fc9
2 changed files with 17 additions and 6 deletions

View File

@@ -33,7 +33,7 @@ class RescanFilesMetadata extends Command
->addOption('min_record_id', null, InputOption::VALUE_REQUIRED, "lowest record_id value") ->addOption('min_record_id', null, InputOption::VALUE_REQUIRED, "lowest record_id value")
->addOption('record_type', null, InputOption::VALUE_REQUIRED, 'Type of records(s) to scan.') ->addOption('record_type', null, InputOption::VALUE_REQUIRED, 'Type of records(s) to scan.')
->addOption('partition', null, InputOption::VALUE_REQUIRED, 'n/N : work only on records belonging to partition') ->addOption('partition', null, InputOption::VALUE_REQUIRED, 'n/N : work only on records belonging to partition')
->addOption('source', null, InputOption::VALUE_REQUIRED, 'tag to search exemple IPTC:KEYWORD') ->addOption('source', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'tag to search exemple IPTC:KEYWORD')
->addOption('destination', null, InputOption::VALUE_REQUIRED, "ID of the field de fill") ->addOption('destination', null, InputOption::VALUE_REQUIRED, "ID of the field de fill")
->addOption('overwrite', null, InputOption::VALUE_NONE, "act even if the destination field has a value in databox") ->addOption('overwrite', null, InputOption::VALUE_NONE, "act even if the destination field has a value in databox")
->addOption('method', null, InputOption::VALUE_REQUIRED, "replace or merge for multi value field") ->addOption('method', null, InputOption::VALUE_REQUIRED, "replace or merge for multi value field")

View File

@@ -1287,12 +1287,15 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
* @return array|null * @return array|null
* @throws \PHPExiftool\Exception\EmptyCollectionException * @throws \PHPExiftool\Exception\EmptyCollectionException
*/ */
public function getFileMetadataByTag($tag) public function getFileMetadataByTag($tags)
{ {
$logger = new Logger('exif-tool'); $logger = new Logger('exif-tool');
$reader = Reader::create($logger); $reader = Reader::create($logger);
$value = null; if(!is_array($tags)) {
$tags = [$tags];
}
$tags = array_fill_keys($tags, null);
// throw exception // throw exception
$documentSubdef = $this->get_subdef('document'); $documentSubdef = $this->get_subdef('document');
@@ -1301,14 +1304,22 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
/** @var Metadata $metadata */ /** @var Metadata $metadata */
foreach ($metadatas as $metadata) { foreach ($metadatas as $metadata) {
if ($metadata->getTag() == $tag) { /** @var string $t */
$value = explode(";", $metadata->getValue()); $t = (string)$metadata->getTag();
if (array_key_exists($t, $tags)) {
$tags[$t] = explode(";", $metadata->getValue());
break; break;
} }
} }
foreach($tags as $tag => $value) {
if($value !== null) {
return $value; return $value;
} }
}
return null;
}
/* /*