diff --git a/lib/db/session.php b/lib/db/session.php index 93fa1015..82b07387 100644 --- a/lib/db/session.php +++ b/lib/db/session.php @@ -48,12 +48,16 @@ class Db_Session extends \OCA\Documents\Db { if (!$oldSession->hasData()){ //TODO: check if genesis document is a valid odt - $genesisPath = $ownerView->storeDocument($ownerView, $path); + $genesisPath = $ownerView->storeDocument( + $file->getOwner(), + $path + ); + if (!$genesisPath){ throw new \Exception('Unable to copy document. Check permissions and make sure you have enought free space.'); } - $hash = $ownerView->getHashByGenesis($genesisPath); + $hash = $ownerView->getHashByGenesis($file->getOwner(), $genesisPath); $newSession = new Db_Session(array( $genesisPath, $hash, $file->getOwner(), $file->getFileId() diff --git a/lib/file.php b/lib/file.php index 31e2a523..7b1befe9 100644 --- a/lib/file.php +++ b/lib/file.php @@ -103,7 +103,15 @@ class File { $this->owner = $owner; } - $view = new View('/' . $this->owner); + /* to emit hooks properly, view root should contain /user/files */ + + if (strpos($this->path, 'files') === 0){ + $this->path = preg_replace('|^files|', '', $this->path); + $view = new View('/' . $this->owner . '/files'); + } else { + $view = new View('/' . $this->owner); + } + if (!$view->file_exists($this->path)){ throw new \Exception($this->path . ' doesn\'t exist'); } diff --git a/lib/view.php b/lib/view.php index 898e44e3..fc483ba9 100644 --- a/lib/view.php +++ b/lib/view.php @@ -34,10 +34,13 @@ class View extends \OC\Files\View{ return $permissions; } - public function storeDocument($ownerView, $filePath){ + public function storeDocument($owner, $filePath){ $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; + $ownerView = new View('/' . $owner); + $filePath = '/files' . $filePath; + if (!$ownerView->file_exists($filePath)){ throw new \Exception($filePath . ' doesn\'t exist'); } @@ -57,7 +60,8 @@ class View extends \OC\Files\View{ return $newName; } - public function getHashByGenesis($genesisPath){ - return sha1($this->file_get_contents(self::DOCUMENTS_DIRNAME . $genesisPath)); + public function getHashByGenesis($owner, $genesisPath){ + $ownerView = new View('/' . $owner); + return sha1($ownerView->file_get_contents(self::DOCUMENTS_DIRNAME . $genesisPath)); } }