}
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;
* @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;
* @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();
}
/**
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();
}
}
}
public function testBackgroundScanNestedIncompleteFolders() {
$this->storage->mkdir('folder');
$this->scanner->backgroundScan();
-
+
$this->storage->mkdir('folder/subfolder1');
$this->storage->mkdir('folder/subfolder2');
-
+
$this->storage->mkdir('folder/subfolder1/subfolder3');
$this->cache->put('folder', ['size' => -1]);
$this->cache->put('folder/subfolder1', ['size' => -1]);
-
+
// do a scan to get the folders into the cache.
$this->scanner->backgroundScan();
$this->assertTrue($this->cache->inCache('folder/subfolder1/subfolder3'));
-
+
$this->storage->file_put_contents('folder/subfolder1/bar1.txt', 'foobar');
$this->storage->file_put_contents('folder/subfolder1/subfolder3/bar3.txt', 'foobar');
$this->storage->file_put_contents('folder/subfolder2/bar2.txt', 'foobar');
$this->cache->put('folder/subfolder1', ['size' => -1]);
$this->cache->put('folder/subfolder2', ['size' => -1]);
$this->cache->put('folder/subfolder1/subfolder3', ['size' => -1]);
-
+
$this->scanner->backgroundScan();
$this->assertTrue($this->cache->inCache('folder/subfolder1/bar1.txt'));
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
$oldFolderId = $this->cache->getId('folder');
- // delete the folder without removing the childs
- $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?';
- \OC_DB::executeAudited($sql, [$oldFolderId]);
+ // delete the folder without removing the children
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->delete('filecache')
+ ->where($query->expr()->eq('fileid', $query->createNamedParameter($oldFolderId)));
+ $query->execute();
$cachedData = $this->cache->get('folder/bar.txt');
$this->assertEquals($oldFolderId, $cachedData['parent']);
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
$oldFolderId = $this->cache->getId('folder');
- // delete the folder without removing the childs
- $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?';
- \OC_DB::executeAudited($sql, [$oldFolderId]);
+ // delete the folder without removing the children
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->delete('filecache')
+ ->where($query->expr()->eq('fileid', $query->createNamedParameter($oldFolderId)));
+ $query->execute();
$cachedData = $this->cache->get('folder/bar.txt');
$this->assertEquals($oldFolderId, $cachedData['parent']);