Skip to content

Commit 28b4f27

Browse files
linting
1 parent 6f23b3d commit 28b4f27

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

src/Database/Adapter/Mongo.php

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ public function upsertDocuments(Document $collection, string $attribute, array $
15891589
unset($record['_id']); // Don't update _id
15901590

15911591
// Get fields to unset for schemaless mode
1592-
$unsetFields = $this->getUnsetForSchemalessUpsert($oldDocument, $document, $record);
1592+
$unsetFields = $this->getUpsertAttributeRemovals($oldDocument, $document, $record);
15931593

15941594
if (!empty($attribute)) {
15951595
// Get the attribute value before removing it from $set
@@ -1649,6 +1649,43 @@ public function upsertDocuments(Document $collection, string $attribute, array $
16491649
return \array_map(fn ($change) => $change->getNew(), $changes);
16501650
}
16511651

1652+
/**
1653+
* Get fields to unset for schemaless upsert operations
1654+
*
1655+
* @param Document $oldDocument
1656+
* @param Document $newDocument
1657+
* @param array<string, mixed> $record
1658+
* @return array<string, string>
1659+
*/
1660+
private function getUpsertAttributeRemovals(Document $oldDocument, Document $newDocument, array $record): array
1661+
{
1662+
$unsetFields = [];
1663+
1664+
if ($this->getSupportForAttributes() || $oldDocument->isEmpty()) {
1665+
return $unsetFields;
1666+
}
1667+
1668+
$oldUserAttributes = $oldDocument->getAttributes();
1669+
$newUserAttributes = $newDocument->getAttributes();
1670+
1671+
$protectedFields = ['_uid', '_id', '_createdAt', '_updatedAt', '_permissions', '_tenant'];
1672+
1673+
foreach ($oldUserAttributes as $originalKey => $originalValue) {
1674+
if (in_array($originalKey, $protectedFields) || array_key_exists($originalKey, $newUserAttributes)) {
1675+
continue;
1676+
}
1677+
1678+
$transformed = $this->replaceChars('$', '_', [$originalKey => $originalValue]);
1679+
$dbKey = array_key_first($transformed);
1680+
1681+
if ($dbKey && !array_key_exists($dbKey, $record) && !in_array($dbKey, $protectedFields)) {
1682+
$unsetFields[$dbKey] = '';
1683+
}
1684+
}
1685+
1686+
return $unsetFields;
1687+
}
1688+
16521689
/**
16531690
* Get sequences for documents that were created
16541691
*
@@ -3410,41 +3447,4 @@ public function getSupportForTrigramIndex(): bool
34103447
{
34113448
return false;
34123449
}
3413-
3414-
/**
3415-
* Get fields to unset for schemaless upsert operations
3416-
*
3417-
* @param Document $oldDocument
3418-
* @param Document $newDocument
3419-
* @param array<string, mixed> $record
3420-
* @return array<string, string>
3421-
*/
3422-
private function getUnsetForSchemalessUpsert(Document $oldDocument, Document $newDocument, array $record): array
3423-
{
3424-
$unsetFields = [];
3425-
3426-
if ($this->getSupportForAttributes() || $oldDocument->isEmpty()) {
3427-
return $unsetFields;
3428-
}
3429-
3430-
$oldUserAttributes = $oldDocument->getAttributes();
3431-
$newUserAttributes = $newDocument->getAttributes();
3432-
3433-
$protectedFields = ['_uid', '_id', '_createdAt', '_updatedAt', '_permissions', '_tenant'];
3434-
3435-
foreach ($oldUserAttributes as $originalKey => $originalValue) {
3436-
if (in_array($originalKey, $protectedFields) || array_key_exists($originalKey, $newUserAttributes)) {
3437-
continue;
3438-
}
3439-
3440-
$transformed = $this->replaceChars('$', '_', [$originalKey => $originalValue]);
3441-
$dbKey = array_key_first($transformed);
3442-
3443-
if ($dbKey && !array_key_exists($dbKey, $record) && !in_array($dbKey, $protectedFields)) {
3444-
$unsetFields[$dbKey] = '';
3445-
}
3446-
}
3447-
3448-
return $unsetFields;
3449-
}
34503450
}

0 commit comments

Comments
 (0)