diff options
author | blizzz <blizzz@owncloud.com> | 2014-07-15 19:49:36 +0200 |
---|---|---|
committer | blizzz <blizzz@owncloud.com> | 2014-07-15 19:49:36 +0200 |
commit | 10b59f101f324dc1379d48b6a7d3daeb48de7e08 (patch) | |
tree | fc8ae0ce819bf1659d255f6cc5eec59aee83da18 | |
parent | d22904612b6c76fd05d677ac4aa054500df30f11 (diff) | |
parent | 8f11019f4562ba2eb483421f3a62c7f7f7db0ed9 (diff) | |
download | nextcloud-server-10b59f101f324dc1379d48b6a7d3daeb48de7e08.tar.gz nextcloud-server-10b59f101f324dc1379d48b6a7d3daeb48de7e08.zip |
Merge pull request #9540 from owncloud/use_fileinfo_in_search_results
use fileinfo object in search results
-rw-r--r-- | lib/private/search/result/file.php | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/lib/private/search/result/file.php b/lib/private/search/result/file.php index da5fa64ef45..331fdaa383a 100644 --- a/lib/private/search/result/file.php +++ b/lib/private/search/result/file.php @@ -18,7 +18,9 @@ */ namespace OC\Search\Result; -use \OC\Files\Filesystem; +use OC\Files\Filesystem; +use OCP\Files\FileInfo; + /** * A found file */ @@ -63,49 +65,36 @@ class File extends \OCP\Search\Result { /** * Create a new file search result - * @param array $data file data given by provider + * @param FileInfo $data file data given by provider */ - public function __construct(array $data = null) { - $info = pathinfo($data['path']); - $this->id = $data['fileid']; + public function __construct(FileInfo $data) { + + $path = $this->getRelativePath($data->getPath()); + + $info = pathinfo($path); + $this->id = $data->getId(); $this->name = $info['basename']; $this->link = \OCP\Util::linkTo( 'files', 'index.php', array('dir' => $info['dirname'], 'file' => $info['basename']) ); - $this->permissions = self::get_permissions($data['path']); - $this->path = (strpos($data['path'], 'files') === 0) ? substr($data['path'], 5) : $data['path']; - $this->size = $data['size']; - $this->modified = $data['mtime']; - $this->mime_type = $data['mimetype']; + $this->permissions = $data->getPermissions(); + $this->path = $path; + $this->size = $data->getSize(); + $this->modified = $data->getMtime(); + $this->mime_type = $data->getMimetype(); } /** - * Determine permissions for a given file path + * converts a path relative to the users files folder + * eg /user/files/foo.txt -> /foo.txt * @param string $path - * @return int + * @return string relative path */ - function get_permissions($path) { - // add read permissions - $permissions = \OCP\PERMISSION_READ; - // get directory - $fileinfo = pathinfo($path); - $dir = $fileinfo['dirname'] . '/'; - // add update permissions - if (Filesystem::isUpdatable($dir)) { - $permissions |= \OCP\PERMISSION_UPDATE; - } - // add delete permissions - if (Filesystem::isDeletable($dir)) { - $permissions |= \OCP\PERMISSION_DELETE; - } - // add share permissions - if (Filesystem::isSharable($dir)) { - $permissions |= \OCP\PERMISSION_SHARE; - } - // return - return $permissions; + protected function getRelativePath ($path) { + $root = \OC::$server->getUserFolder(); + return $root->getRelativePath($path); } - + } |