2012-12-16 04:44:46 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2013-01-29 00:25:19 +04:00
|
|
|
* ownCloud
|
|
|
|
*
|
2014-04-02 14:04:51 +04:00
|
|
|
* @author Bjoern Schiessle, Michael Gapczynski
|
|
|
|
* @copyright 2012 Michael Gapczynski <mtgap@owncloud.com>
|
|
|
|
* 2014 Bjoern Schiessle <schiessle@owncloud.com>
|
2013-01-29 00:25:19 +04:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2012-12-16 04:44:46 +04:00
|
|
|
|
|
|
|
namespace OC\Files\Cache;
|
2014-03-28 18:26:15 +04:00
|
|
|
|
2013-09-24 12:37:58 +04:00
|
|
|
use OCP\Share_Backend_Collection;
|
2012-12-16 04:44:46 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Metadata cache for shared files
|
|
|
|
*
|
|
|
|
* don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
|
|
|
|
*/
|
|
|
|
class Shared_Cache extends Cache {
|
|
|
|
|
2013-02-20 05:42:48 +04:00
|
|
|
private $storage;
|
2012-12-16 04:44:46 +04:00
|
|
|
private $files = array();
|
|
|
|
|
2014-02-06 19:30:58 +04:00
|
|
|
/**
|
|
|
|
* @param \OC\Files\Storage\Shared $storage
|
|
|
|
*/
|
2012-12-29 00:06:12 +04:00
|
|
|
public function __construct($storage) {
|
2013-02-20 05:42:48 +04:00
|
|
|
$this->storage = $storage;
|
2012-12-29 00:06:12 +04:00
|
|
|
}
|
|
|
|
|
2012-12-16 04:44:46 +04:00
|
|
|
/**
|
2014-05-19 19:50:53 +04:00
|
|
|
* Get the source cache of a shared file or folder
|
2013-01-29 00:25:19 +04:00
|
|
|
* @param string $target Shared target file path
|
|
|
|
* @return \OC\Files\Cache\Cache
|
|
|
|
*/
|
2012-12-16 04:44:46 +04:00
|
|
|
private function getSourceCache($target) {
|
2014-04-08 21:57:07 +04:00
|
|
|
if ($target === false || $target === $this->storage->getMountPoint()) {
|
2014-04-02 14:04:51 +04:00
|
|
|
$target = '';
|
|
|
|
}
|
2014-04-14 13:33:10 +04:00
|
|
|
$source = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getItemType());
|
2013-03-08 23:27:30 +04:00
|
|
|
if (isset($source['path']) && isset($source['fileOwner'])) {
|
|
|
|
\OC\Files\Filesystem::initMountPoints($source['fileOwner']);
|
2014-04-15 18:36:05 +04:00
|
|
|
$mounts = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
|
2014-04-21 14:35:52 +04:00
|
|
|
if (is_array($mounts) and !empty($mounts)) {
|
2014-04-15 18:36:05 +04:00
|
|
|
$fullPath = $mounts[0]->getMountPoint() . $source['path'];
|
2013-03-08 23:27:30 +04:00
|
|
|
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($fullPath);
|
|
|
|
if ($storage) {
|
|
|
|
$this->files[$target] = $internalPath;
|
|
|
|
$cache = $storage->getCache();
|
|
|
|
$this->storageId = $storage->getId();
|
|
|
|
$this->numericId = $cache->getNumericStorageId();
|
|
|
|
return $cache;
|
|
|
|
}
|
2012-12-29 00:06:12 +04:00
|
|
|
}
|
2012-12-16 04:44:46 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-03 01:47:11 +04:00
|
|
|
public function getNumericStorageId() {
|
|
|
|
if (isset($this->numericId)) {
|
|
|
|
return $this->numericId;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-16 04:44:46 +04:00
|
|
|
/**
|
|
|
|
* get the stored metadata of a file or folder
|
|
|
|
*
|
2014-05-15 16:19:32 +04:00
|
|
|
* @param string|int $file
|
2012-12-16 04:44:46 +04:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get($file) {
|
2014-04-04 19:45:53 +04:00
|
|
|
if (is_string($file)) {
|
2014-04-30 19:30:22 +04:00
|
|
|
$cache = $this->getSourceCache($file);
|
|
|
|
if ($cache) {
|
2014-04-08 18:37:34 +04:00
|
|
|
$data = $cache->get($this->files[$file]);
|
|
|
|
$data['displayname_owner'] = \OC_User::getDisplayName($this->storage->getSharedFrom());
|
2014-04-25 16:04:22 +04:00
|
|
|
$data['path'] = $file;
|
2014-04-17 17:54:45 +04:00
|
|
|
if ($file === '') {
|
|
|
|
$data['is_share_mount_point'] = true;
|
|
|
|
}
|
2014-04-25 14:28:10 +04:00
|
|
|
$data['uid_owner'] = $this->storage->getOwner($file);
|
2014-04-08 18:37:34 +04:00
|
|
|
return $data;
|
2012-12-16 04:44:46 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-04-30 19:30:22 +04:00
|
|
|
$sourceId = $file;
|
2014-04-04 20:32:49 +04:00
|
|
|
// if we are at the root of the mount point we want to return the
|
|
|
|
// cache information for the source item
|
2014-04-30 19:30:22 +04:00
|
|
|
if (!is_int($sourceId) || $sourceId === 0) {
|
|
|
|
$sourceId = $this->storage->getSourceId();
|
2014-04-04 20:32:49 +04:00
|
|
|
}
|
2012-12-16 04:44:46 +04:00
|
|
|
$query = \OC_DB::prepare(
|
2013-02-15 01:37:49 +04:00
|
|
|
'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`,'
|
2014-06-03 19:57:56 +04:00
|
|
|
. ' `size`, `mtime`, `encrypted`, `unencrypted_size`, `storage_mtime`, `etag`, `permissions`'
|
2014-03-28 18:26:15 +04:00
|
|
|
. ' FROM `*PREFIX*filecache` WHERE `fileid` = ?');
|
2014-04-30 19:30:22 +04:00
|
|
|
$result = $query->execute(array($sourceId));
|
2012-12-16 04:44:46 +04:00
|
|
|
$data = $result->fetchRow();
|
|
|
|
$data['fileid'] = (int)$data['fileid'];
|
|
|
|
$data['mtime'] = (int)$data['mtime'];
|
2013-10-25 14:39:21 +04:00
|
|
|
$data['storage_mtime'] = (int)$data['storage_mtime'];
|
2012-12-16 04:44:46 +04:00
|
|
|
$data['encrypted'] = (bool)$data['encrypted'];
|
2013-01-08 00:27:22 +04:00
|
|
|
$data['mimetype'] = $this->getMimetype($data['mimetype']);
|
|
|
|
$data['mimepart'] = $this->getMimetype($data['mimepart']);
|
2013-11-05 00:23:10 +04:00
|
|
|
if ($data['storage_mtime'] === 0) {
|
2013-10-25 14:39:21 +04:00
|
|
|
$data['storage_mtime'] = $data['mtime'];
|
|
|
|
}
|
2014-02-06 19:01:42 +04:00
|
|
|
if ($data['encrypted'] or ($data['unencrypted_size'] > 0 and $data['mimetype'] === 'httpd/unix-directory')) {
|
|
|
|
$data['encrypted_size'] = (int)$data['size'];
|
|
|
|
$data['size'] = (int)$data['unencrypted_size'];
|
|
|
|
} else {
|
|
|
|
$data['size'] = (int)$data['size'];
|
|
|
|
}
|
2014-06-03 19:57:56 +04:00
|
|
|
$data['permissions'] = (int)$data['permissions'];
|
2014-04-25 16:04:22 +04:00
|
|
|
if (!is_int($file) || $file === 0) {
|
|
|
|
$data['path'] = '';
|
2014-04-30 19:30:22 +04:00
|
|
|
$data['name'] = basename($this->storage->getMountPoint());
|
2014-04-17 17:54:45 +04:00
|
|
|
$data['is_share_mount_point'] = true;
|
2014-04-04 20:32:49 +04:00
|
|
|
}
|
2012-12-16 04:44:46 +04:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the metadata of all files stored in $folder
|
|
|
|
*
|
|
|
|
* @param string $folder
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getFolderContents($folder) {
|
2014-01-22 19:54:17 +04:00
|
|
|
|
2014-04-02 14:04:51 +04:00
|
|
|
if ($folder === false) {
|
|
|
|
$folder = '';
|
|
|
|
}
|
|
|
|
|
2014-04-15 22:18:04 +04:00
|
|
|
$dir = ($folder !== '') ? $folder . '/' : '';
|
2014-04-08 21:57:07 +04:00
|
|
|
|
2014-04-02 14:04:51 +04:00
|
|
|
$cache = $this->getSourceCache($folder);
|
|
|
|
if ($cache) {
|
|
|
|
$parent = $this->storage->getFile($folder);
|
|
|
|
$sourceFolderContent = $cache->getFolderContents($this->files[$folder]);
|
|
|
|
foreach ($sourceFolderContent as $key => $c) {
|
2014-04-15 22:18:04 +04:00
|
|
|
$sourceFolderContent[$key]['path'] = $dir . $c['name'];
|
2014-04-02 14:04:51 +04:00
|
|
|
$sourceFolderContent[$key]['uid_owner'] = $parent['uid_owner'];
|
|
|
|
$sourceFolderContent[$key]['displayname_owner'] = $parent['uid_owner'];
|
2012-12-29 00:06:12 +04:00
|
|
|
}
|
2014-04-02 14:04:51 +04:00
|
|
|
|
|
|
|
return $sourceFolderContent;
|
2012-12-16 04:44:46 +04:00
|
|
|
}
|
2014-04-02 14:04:51 +04:00
|
|
|
|
2012-12-29 00:06:12 +04:00
|
|
|
return false;
|
2012-12-16 04:44:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* store meta data for a file or folder
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return int file id
|
|
|
|
*/
|
|
|
|
public function put($file, array $data) {
|
2014-04-11 13:18:50 +04:00
|
|
|
$file = ($file === false) ? '' : $file;
|
|
|
|
if ($cache = $this->getSourceCache($file)) {
|
2013-01-01 21:10:38 +04:00
|
|
|
return $cache->put($this->files[$file], $data);
|
2012-12-16 04:44:46 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the file id for a file
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getId($file) {
|
2014-04-08 21:57:07 +04:00
|
|
|
if ($file === false) {
|
|
|
|
return $this->storage->getSourceId();
|
|
|
|
}
|
|
|
|
$cache = $this->getSourceCache($file);
|
|
|
|
if ($cache) {
|
2012-12-16 04:44:46 +04:00
|
|
|
return $cache->getId($this->files[$file]);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-01-08 05:52:51 +04:00
|
|
|
/**
|
|
|
|
* check if a file is available in the cache
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function inCache($file) {
|
|
|
|
if ($file == '') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return parent::inCache($file);
|
|
|
|
}
|
|
|
|
|
2012-12-16 04:44:46 +04:00
|
|
|
/**
|
|
|
|
* remove a file or folder from the cache
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
*/
|
|
|
|
public function remove($file) {
|
2014-04-11 13:54:14 +04:00
|
|
|
$file = ($file === false) ? '' : $file;
|
2012-12-16 04:44:46 +04:00
|
|
|
if ($cache = $this->getSourceCache($file)) {
|
|
|
|
$cache->remove($this->files[$file]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move a file or folder in the cache
|
|
|
|
*
|
|
|
|
* @param string $source
|
|
|
|
* @param string $target
|
|
|
|
*/
|
|
|
|
public function move($source, $target) {
|
|
|
|
if ($cache = $this->getSourceCache($source)) {
|
2014-04-14 13:33:10 +04:00
|
|
|
$file = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getItemType());
|
2013-05-02 04:29:07 +04:00
|
|
|
if ($file && isset($file['path'])) {
|
|
|
|
$cache->move($this->files[$source], $file['path']);
|
2012-12-16 04:44:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* remove all entries for files that are stored on the storage from the cache
|
|
|
|
*/
|
|
|
|
public function clear() {
|
|
|
|
// Not a valid action for Shared Cache
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file
|
|
|
|
*
|
|
|
|
* @return int, Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
|
|
|
|
*/
|
|
|
|
public function getStatus($file) {
|
2013-01-01 20:19:33 +04:00
|
|
|
if ($file == '') {
|
|
|
|
return self::COMPLETE;
|
|
|
|
}
|
2012-12-16 04:44:46 +04:00
|
|
|
if ($cache = $this->getSourceCache($file)) {
|
|
|
|
return $cache->getStatus($this->files[$file]);
|
|
|
|
}
|
2013-01-11 07:29:47 +04:00
|
|
|
return self::NOT_FOUND;
|
2012-12-16 04:44:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* search for files matching $pattern
|
|
|
|
*
|
|
|
|
* @param string $pattern
|
|
|
|
* @return array of file data
|
|
|
|
*/
|
|
|
|
public function search($pattern) {
|
2013-07-26 16:11:59 +04:00
|
|
|
|
2013-10-30 18:48:38 +04:00
|
|
|
$where = '`name` LIKE ? AND ';
|
|
|
|
|
2013-07-26 16:11:59 +04:00
|
|
|
// normalize pattern
|
2013-10-30 18:48:38 +04:00
|
|
|
$value = $this->normalize($pattern);
|
2013-07-26 16:11:59 +04:00
|
|
|
|
2013-10-30 18:48:38 +04:00
|
|
|
return $this->searchWithWhere($where, $value);
|
2013-07-31 17:13:00 +04:00
|
|
|
|
2012-12-16 04:44:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* search for files by mimetype
|
|
|
|
*
|
2013-10-30 18:48:38 +04:00
|
|
|
* @param string $mimetype
|
2012-12-16 04:44:46 +04:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function searchByMime($mimetype) {
|
2014-02-05 15:00:08 +04:00
|
|
|
$mimepart = null;
|
|
|
|
if (strpos($mimetype, '/') === false) {
|
|
|
|
$mimepart = $mimetype;
|
|
|
|
$mimetype = null;
|
2012-12-16 04:44:46 +04:00
|
|
|
}
|
2013-10-30 18:48:38 +04:00
|
|
|
|
2014-02-05 15:00:08 +04:00
|
|
|
// note: searchWithWhere is currently broken as it doesn't
|
|
|
|
// recurse into subdirs nor returns the correct
|
|
|
|
// file paths, so using getFolderContents() for now
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
$exploreDirs = array('');
|
|
|
|
while (count($exploreDirs) > 0) {
|
|
|
|
$dir = array_pop($exploreDirs);
|
|
|
|
$files = $this->getFolderContents($dir);
|
|
|
|
// no results?
|
|
|
|
if (!$files) {
|
2014-04-25 14:28:10 +04:00
|
|
|
// maybe it's a single shared file
|
|
|
|
$file = $this->get('');
|
|
|
|
if (($mimepart && $file['mimepart'] === $mimepart) || ($mimetype && $file['mimetype'] === $mimetype)) {
|
|
|
|
$result[] = $file;
|
|
|
|
}
|
2014-02-05 15:00:08 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file['mimetype'] === 'httpd/unix-directory') {
|
|
|
|
$exploreDirs[] = ltrim($dir . '/' . $file['name'], '/');
|
2014-03-28 18:26:15 +04:00
|
|
|
} else if (($mimepart && $file['mimepart'] === $mimepart) || ($mimetype && $file['mimetype'] === $mimetype)) {
|
2014-02-05 15:00:08 +04:00
|
|
|
$result[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
2013-10-30 18:48:38 +04:00
|
|
|
}
|
2014-01-22 19:54:17 +04:00
|
|
|
|
2013-10-30 18:48:38 +04:00
|
|
|
/**
|
|
|
|
* The maximum number of placeholders that can be used in an SQL query.
|
|
|
|
* Value MUST be <= 1000 for oracle:
|
|
|
|
* see ORA-01795 maximum number of expressions in a list is 1000
|
|
|
|
* FIXME we should get this from doctrine as other DBs allow a lot more placeholders
|
|
|
|
*/
|
|
|
|
const MAX_SQL_CHUNK_SIZE = 1000;
|
2014-01-22 19:54:17 +04:00
|
|
|
|
2013-10-30 18:48:38 +04:00
|
|
|
/**
|
|
|
|
* search for files with a custom where clause and value
|
|
|
|
* the $wherevalue will be array_merge()d with the file id chunks
|
|
|
|
*
|
|
|
|
* @param string $sqlwhere
|
|
|
|
* @param string $wherevalue
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function searchWithWhere($sqlwhere, $wherevalue, $chunksize = self::MAX_SQL_CHUNK_SIZE) {
|
|
|
|
|
2012-12-16 04:44:46 +04:00
|
|
|
$ids = $this->getAll();
|
2013-08-28 14:39:43 +04:00
|
|
|
|
|
|
|
$files = array();
|
2014-01-22 19:54:17 +04:00
|
|
|
|
2013-10-30 18:48:38 +04:00
|
|
|
// divide into chunks
|
|
|
|
$chunks = array_chunk($ids, $chunksize);
|
2014-01-22 19:54:17 +04:00
|
|
|
|
2013-08-28 14:39:43 +04:00
|
|
|
foreach ($chunks as $chunk) {
|
2013-10-30 18:48:38 +04:00
|
|
|
$placeholders = join(',', array_fill(0, count($chunk), '?'));
|
2013-08-28 14:39:43 +04:00
|
|
|
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
|
|
|
|
`encrypted`, `unencrypted_size`, `etag`
|
2013-10-30 18:48:38 +04:00
|
|
|
FROM `*PREFIX*filecache` WHERE ' . $sqlwhere . ' `fileid` IN (' . $placeholders . ')';
|
2014-01-22 19:54:17 +04:00
|
|
|
|
2013-10-30 18:48:38 +04:00
|
|
|
$stmt = \OC_DB::prepare($sql);
|
|
|
|
|
|
|
|
$result = $stmt->execute(array_merge(array($wherevalue), $chunk));
|
2013-08-28 14:39:43 +04:00
|
|
|
|
|
|
|
while ($row = $result->fetchRow()) {
|
2013-10-30 18:48:38 +04:00
|
|
|
if (substr($row['path'], 0, 6) === 'files/') {
|
|
|
|
$row['path'] = substr($row['path'], 6); // remove 'files/' from path as it's relative to '/Shared'
|
2013-08-28 23:10:06 +04:00
|
|
|
}
|
|
|
|
$row['mimetype'] = $this->getMimetype($row['mimetype']);
|
|
|
|
$row['mimepart'] = $this->getMimetype($row['mimepart']);
|
2014-02-06 19:01:42 +04:00
|
|
|
if ($row['encrypted'] or ($row['unencrypted_size'] > 0 and $row['mimetype'] === 'httpd/unix-directory')) {
|
|
|
|
$row['encrypted_size'] = $row['size'];
|
|
|
|
$row['size'] = $row['unencrypted_size'];
|
|
|
|
}
|
2013-08-28 23:10:06 +04:00
|
|
|
$files[] = $row;
|
2013-08-28 14:39:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $files;
|
2012-12-16 04:44:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the size of a folder and set it in the cache
|
|
|
|
*
|
|
|
|
* @param string $path
|
2014-02-28 17:23:07 +04:00
|
|
|
* @param array $entry (optional) meta data of the folder
|
2012-12-16 04:44:46 +04:00
|
|
|
* @return int
|
|
|
|
*/
|
2014-02-28 17:23:07 +04:00
|
|
|
public function calculateFolderSize($path, $entry = null) {
|
2014-04-11 13:18:50 +04:00
|
|
|
$path = ($path === false) ? '' : $path;
|
2012-12-16 04:44:46 +04:00
|
|
|
if ($cache = $this->getSourceCache($path)) {
|
|
|
|
return $cache->calculateFolderSize($this->files[$path]);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get all file ids on the files on the storage
|
|
|
|
*
|
|
|
|
* @return int[]
|
|
|
|
*/
|
|
|
|
public function getAll() {
|
2013-08-28 14:39:43 +04:00
|
|
|
$ids = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_ALL);
|
|
|
|
$folderBackend = \OCP\Share::getBackend('folder');
|
2013-09-24 12:37:58 +04:00
|
|
|
if ($folderBackend instanceof Share_Backend_Collection) {
|
|
|
|
foreach ($ids as $file) {
|
|
|
|
/** @var $folderBackend Share_Backend_Collection */
|
|
|
|
$children = $folderBackend->getChildren($file);
|
|
|
|
foreach ($children as $child) {
|
|
|
|
$ids[] = (int)$child['source'];
|
|
|
|
}
|
|
|
|
|
2013-08-28 14:39:43 +04:00
|
|
|
}
|
|
|
|
}
|
2013-09-24 12:37:58 +04:00
|
|
|
|
2013-08-28 14:39:43 +04:00
|
|
|
return $ids;
|
2012-12-16 04:44:46 +04:00
|
|
|
}
|
|
|
|
|
2013-05-03 01:47:11 +04:00
|
|
|
/**
|
|
|
|
* find a folder in the cache which has not been fully scanned
|
|
|
|
*
|
|
|
|
* If multiply 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
|
|
|
|
*
|
2014-02-19 12:31:54 +04:00
|
|
|
* @return boolean the path of the folder or false when no folder matched
|
2013-05-03 01:47:11 +04:00
|
|
|
*/
|
|
|
|
public function getIncomplete() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-31 16:29:55 +04:00
|
|
|
/**
|
2014-04-15 13:19:31 +04:00
|
|
|
* get the path of a file on this storage relative to the mount point by it's id
|
2014-03-31 16:29:55 +04:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @param string $pathEnd (optional) used internally for recursive calls
|
2014-05-16 00:47:28 +04:00
|
|
|
* @return string|null
|
2014-03-31 16:29:55 +04:00
|
|
|
*/
|
2014-03-28 18:26:15 +04:00
|
|
|
public function getPathById($id, $pathEnd = '') {
|
|
|
|
// direct shares are easy
|
2014-04-15 13:19:31 +04:00
|
|
|
$path = $this->getShareById($id);
|
|
|
|
if (is_string($path)) {
|
|
|
|
return ltrim($pathEnd, '/');
|
2014-03-28 18:26:15 +04:00
|
|
|
} else {
|
|
|
|
// if the item is a direct share we try and get the path of the parent and append the name of the item to it
|
|
|
|
list($parent, $name) = $this->getParentInfo($id);
|
|
|
|
if ($parent > 0) {
|
|
|
|
return $this->getPathById($parent, '/' . $name . $pathEnd);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-14 19:49:27 +04:00
|
|
|
/**
|
|
|
|
* @param integer $id
|
|
|
|
*/
|
2014-03-28 18:26:15 +04:00
|
|
|
private function getShareById($id) {
|
|
|
|
$item = \OCP\Share::getItemSharedWithBySource('file', $id);
|
|
|
|
if ($item) {
|
|
|
|
return trim($item['file_target'], '/');
|
|
|
|
}
|
|
|
|
$item = \OCP\Share::getItemSharedWithBySource('folder', $id);
|
|
|
|
if ($item) {
|
|
|
|
return trim($item['file_target'], '/');
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-04-14 19:49:27 +04:00
|
|
|
/**
|
|
|
|
* @param integer $id
|
|
|
|
*/
|
2014-03-28 18:26:15 +04:00
|
|
|
private function getParentInfo($id) {
|
|
|
|
$sql = 'SELECT `parent`, `name` FROM `*PREFIX*filecache` WHERE `fileid` = ?';
|
|
|
|
$query = \OC_DB::prepare($sql);
|
|
|
|
$result = $query->execute(array($id));
|
|
|
|
if ($row = $result->fetchRow()) {
|
|
|
|
return array($row['parent'], $row['name']);
|
|
|
|
} else {
|
|
|
|
return array(-1, '');
|
|
|
|
}
|
|
|
|
}
|
2013-08-18 13:02:08 +04:00
|
|
|
}
|