2014-11-10 15:00:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
2016-01-12 14:02:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2015-03-26 10:44:34 +00:00
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2014-11-10 15:00:08 +00:00
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2014-11-10 15:00:08 +00:00
|
|
|
namespace OC\Files\Cache\Wrapper;
|
|
|
|
|
|
|
|
use OC\Files\Cache\Cache;
|
2015-12-02 13:59:13 +00:00
|
|
|
use OCP\Files\Cache\ICacheEntry;
|
2014-11-10 15:00:08 +00:00
|
|
|
|
|
|
|
class CacheWrapper extends Cache {
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Cache\Cache
|
|
|
|
*/
|
|
|
|
protected $cache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \OC\Files\Cache\Cache $cache
|
|
|
|
*/
|
|
|
|
public function __construct($cache) {
|
|
|
|
$this->cache = $cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make it easy for wrappers to modify every returned cache entry
|
|
|
|
*
|
2015-12-02 13:59:13 +00:00
|
|
|
* @param ICacheEntry $entry
|
|
|
|
* @return ICacheEntry
|
2014-11-10 15:00:08 +00:00
|
|
|
*/
|
|
|
|
protected function formatCacheEntry($entry) {
|
|
|
|
return $entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the stored metadata of a file or folder
|
|
|
|
*
|
|
|
|
* @param string /int $file
|
2015-12-02 13:59:13 +00:00
|
|
|
* @return ICacheEntry|false
|
2014-11-10 15:00:08 +00:00
|
|
|
*/
|
|
|
|
public function get($file) {
|
|
|
|
$result = $this->cache->get($file);
|
|
|
|
if ($result) {
|
|
|
|
$result = $this->formatCacheEntry($result);
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the metadata of all files stored in $folder
|
|
|
|
*
|
|
|
|
* @param string $folder
|
2015-12-02 13:59:13 +00:00
|
|
|
* @return ICacheEntry[]
|
2014-11-10 15:00:08 +00:00
|
|
|
*/
|
|
|
|
public function getFolderContents($folder) {
|
|
|
|
// cant do a simple $this->cache->.... call here since getFolderContentsById needs to be called on this
|
|
|
|
// and not the wrapped cache
|
|
|
|
$fileId = $this->getId($folder);
|
|
|
|
return $this->getFolderContentsById($fileId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the metadata of all files stored in $folder
|
|
|
|
*
|
|
|
|
* @param int $fileId the file id of the folder
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getFolderContentsById($fileId) {
|
|
|
|
$results = $this->cache->getFolderContentsById($fileId);
|
|
|
|
return array_map(array($this, 'formatCacheEntry'), $results);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* store meta data for a file or folder
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return int file id
|
|
|
|
*/
|
|
|
|
public function put($file, array $data) {
|
|
|
|
return $this->cache->put($file, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* update the metadata in the cache
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @param array $data
|
|
|
|
*/
|
|
|
|
public function update($id, array $data) {
|
|
|
|
$this->cache->update($id, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the file id for a file
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getId($file) {
|
|
|
|
return $this->cache->getId($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the id of the parent folder of a file
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getParentId($file) {
|
|
|
|
return $this->cache->getParentId($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check if a file is available in the cache
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function inCache($file) {
|
|
|
|
return $this->cache->inCache($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* remove a file or folder from the cache
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
*/
|
|
|
|
public function remove($file) {
|
|
|
|
$this->cache->remove($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move a file or folder in the cache
|
|
|
|
*
|
|
|
|
* @param string $source
|
|
|
|
* @param string $target
|
|
|
|
*/
|
|
|
|
public function move($source, $target) {
|
|
|
|
$this->cache->move($source, $target);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* remove all entries for files that are stored on the storage from the cache
|
|
|
|
*/
|
|
|
|
public function clear() {
|
|
|
|
$this->cache->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file
|
|
|
|
*
|
2015-01-16 18:31:15 +00:00
|
|
|
* @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
|
2014-11-10 15:00:08 +00:00
|
|
|
*/
|
|
|
|
public function getStatus($file) {
|
|
|
|
return $this->cache->getStatus($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* search for files matching $pattern
|
|
|
|
*
|
|
|
|
* @param string $pattern
|
2015-12-02 13:59:13 +00:00
|
|
|
* @return ICacheEntry[] an array of file data
|
2014-11-10 15:00:08 +00:00
|
|
|
*/
|
|
|
|
public function search($pattern) {
|
|
|
|
$results = $this->cache->search($pattern);
|
|
|
|
return array_map(array($this, 'formatCacheEntry'), $results);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* search for files by mimetype
|
|
|
|
*
|
|
|
|
* @param string $mimetype
|
2015-12-02 13:59:13 +00:00
|
|
|
* @return ICacheEntry[]
|
2014-11-10 15:00:08 +00:00
|
|
|
*/
|
|
|
|
public function searchByMime($mimetype) {
|
|
|
|
$results = $this->cache->searchByMime($mimetype);
|
|
|
|
return array_map(array($this, 'formatCacheEntry'), $results);
|
|
|
|
}
|
|
|
|
|
2014-12-04 13:01:15 +00:00
|
|
|
/**
|
|
|
|
* search for files by tag
|
|
|
|
*
|
|
|
|
* @param string|int $tag name or tag id
|
|
|
|
* @param string $userId owner of the tags
|
2015-12-02 13:59:13 +00:00
|
|
|
* @return ICacheEntry[] file data
|
2014-12-04 13:01:15 +00:00
|
|
|
*/
|
2014-12-12 10:18:35 +00:00
|
|
|
public function searchByTag($tag, $userId) {
|
2014-12-04 13:01:15 +00:00
|
|
|
$results = $this->cache->searchByTag($tag, $userId);
|
|
|
|
return array_map(array($this, 'formatCacheEntry'), $results);
|
|
|
|
}
|
|
|
|
|
2014-11-10 15:00:08 +00:00
|
|
|
/**
|
|
|
|
* update the folder size and the size of all parent folders
|
|
|
|
*
|
|
|
|
* @param string|boolean $path
|
|
|
|
* @param array $data (optional) meta data of the folder
|
|
|
|
*/
|
|
|
|
public function correctFolderSize($path, $data = null) {
|
|
|
|
$this->cache->correctFolderSize($path, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the size of a folder and set it in the cache
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param array $entry (optional) meta data of the folder
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function calculateFolderSize($path, $entry = null) {
|
|
|
|
return $this->cache->calculateFolderSize($path, $entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get all file ids on the files on the storage
|
|
|
|
*
|
|
|
|
* @return int[]
|
|
|
|
*/
|
|
|
|
public function getAll() {
|
|
|
|
return $this->cache->getAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* find a folder in the cache which has not been fully scanned
|
|
|
|
*
|
|
|
|
* If multiple incomplete folders are in the cache, the one with the highest id will be returned,
|
|
|
|
* use the one with the highest id gives the best result with the background scanner, since that is most
|
|
|
|
* likely the folder where we stopped scanning previously
|
|
|
|
*
|
|
|
|
* @return string|bool the path of the folder or false when no folder matched
|
|
|
|
*/
|
|
|
|
public function getIncomplete() {
|
|
|
|
return $this->cache->getIncomplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the path of a file on this storage by it's id
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getPathById($id) {
|
|
|
|
return $this->cache->getPathById($id);
|
|
|
|
}
|
|
|
|
|
2014-12-10 11:55:01 +00:00
|
|
|
/**
|
|
|
|
* Returns the numeric storage id
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getNumericStorageId() {
|
|
|
|
return $this->cache->getNumericStorageId();
|
|
|
|
}
|
|
|
|
|
2014-11-10 15:00:08 +00:00
|
|
|
/**
|
|
|
|
* get the storage id of the storage for a file and the internal path of the file
|
|
|
|
* unlike getPathById this does not limit the search to files on this storage and
|
|
|
|
* instead does a global search in the cache table
|
|
|
|
*
|
|
|
|
* @param int $id
|
2015-01-16 18:31:15 +00:00
|
|
|
* @return array first element holding the storage id, second the path
|
2014-11-10 15:00:08 +00:00
|
|
|
*/
|
|
|
|
static public function getById($id) {
|
|
|
|
return parent::getById($id);
|
|
|
|
}
|
|
|
|
}
|