Skip to content

Commit 98a4fa8

Browse files
abnegateclaude
andcommitted
fix: address review — add missing syncReadHooks in Mongo and tenant guards in batch writes
- Mongo adapter: add syncReadHooks() before applyReadFilters() in updateDocument, updateDocuments, deleteDocument, deleteDocuments, and increaseDocumentAttribute to ensure tenant/permission hooks are initialized on update/delete paths - Documents trait: add shared-table tenant guard to createDocuments() and upsertDocumentsWithIncrease() matching the existing guard in createDocument() to prevent writes without a tenant partition Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 582d2cb commit 98a4fa8

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/Database/Adapter/Mongo.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,8 @@ public function updateDocument(Document $collection, string $id, Document $docum
14251425
$record = $this->replaceChars('$', '_', $record);
14261426

14271427
$filters = ['_uid' => $id];
1428+
1429+
$this->syncReadHooks();
14281430
$filters = $this->applyReadFilters($filters, $collection->getId());
14291431

14301432
try {
@@ -1462,6 +1464,8 @@ public function updateDocuments(Document $collection, Document $updates, array $
14621464

14631465
/** @var array<string, mixed> $filters */
14641466
$filters = $this->buildFilters($queries);
1467+
1468+
$this->syncReadHooks();
14651469
$filters = $this->applyReadFilters($filters, $collection->getId());
14661470

14671471
$record = $updates->getArrayCopy();
@@ -1601,6 +1605,8 @@ public function deleteDocument(string $collection, string $id): bool
16011605
$name = $this->getNamespace().'_'.$this->filter($collection);
16021606

16031607
$filters = ['_uid' => $id];
1608+
1609+
$this->syncReadHooks();
16041610
$filters = $this->applyReadFilters($filters, $collection);
16051611

16061612
$options = $this->getTransactionOptions();
@@ -1627,6 +1633,8 @@ public function deleteDocuments(string $collection, array $sequences, array $per
16271633

16281634
/** @var array<string, mixed> $filters */
16291635
$filters = $this->buildFilters([new Query(Method::Equal, '_id', $sequences)]);
1636+
1637+
$this->syncReadHooks();
16301638
$filters = $this->applyReadFilters($filters, $collection);
16311639

16321640
$filters = $this->replaceInternalIdsKeys($filters, '$', '_', $this->operators);
@@ -1656,6 +1664,8 @@ public function increaseDocumentAttribute(string $collection, string $id, string
16561664
{
16571665
$attribute = $this->filter($attribute);
16581666
$filters = ['_uid' => $id];
1667+
1668+
$this->syncReadHooks();
16591669
$filters = $this->applyReadFilters($filters, $collection);
16601670

16611671
if ($max !== null || $min !== null) {

src/Database/Traits/Documents.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,14 @@ public function createDocuments(
470470
?callable $onNext = null,
471471
?callable $onError = null,
472472
): int {
473+
if (
474+
$this->adapter->getSharedTables()
475+
&& ! $this->adapter->getTenantPerDocument()
476+
&& empty($this->adapter->getTenant())
477+
) {
478+
throw new DatabaseException('Missing tenant. Tenant must be set when table sharing is enabled.');
479+
}
480+
473481
if (! $this->adapter->getSharedTables() && $this->adapter->getTenantPerDocument()) {
474482
throw new DatabaseException('Shared tables must be enabled if tenant per document is enabled.');
475483
}
@@ -1207,6 +1215,18 @@ public function upsertDocumentsWithIncrease(
12071215
?callable $onError = null,
12081216
int $batchSize = self::INSERT_BATCH_SIZE
12091217
): int {
1218+
if (
1219+
$this->adapter->getSharedTables()
1220+
&& ! $this->adapter->getTenantPerDocument()
1221+
&& empty($this->adapter->getTenant())
1222+
) {
1223+
throw new DatabaseException('Missing tenant. Tenant must be set when table sharing is enabled.');
1224+
}
1225+
1226+
if (! $this->adapter->getSharedTables() && $this->adapter->getTenantPerDocument()) {
1227+
throw new DatabaseException('Shared tables must be enabled if tenant per document is enabled.');
1228+
}
1229+
12101230
if (empty($documents)) {
12111231
return 0;
12121232
}

0 commit comments

Comments
 (0)