Use query builder instead of OC_DB in OC\Files\*
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
20885847c8
commit
adcc942553
|
@ -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()) {
|
||||
|
||||
$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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -343,9 +343,11 @@ class ScannerTest extends \Test\TestCase {
|
|||
$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']);
|
||||
|
@ -367,9 +369,11 @@ class ScannerTest extends \Test\TestCase {
|
|||
$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']);
|
||||
|
|
Loading…
Reference in New Issue