Skip to content

Commit dbfac22

Browse files
committed
Fix array_filter to preserve valid UID '0' and tenant 0 — filter only null
1 parent bb419ba commit dbfac22

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/Database/Adapter/Mongo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ public function createDocuments(Document $collection, array $documents, bool $ig
15261526
}
15271527
}
15281528
} else {
1529-
$uids = \array_filter(\array_map(fn ($r) => $r['_uid'] ?? null, $records));
1529+
$uids = \array_filter(\array_map(fn ($r) => $r['_uid'] ?? null, $records), fn ($v) => $v !== null);
15301530
if (!empty($uids)) {
15311531
$uidValues = \array_values(\array_unique($uids));
15321532
$findOptions = $this->getTransactionOptions([

src/Database/Adapter/SQL.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,7 @@ public function createDocuments(Document $collection, array $documents, bool $ig
24822482
if ($ignore) {
24832483
$collectionId = $collection->getId();
24842484
$name = $this->filter($collectionId);
2485-
$uids = \array_filter(\array_map(fn (Document $doc) => $doc->getId(), $documents));
2485+
$uids = \array_filter(\array_map(fn (Document $doc) => $doc->getId(), $documents), fn ($v) => $v !== null);
24862486

24872487
if (!empty($uids)) {
24882488
try {
@@ -2498,7 +2498,8 @@ public function createDocuments(Document $collection, array $documents, bool $ig
24982498
if ($this->sharedTables) {
24992499
if ($this->tenantPerDocument) {
25002500
$tenants = \array_values(\array_unique(\array_filter(
2501-
\array_map(fn (Document $doc) => $doc->getTenant(), $documents)
2501+
\array_map(fn (Document $doc) => $doc->getTenant(), $documents),
2502+
fn ($v) => $v !== null
25022503
)));
25032504
$tenantPlaceholders = [];
25042505
foreach ($tenants as $j => $tenant) {
@@ -2687,7 +2688,8 @@ public function createDocuments(Document $collection, array $documents, bool $ig
26872688
if ($this->sharedTables) {
26882689
if ($this->tenantPerDocument) {
26892690
$tenants = \array_values(\array_unique(\array_filter(
2690-
\array_map(fn (Document $doc) => $doc->getTenant(), $documents)
2691+
\array_map(fn (Document $doc) => $doc->getTenant(), $documents),
2692+
fn ($v) => $v !== null
26912693
)));
26922694
$tenantPlaceholders = [];
26932695
foreach ($tenants as $j => $tenant) {

src/Database/Database.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5689,7 +5689,7 @@ public function createDocuments(
56895689
$idsByTenant[$doc->getTenant()][] = $doc->getId();
56905690
}
56915691
foreach ($idsByTenant as $tenant => $tenantIds) {
5692-
$tenantIds = \array_values(\array_unique(\array_filter($tenantIds)));
5692+
$tenantIds = \array_values(\array_unique(\array_filter($tenantIds, fn ($v) => $v !== null)));
56935693
foreach (\array_chunk($tenantIds, \max(1, $this->maxQueryValues)) as $idChunk) {
56945694
$existing = $this->authorization->skip(fn () => $this->withTenant($tenant, fn () => $this->silent(fn () => $this->find(
56955695
$collection->getId(),
@@ -5706,7 +5706,8 @@ public function createDocuments(
57065706
}
57075707
} else {
57085708
$inputIds = \array_values(\array_unique(\array_filter(
5709-
\array_map(fn (Document $doc) => $doc->getId(), $documents)
5709+
\array_map(fn (Document $doc) => $doc->getId(), $documents),
5710+
fn ($v) => $v !== null
57105711
)));
57115712

57125713
foreach (\array_chunk($inputIds, \max(1, $this->maxQueryValues)) as $idChunk) {
@@ -7252,7 +7253,7 @@ public function upsertDocumentsWithIncrease(
72527253
$seenIds = [];
72537254

72547255
// Batch-fetch existing documents in one query instead of N individual getDocument() calls
7255-
$ids = \array_filter(\array_map(fn ($doc) => $doc->getId(), $documents));
7256+
$ids = \array_filter(\array_map(fn ($doc) => $doc->getId(), $documents), fn ($v) => $v !== null);
72567257
$existingDocs = [];
72577258
$upsertTenantPerDocument = $this->getSharedTables() && $this->getTenantPerDocument();
72587259

@@ -7268,7 +7269,7 @@ public function upsertDocumentsWithIncrease(
72687269
$idsByTenant[$tenant][] = $doc->getId();
72697270
}
72707271
foreach ($idsByTenant as $tenant => $tenantIds) {
7271-
$tenantIds = \array_values(\array_unique(\array_filter($tenantIds)));
7272+
$tenantIds = \array_values(\array_unique(\array_filter($tenantIds, fn ($v) => $v !== null)));
72727273
foreach (\array_chunk($tenantIds, \max(1, $this->maxQueryValues)) as $idChunk) {
72737274
$fetched = $this->authorization->skip(fn () => $this->withTenant($tenant, fn () => $this->silent(fn () => $this->find(
72747275
$collection->getId(),

0 commit comments

Comments
 (0)