summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2020-11-09 11:58:36 +0100
committerGitHub <noreply@github.com>2020-11-09 11:58:36 +0100
commit72545ffd07a07f142c9c18b3e4afc9ae1b5c8da2 (patch)
tree3cf50421355a0c04d1280888e2436b705eba86bf /lib
parentf02bab1425b9db105bfd4a8e37e56ac589ab971e (diff)
parentc07720de77282408ddf00311bb13c27d7a898d84 (diff)
downloadnextcloud-server-72545ffd07a07f142c9c18b3e4afc9ae1b5c8da2.tar.gz
nextcloud-server-72545ffd07a07f142c9c18b3e4afc9ae1b5c8da2.zip
Merge pull request #23937 from nextcloud/bugfix/noid/files-ocdb
Use query builder instead of OC_DB in OC\Files\*
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Cache/HomeCache.php19
-rw-r--r--lib/private/Files/Cache/Storage.php33
2 files changed, 37 insertions, 15 deletions
diff --git a/lib/private/Files/Cache/HomeCache.php b/lib/private/Files/Cache/HomeCache.php
index b86a31fe4d1..e66ed7d9722 100644
--- a/lib/private/Files/Cache/HomeCache.php
+++ b/lib/private/Files/Cache/HomeCache.php
@@ -52,12 +52,19 @@ class HomeCache extends Cache {
}
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
$id = $entry['fileid'];
- $sql = 'SELECT SUM(`size`) AS f1 ' .
- 'FROM `*PREFIX*filecache` ' .
- 'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
- $result = \OC_DB::executeAudited($sql, [$id, $this->getNumericStorageId()]);
- if ($row = $result->fetchRow()) {
- $result->closeCursor();
+
+ $query = $this->connection->getQueryBuilder();
+ $query->selectAlias($query->func()->sum('size'), 'f1')
+ ->from('filecache')
+ ->where($query->expr()->eq('parent', $query->createNamedParameter($id)))
+ ->andWhere($query->expr()->eq('storage', $query->createNamedParameter($this->getNumericStorageId())))
+ ->andWhere($query->expr()->gte('size', $query->createNamedParameter(0)));
+
+ $result = $query->execute();
+ $row = $result->fetch();
+ $result->closeCursor();
+
+ if ($row) {
list($sum) = array_values($row);
$totalSize = 0 + $sum;
$entry['size'] += 0;
diff --git a/lib/private/Files/Cache/Storage.php b/lib/private/Files/Cache/Storage.php
index 62228e16290..b11cd5799de 100644
--- a/lib/private/Files/Cache/Storage.php
+++ b/lib/private/Files/Cache/Storage.php
@@ -126,9 +126,14 @@ class Storage {
* @return string|null either the storage id string or null if the numeric id is not known
*/
public static function getStorageId($numericId) {
- $sql = 'SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?';
- $result = \OC_DB::executeAudited($sql, [$numericId]);
- if ($row = $result->fetchRow()) {
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->select('id')
+ ->from('storages')
+ ->where($query->expr()->eq('numeric_id', $query->createNamedParameter($numericId)));
+ $result = $query->execute();
+ $row = $result->fetch();
+ $result->closeCursor();
+ if ($row) {
return $row['id'];
} else {
return null;
@@ -170,9 +175,14 @@ class Storage {
* @param int $delay amount of seconds to delay reconsidering that storage further
*/
public function setAvailability($isAvailable, int $delay = 0) {
- $sql = 'UPDATE `*PREFIX*storages` SET `available` = ?, `last_checked` = ? WHERE `id` = ?';
$available = $isAvailable ? 1 : 0;
- \OC_DB::executeAudited($sql, [$available, time() + $delay, $this->storageId]);
+
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->update('storages')
+ ->set('available', $query->createNamedParameter($available))
+ ->set('last_checked', $query->createNamedParameter(time() + $delay))
+ ->where($query->expr()->eq('id', $query->createNamedParameter($this->storageId)));
+ $query->execute();
}
/**
@@ -193,12 +203,17 @@ class Storage {
public static function remove($storageId) {
$storageId = self::adjustStorageId($storageId);
$numericId = self::getNumericStorageId($storageId);
- $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?';
- \OC_DB::executeAudited($sql, [$storageId]);
+
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->delete('storages')
+ ->where($query->expr()->eq('id', $query->createNamedParameter($storageId)));
+ $query->execute();
if (!is_null($numericId)) {
- $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?';
- \OC_DB::executeAudited($sql, [$numericId]);
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->delete('filecache')
+ ->where($query->expr()->eq('storage', $query->createNamedParameter($numericId)));
+ $query->execute();
}
}
}