|
|
|
|
@ -30,11 +30,9 @@ class Cache {
|
|
|
|
|
private $storageId;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* numeric storage id
|
|
|
|
|
*
|
|
|
|
|
* @var int $numericId
|
|
|
|
|
* @var Storage $storageCache
|
|
|
|
|
*/
|
|
|
|
|
private $numericId;
|
|
|
|
|
private $storageCache;
|
|
|
|
|
|
|
|
|
|
private $mimetypeIds = array();
|
|
|
|
|
private $mimetypes = array();
|
|
|
|
|
@ -52,19 +50,11 @@ class Cache {
|
|
|
|
|
$this->storageId = md5($this->storageId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$query = \OC_DB::prepare('SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?');
|
|
|
|
|
$result = $query->execute(array($this->storageId));
|
|
|
|
|
if ($row = $result->fetchRow()) {
|
|
|
|
|
$this->numericId = $row['numeric_id'];
|
|
|
|
|
} else {
|
|
|
|
|
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*storages`(`id`) VALUES(?)');
|
|
|
|
|
$query->execute(array($this->storageId));
|
|
|
|
|
$this->numericId = \OC_DB::insertid('*PREFIX*storages');
|
|
|
|
|
}
|
|
|
|
|
$this->storageCache = new Storage($storage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getNumericStorageId() {
|
|
|
|
|
return $this->numericId;
|
|
|
|
|
return $this->storageCache->getNumericId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -111,7 +101,7 @@ class Cache {
|
|
|
|
|
public function get($file) {
|
|
|
|
|
if (is_string($file) or $file == '') {
|
|
|
|
|
$where = 'WHERE `storage` = ? AND `path_hash` = ?';
|
|
|
|
|
$params = array($this->numericId, md5($file));
|
|
|
|
|
$params = array($this->getNumericStorageId(), md5($file));
|
|
|
|
|
} else { //file id
|
|
|
|
|
$where = 'WHERE `fileid` = ?';
|
|
|
|
|
$params = array($file);
|
|
|
|
|
@ -198,14 +188,14 @@ class Cache {
|
|
|
|
|
|
|
|
|
|
list($queryParts, $params) = $this->buildParts($data);
|
|
|
|
|
$queryParts[] = '`storage`';
|
|
|
|
|
$params[] = $this->numericId;
|
|
|
|
|
$params[] = $this->getNumericStorageId();
|
|
|
|
|
$valuesPlaceholder = array_fill(0, count($queryParts), '?');
|
|
|
|
|
|
|
|
|
|
$query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ')'
|
|
|
|
|
. ' VALUES(' . implode(', ', $valuesPlaceholder) . ')');
|
|
|
|
|
$result = $query->execute($params);
|
|
|
|
|
if (\OC_DB::isError($result)) {
|
|
|
|
|
\OCP\Util::writeLog('cache', 'Insert to cache failed: '.$result, \OCP\Util::ERROR);
|
|
|
|
|
\OCP\Util::writeLog('cache', 'Insert to cache failed: ' . $result, \OCP\Util::ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (int)\OC_DB::insertid('*PREFIX*filecache');
|
|
|
|
|
@ -264,7 +254,7 @@ class Cache {
|
|
|
|
|
$pathHash = md5($file);
|
|
|
|
|
|
|
|
|
|
$query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
|
|
|
|
|
$result = $query->execute(array($this->numericId, $pathHash));
|
|
|
|
|
$result = $query->execute(array($this->getNumericStorageId(), $pathHash));
|
|
|
|
|
|
|
|
|
|
if ($row = $result->fetchRow()) {
|
|
|
|
|
return $row['fileid'];
|
|
|
|
|
@ -353,7 +343,7 @@ class Cache {
|
|
|
|
|
*/
|
|
|
|
|
public function clear() {
|
|
|
|
|
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage = ?');
|
|
|
|
|
$query->execute(array($this->numericId));
|
|
|
|
|
$query->execute(array($this->getNumericStorageId()));
|
|
|
|
|
|
|
|
|
|
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*storages` WHERE id = ?');
|
|
|
|
|
$query->execute(array($this->storageId));
|
|
|
|
|
@ -367,7 +357,7 @@ class Cache {
|
|
|
|
|
public function getStatus($file) {
|
|
|
|
|
$pathHash = md5($file);
|
|
|
|
|
$query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
|
|
|
|
|
$result = $query->execute(array($this->numericId, $pathHash));
|
|
|
|
|
$result = $query->execute(array($this->getNumericStorageId(), $pathHash));
|
|
|
|
|
if ($row = $result->fetchRow()) {
|
|
|
|
|
if ((int)$row['size'] === -1) {
|
|
|
|
|
return self::SHALLOW;
|
|
|
|
|
@ -394,7 +384,7 @@ class Cache {
|
|
|
|
|
SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`
|
|
|
|
|
FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `storage` = ?'
|
|
|
|
|
);
|
|
|
|
|
$result = $query->execute(array($pattern, $this->numericId));
|
|
|
|
|
$result = $query->execute(array($pattern, $this->getNumericStorageId()));
|
|
|
|
|
$files = array();
|
|
|
|
|
while ($row = $result->fetchRow()) {
|
|
|
|
|
$row['mimetype'] = $this->getMimetype($row['mimetype']);
|
|
|
|
|
@ -421,7 +411,7 @@ class Cache {
|
|
|
|
|
FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?'
|
|
|
|
|
);
|
|
|
|
|
$mimetype = $this->getMimetypeId($mimetype);
|
|
|
|
|
$result = $query->execute(array($mimetype, $this->numericId));
|
|
|
|
|
$result = $query->execute(array($mimetype, $this->getNumericStorageId()));
|
|
|
|
|
$files = array();
|
|
|
|
|
while ($row = $result->fetchRow()) {
|
|
|
|
|
$row['mimetype'] = $this->getMimetype($row['mimetype']);
|
|
|
|
|
@ -459,7 +449,7 @@ class Cache {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
$query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?');
|
|
|
|
|
$result = $query->execute(array($id, $this->numericId));
|
|
|
|
|
$result = $query->execute(array($id, $this->getNumericStorageId()));
|
|
|
|
|
$totalSize = 0;
|
|
|
|
|
$hasChilds = 0;
|
|
|
|
|
while ($row = $result->fetchRow()) {
|
|
|
|
|
@ -486,7 +476,7 @@ class Cache {
|
|
|
|
|
*/
|
|
|
|
|
public function getAll() {
|
|
|
|
|
$query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?');
|
|
|
|
|
$result = $query->execute(array($this->numericId));
|
|
|
|
|
$result = $query->execute(array($this->getNumericStorageId()));
|
|
|
|
|
$ids = array();
|
|
|
|
|
while ($row = $result->fetchRow()) {
|
|
|
|
|
$ids[] = $row['fileid'];
|
|
|
|
|
@ -506,7 +496,7 @@ class Cache {
|
|
|
|
|
public function getIncomplete() {
|
|
|
|
|
$query = \OC_DB::prepare('SELECT `path` FROM `*PREFIX*filecache`'
|
|
|
|
|
. ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC LIMIT 1');
|
|
|
|
|
$result = $query->execute(array($this->numericId));
|
|
|
|
|
$result = $query->execute(array($this->getNumericStorageId()));
|
|
|
|
|
if ($row = $result->fetchRow()) {
|
|
|
|
|
return $row['path'];
|
|
|
|
|
} else {
|
|
|
|
|
@ -517,6 +507,7 @@ class Cache {
|
|
|
|
|
/**
|
|
|
|
|
* get the storage id of the storage for a file and the internal path of the file
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return array, first element holding the storage id, second the path
|
|
|
|
|
*/
|
|
|
|
|
static public function getById($id) {
|
|
|
|
|
@ -529,10 +520,8 @@ class Cache {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?');
|
|
|
|
|
$result = $query->execute(array($numericId));
|
|
|
|
|
if ($row = $result->fetchRow()) {
|
|
|
|
|
return array($row['id'], $path);
|
|
|
|
|
if ($id = Storage::getStorageId($numericId)) {
|
|
|
|
|
return array($id, $path);
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|