Improve shared files resolution. Fixes #162,#167
This commit is contained in:
parent
2b99ff0a63
commit
b7d71e025b
47
lib/file.php
47
lib/file.php
@ -58,7 +58,7 @@ class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($rootLinkItem['path']) && isset($rootLinkItem['file_target'])){
|
if (!isset($rootLinkItem['path']) && isset($rootLinkItem['file_target'])){
|
||||||
$rootLinkItem['path'] = 'files/' . $rootLinkItem['file_target'];
|
$rootLinkItem['path'] = $rootLinkItem['file_target'];
|
||||||
}
|
}
|
||||||
$file = new File($rootLinkItem['file_source'], array($rootLinkItem));
|
$file = new File($rootLinkItem['file_source'], array($rootLinkItem));
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ class File {
|
|||||||
\OC_Util::tearDownFS();
|
\OC_Util::tearDownFS();
|
||||||
\OC_Util::setupFS($rootLinkItem['uid_owner']);
|
\OC_Util::setupFS($rootLinkItem['uid_owner']);
|
||||||
$file->setOwner($rootLinkItem['uid_owner']);
|
$file->setOwner($rootLinkItem['uid_owner']);
|
||||||
$file->setPath('/files' . \OC\Files\Filesystem::getPath($linkItem['file_source']));
|
$file->setPath(\OC\Files\Filesystem::getPath($linkItem['file_source']));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])){
|
if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])){
|
||||||
@ -169,37 +169,26 @@ class File {
|
|||||||
*/
|
*/
|
||||||
public function getOwnerViewAndPath(){
|
public function getOwnerViewAndPath(){
|
||||||
if (!$this->owner || !$this->path){
|
if (!$this->owner || !$this->path){
|
||||||
$info = $this->getSharedFileOwnerAndPath();
|
if ($this->isPublicShare()){
|
||||||
if (is_array($info) && count($info)){
|
list($owner, $path) = $this->getSharedFileOwnerAndPath();
|
||||||
$owner = $info[0];
|
|
||||||
$path = $info[1];
|
|
||||||
} else {
|
} else {
|
||||||
list($owner, $path) = $this->getLocalFileOwnerAndPath();
|
$owner = \OCP\User::getUser();
|
||||||
}
|
$path = Storage::resolvePath($this->fileId);
|
||||||
|
|
||||||
if (!$path){
|
if (!$path){
|
||||||
throw new \Exception($this->fileId . ' can not be resolved');
|
throw new \Exception($this->fileId . ' can not be resolved');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
$this->owner = $owner;
|
$this->owner = $owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* to emit hooks properly, view root should contain /user/files */
|
|
||||||
|
|
||||||
if (strpos($this->path, 'files') === 0){
|
|
||||||
$path = preg_replace('|^files|', '', $this->path);
|
|
||||||
$view = new View('/' . $this->owner . '/files');
|
$view = new View('/' . $this->owner . '/files');
|
||||||
} else {
|
if (!$view->file_exists($this->path)){
|
||||||
$path = $this->path;
|
|
||||||
$view = new View('/' . $this->owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$view->file_exists($path)){
|
|
||||||
throw new \Exception($this->path . ' doesn\'t exist');
|
throw new \Exception($this->path . ' doesn\'t exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($view, $path);
|
return array($view, $this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOwner(){
|
public function getOwner(){
|
||||||
@ -209,19 +198,29 @@ class File {
|
|||||||
return $this->owner;
|
return $this->owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public links only
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function getSharedFileOwnerAndPath(){
|
protected function getSharedFileOwnerAndPath(){
|
||||||
$result = array();
|
|
||||||
foreach ($this->sharing as $share){
|
foreach ($this->sharing as $share){
|
||||||
|
$rootLinkItem = \OCP\Share::resolveReShare($share);
|
||||||
|
if (isset($rootLinkItem['uid_owner'])){
|
||||||
|
$owner = $rootLinkItem['uid_owner'];
|
||||||
|
} else {
|
||||||
|
$owner = false;
|
||||||
|
}
|
||||||
|
\OC_Util::tearDownFS();
|
||||||
|
\OC_Util::setupFS($owner);
|
||||||
return array(
|
return array(
|
||||||
$share['uid_owner'],
|
$owner,
|
||||||
$share['path']
|
\OC\Files\Filesystem::getPath($rootLinkItem['file_source'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function getLocalFileOwnerAndPath(){
|
protected function getLocalFileOwnerAndPath(){
|
||||||
$fileInfo = \OC\Files\Cache\Cache::getById($this->fileId);
|
$fileInfo = \OC\Files\Cache\Cache::getById($this->fileId);
|
||||||
$owner = \OCP\User::getUser();
|
$owner = \OCP\User::getUser();
|
||||||
|
@ -41,6 +41,20 @@ class Storage {
|
|||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function resolvePath($fileId){
|
||||||
|
$list = array_filter(
|
||||||
|
\OCP\Files::searchByMime('application/vnd.oasis.opendocument.text'),
|
||||||
|
function($item) use ($fileId){
|
||||||
|
return intval($item['fileid'])==$fileId;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (count($list)>0){
|
||||||
|
$item = current($list);
|
||||||
|
return $item['path'];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Cleanup session data on removing the document
|
* @brief Cleanup session data on removing the document
|
||||||
* @param array
|
* @param array
|
||||||
|
Loading…
x
Reference in New Issue
Block a user