Skip to content

Commit 235b64d

Browse files
authored
[Encryption] Fix query option min/max type for exported encrypted fields map (#915)
* Fix query option min/max type for exported encrypted fields map * Type 'decimal' is not a supported equality indexed type
1 parent 28b8e68 commit 235b64d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Command/EncryptionDumpFieldsMapCommand.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7676
continue;
7777
}
7878

79+
// The min/max query options must have the same type as the field.
80+
// But the PHP driver always convert to "int" or "float" when the value fit in the range
7981
foreach ($encryptedFieldsMap as $ns => $encryptedFields) {
82+
$fields = json_decode(PackedArray::fromPHP($encryptedFields['fields'])->toCanonicalExtendedJSON(), true);
83+
foreach ($fields as &$field) {
84+
if ($field['bsonType'] === 'long') {
85+
if (isset($field['queries']['min']['$numberInt'])) {
86+
$field['queries']['min'] = ['$numberLong' => $field['queries']['min']['$numberInt']];
87+
}
88+
89+
if (isset($field['queries']['max']['$numberInt'])) {
90+
$field['queries']['max'] = ['$numberLong' => $field['queries']['max']['$numberInt']];
91+
}
92+
}
93+
}
94+
8095
// Keep only the "fields" key and ignore "escCollection" and "ecocCollection"
81-
$encryptedFieldsMap[$ns] = ['fields' => json_decode(PackedArray::fromPHP($encryptedFields['fields'])->toRelaxedExtendedJSON(), true)];
96+
$encryptedFieldsMap[$ns] = ['fields' => $fields];
8297
}
8398

8499
$io->section(sprintf('Dumping encrypted fields map for document manager "%s"', $name));

0 commit comments

Comments
 (0)