Skip to content

Commit 907a7e4

Browse files
committed
Move to sql.php
1 parent aac387a commit 907a7e4

File tree

3 files changed

+70
-141
lines changed

3 files changed

+70
-141
lines changed

src/Database/Adapter/MariaDB.php

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,76 +1943,6 @@ public function deleteDocument(string $collection, string $id): bool
19431943
return $deleted;
19441944
}
19451945

1946-
/**
1947-
* Delete Documents
1948-
*
1949-
* @param string $collection
1950-
* @param array<string> $internalIds
1951-
* @param array<string> $permissionIds
1952-
*
1953-
* @return int
1954-
*/
1955-
public function deleteDocuments(string $collection, array $internalIds, array $permissionIds): int
1956-
{
1957-
if (empty($internalIds)) {
1958-
return 0;
1959-
}
1960-
1961-
try {
1962-
$name = $this->filter($collection);
1963-
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-
";
1969-
1970-
$sql = $this->trigger(Database::EVENT_DOCUMENTS_DELETE, $sql);
1971-
1972-
$stmt = $this->getPDO()->prepare($sql);
1973-
1974-
foreach ($internalIds as $id => $value) {
1975-
$stmt->bindValue(":_id_{$id}", $value);
1976-
}
1977-
1978-
if ($this->sharedTables) {
1979-
$stmt->bindValue(':_tenant', $this->tenant);
1980-
}
1981-
1982-
if (!$stmt->execute()) {
1983-
throw new DatabaseException('Failed to delete documents');
1984-
}
1985-
1986-
if (!empty($permissionIds)) {
1987-
$sql = "
1988-
DELETE FROM {$this->getSQLTable($name . '_perms')}
1989-
WHERE _document IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($permissionIds))) . ")
1990-
{$this->getTenantQuery($collection)}
1991-
";
1992-
1993-
$sql = $this->trigger(Database::EVENT_PERMISSIONS_DELETE, $sql);
1994-
1995-
$stmtPermissions = $this->getPDO()->prepare($sql);
1996-
1997-
foreach ($permissionIds as $id => $value) {
1998-
$stmtPermissions->bindValue(":_id_{$id}", $value);
1999-
}
2000-
2001-
if ($this->sharedTables) {
2002-
$stmtPermissions->bindValue(':_tenant', $this->tenant);
2003-
}
2004-
2005-
if (!$stmtPermissions->execute()) {
2006-
throw new DatabaseException('Failed to delete permissions');
2007-
}
2008-
}
2009-
} catch (\Throwable $e) {
2010-
throw new DatabaseException($e->getMessage(), $e->getCode(), $e);
2011-
}
2012-
2013-
return $stmt->rowCount();
2014-
}
2015-
20161946
/**
20171947
* Find Documents
20181948
*

src/Database/Adapter/Postgres.php

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,77 +1749,6 @@ public function deleteDocument(string $collection, string $id): bool
17491749
return $deleted;
17501750
}
17511751

1752-
1753-
/**
1754-
* Delete Documents
1755-
*
1756-
* @param string $collection
1757-
* @param array<string> $internalIds
1758-
* @param array<string> $permissionIds
1759-
*
1760-
* @return int
1761-
*/
1762-
public function deleteDocuments(string $collection, array $internalIds, array $permissionIds): int
1763-
{
1764-
if (empty($internalIds)) {
1765-
return 0;
1766-
}
1767-
1768-
try {
1769-
$name = $this->filter($collection);
1770-
1771-
$sql = "
1772-
DELETE FROM {$this->getSQLTable($name)}
1773-
WHERE _id IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($internalIds))) . ")
1774-
{$this->getTenantQuery($collection)}
1775-
";
1776-
1777-
$sql = $this->trigger(Database::EVENT_DOCUMENTS_DELETE, $sql);
1778-
1779-
$stmt = $this->getPDO()->prepare($sql);
1780-
1781-
foreach ($internalIds as $id => $value) {
1782-
$stmt->bindValue(":_id_{$id}", $value);
1783-
}
1784-
1785-
if ($this->sharedTables) {
1786-
$stmt->bindValue(':_tenant', $this->tenant);
1787-
}
1788-
1789-
if (!$stmt->execute()) {
1790-
throw new DatabaseException('Failed to delete documents');
1791-
}
1792-
1793-
if (!empty($permissionIds)) {
1794-
$sql = "
1795-
DELETE FROM {$this->getSQLTable($name . '_perms')}
1796-
WHERE _document IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($permissionIds))) . ")
1797-
{$this->getTenantQuery($collection)}
1798-
";
1799-
1800-
$sql = $this->trigger(Database::EVENT_PERMISSIONS_DELETE, $sql);
1801-
1802-
$stmtPermissions = $this->getPDO()->prepare($sql);
1803-
1804-
foreach ($permissionIds as $id => $value) {
1805-
$stmtPermissions->bindValue(":_id_{$id}", $value);
1806-
}
1807-
1808-
if ($this->sharedTables) {
1809-
$stmtPermissions->bindValue(':_tenant', $this->tenant);
1810-
}
1811-
1812-
if (!$stmtPermissions->execute()) {
1813-
throw new DatabaseException('Failed to delete permissions');
1814-
}
1815-
}
1816-
} catch (\Throwable $e) {
1817-
throw new DatabaseException($e->getMessage(), $e->getCode(), $e);
1818-
}
1819-
1820-
return $stmt->rowCount();
1821-
}
1822-
18231752
/**
18241753
* Find Documents
18251754
*

src/Database/Adapter/SQL.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,4 +1217,74 @@ protected function processException(PDOException $e): \Exception
12171217
{
12181218
return $e;
12191219
}
1220+
1221+
/**
1222+
* Delete Documents
1223+
*
1224+
* @param string $collection
1225+
* @param array<string> $internalIds
1226+
* @param array<string> $permissionIds
1227+
*
1228+
* @return int
1229+
*/
1230+
public function deleteDocuments(string $collection, array $internalIds, array $permissionIds): int
1231+
{
1232+
if (empty($internalIds)) {
1233+
return 0;
1234+
}
1235+
1236+
try {
1237+
$name = $this->filter($collection);
1238+
1239+
$sql = "
1240+
DELETE FROM {$this->getSQLTable($name)}
1241+
WHERE _id IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($internalIds))) . ")
1242+
{$this->getTenantQuery($collection)}
1243+
";
1244+
1245+
$sql = $this->trigger(Database::EVENT_DOCUMENTS_DELETE, $sql);
1246+
1247+
$stmt = $this->getPDO()->prepare($sql);
1248+
1249+
foreach ($internalIds as $id => $value) {
1250+
$stmt->bindValue(":_id_{$id}", $value);
1251+
}
1252+
1253+
if ($this->sharedTables) {
1254+
$stmt->bindValue(':_tenant', $this->tenant);
1255+
}
1256+
1257+
if (!$stmt->execute()) {
1258+
throw new DatabaseException('Failed to delete documents');
1259+
}
1260+
1261+
if (!empty($permissionIds)) {
1262+
$sql = "
1263+
DELETE FROM {$this->getSQLTable($name . '_perms')}
1264+
WHERE _document IN (" . \implode(', ', \array_map(fn ($index) => ":_id_{$index}", \array_keys($permissionIds))) . ")
1265+
{$this->getTenantQuery($collection)}
1266+
";
1267+
1268+
$sql = $this->trigger(Database::EVENT_PERMISSIONS_DELETE, $sql);
1269+
1270+
$stmtPermissions = $this->getPDO()->prepare($sql);
1271+
1272+
foreach ($permissionIds as $id => $value) {
1273+
$stmtPermissions->bindValue(":_id_{$id}", $value);
1274+
}
1275+
1276+
if ($this->sharedTables) {
1277+
$stmtPermissions->bindValue(':_tenant', $this->tenant);
1278+
}
1279+
1280+
if (!$stmtPermissions->execute()) {
1281+
throw new DatabaseException('Failed to delete permissions');
1282+
}
1283+
}
1284+
} catch (\Throwable $e) {
1285+
throw new DatabaseException($e->getMessage(), $e->getCode(), $e);
1286+
}
1287+
1288+
return $stmt->rowCount();
1289+
}
12201290
}

0 commit comments

Comments
 (0)