Cleanup file and storage models

pull/1/head
Victor Dubiniuk 9 years ago
parent 61d2a6cb6f
commit a6be42cb26

@ -27,19 +27,23 @@ use \OC\Files\View;
class File {
protected $fileId;
protected $owner;
protected $path;
protected $sharing;
protected $token ='';
protected $passwordProtected = false;
protected $ownerView;
protected $ownerViewFiles;
protected $path;
protected $pathFiles;
public function __construct($fileId, $shareOps = null){
public function __construct($fileId, $shareOps = null, $token = null){
if (!$fileId){
throw new \Exception('No valid file has been passed');
}
$this->fileId = $fileId;
$this->sharing = $shareOps;
$this->token = $token;
$this->initViews();
}
@ -52,8 +56,7 @@ class File {
throw new \Exception('This file was probably unshared');
}
$file = new File($rootLinkItem['file_source'], $rootLinkItem);
$file->setToken($token);
$file = new File($rootLinkItem['file_source'], $rootLinkItem, $token);
if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])){
$file->setPasswordProtected(true);
@ -70,14 +73,6 @@ class File {
return $this->fileId;
}
public function setOwner($owner){
$this->owner = $owner;
}
public function setPath($path){
$this->path = $path;
}
public function setToken($token){
$this->token = $token;
}
@ -136,7 +131,6 @@ class File {
public function setPasswordProtected($value){
$this->passwordProtected = $value;
}
/**
*
@ -144,9 +138,25 @@ class File {
* @throws \Exception
*/
public function getOwnerViewAndPath($useDefaultRoot = false){
if ($this->isPublicShare()){
return $useDefaultRoot ? [$this->ownerViewFiles, $this->pathFiles] : [$this->ownerView, $this->path];
}
public function getOwner(){
return $this->owner;
}
public function getOwnerView($relativeToFiles = false){
return $relativeToFiles ? $this->ownerViewFiles : $this->ownerView;
}
public function getPath($relativeToFiles = false){
return $relativeToFiles ? $this->pathFiles : $this->path;
}
protected function initViews(){
if ($this->isPublicShare()) {
if (isset($this->sharing['uid_owner'])){
$owner = $this->sharing['uid_owner'];
$this->owner = $this->sharing['uid_owner'];
if (!\OC::$server->getUserManager()->userExists($this->sharing['uid_owner'])) {
throw new \Exception('Share owner' . $this->sharing['uid_owner'] . ' does not exist ');
}
@ -156,39 +166,28 @@ class File {
} else {
throw new \Exception($this->fileId . ' is a broken share');
}
$view = new View('/' . $owner . '/files');
} else {
$owner = \OC::$server->getUserSession()->getUser()->getUID();
$root = '/' . $owner;
if ($useDefaultRoot){
$root .= '/' . 'files';
}
$view = new View($root);
$this->owner = \OC::$server->getUserSession()->getUser()->getUID();
}
$path = $view->getPath($this->fileId);
if (!$path){
$this->ownerView = new View('/' . $this->owner);
$this->ownerViewFiles = new View('/' . $this->owner . '/files');
$this->path = $this->ownerView->getPath($this->fileId);
$this->pathFiles = $this->ownerViewFiles->getPath($this->fileId);
if (!$this->path || !$this->pathFiles) {
throw new \Exception($this->fileId . ' can not be resolved');
}
$this->path = $path;
$this->owner = $owner;
if (!$view->file_exists($this->path)){
if (!$this->ownerView->file_exists($this->path)) {
throw new \Exception($this->path . ' doesn\'t exist');
}
return array($view, $this->path);
}
public function getOwner(){
if (!$this->owner){
$this->getOwnerViewAndPath();
if (!$this->ownerViewFiles->file_exists($this->pathFiles)) {
throw new \Exception($this->pathFiles . ' doesn\'t exist');
}
return $this->owner;
}
protected function getPassword(){
return $this->sharing['share_with'];
}

@ -100,7 +100,7 @@ class Storage {
public static function getSupportedMimetypes(){
return array_merge(
array(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR),
Filter::getAll()
Filter::getAll()
);
}
}

Loading…
Cancel
Save