Skip to content

Commit c36a0d0

Browse files
committed
Address comments
1 parent 799952d commit c36a0d0

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

src/Database/Adapter/MariaDB.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,15 +1960,12 @@ public function deleteDocuments(string $collection, array $internalIds, array $p
19601960

19611961
try {
19621962
$name = $this->filter($collection);
1963-
$where = [];
19641963

1965-
if ($this->sharedTables) {
1966-
$where[] = "_tenant = :_tenant";
1967-
}
1968-
1969-
$where[] = "_id IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($internalIds))) . ")";
1970-
1971-
$sql = "DELETE FROM {$this->getSQLTable($name)} WHERE " . \implode(' AND ', $where);
1964+
$sql = "
1965+
DELETE FROM {$this->getSQLTable($name)}
1966+
WHERE _id IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($internalIds))) . ")
1967+
{$this->getTenantQuery($collection)}
1968+
";
19721969

19731970
$sql = $this->trigger(Database::EVENT_DOCUMENTS_DELETE, $sql);
19741971

@@ -1989,19 +1986,16 @@ public function deleteDocuments(string $collection, array $internalIds, array $p
19891986
if (!empty($permissionIds)) {
19901987
$sql = "
19911988
DELETE FROM {$this->getSQLTable($name . '_perms')}
1992-
WHERE _document IN (" . \implode(', ', \array_map(fn ($index) => ":_pid_{$index}", \array_keys($permissionIds))) . ")
1993-
";
1994-
1995-
if ($this->sharedTables) {
1996-
$sql .= ' AND _tenant = :_tenant';
1997-
}
1989+
WHERE _document IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($permissionIds))) . ")
1990+
{$this->getTenantQuery($collection)}
1991+
";
19981992

19991993
$sql = $this->trigger(Database::EVENT_PERMISSIONS_DELETE, $sql);
20001994

20011995
$stmtPermissions = $this->getPDO()->prepare($sql);
20021996

20031997
foreach ($permissionIds as $id => $value) {
2004-
$stmtPermissions->bindValue(":_pid_{$id}", $value);
1998+
$stmtPermissions->bindValue(":_id_{$id}", $value);
20051999
}
20062000

20072001
if ($this->sharedTables) {

src/Database/Database.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5508,13 +5508,13 @@ public function deleteDocuments(string $collection, array $queries = [], int $ba
55085508
break;
55095509
}
55105510

5511-
$internalId = [];
5512-
$permIds = [];
5511+
$internalIds = [];
5512+
$permissionIds = [];
55135513
foreach ($affectedDocuments as $document) {
55145514
$documents[] = $document;
5515-
$internalId[] = $document->getInternalId();
5515+
$internalIds[] = $document->getInternalId();
55165516
if (!empty($document->getPermissions())) {
5517-
$permIds[] = $document->getId();
5517+
$permissionIds[] = $document->getId();
55185518
}
55195519

55205520
if ($this->resolveRelationships) {
@@ -5536,11 +5536,11 @@ public function deleteDocuments(string $collection, array $queries = [], int $ba
55365536
}
55375537
}
55385538

5539-
$this->withTransaction(function () use ($collection, $skipAuth, $authorization, $internalId, $permIds) {
5539+
$this->withTransaction(function () use ($collection, $skipAuth, $authorization, $internalIds, $permissionIds) {
55405540
$getResults = fn () => $this->adapter->deleteDocuments(
55415541
$collection->getId(),
5542-
$internalId,
5543-
$permIds
5542+
$internalIds,
5543+
$permissionIds
55445544
);
55455545

55465546
$skipAuth ? $authorization->skip($getResults) : $getResults();

0 commit comments

Comments
 (0)