From bfa914d8b2176841bfe9968b340a3c63af4f5187 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Sat, 9 Nov 2013 17:29:12 +0300 Subject: [PATCH] Make sure fs has subdir documents always --- ajax/documentController.php | 3 +-- ajax/sessionController.php | 4 ++-- appinfo/version | 2 +- lib/db/session.php | 23 +++++++-------------- lib/download.php | 13 ++++++++---- lib/download/range.php | 4 ++-- lib/download/simple.php | 4 ++-- lib/view.php | 40 ------------------------------------- 8 files changed, 24 insertions(+), 69 deletions(-) diff --git a/ajax/documentController.php b/ajax/documentController.php index 560d98da..ae186611 100644 --- a/ajax/documentController.php +++ b/ajax/documentController.php @@ -52,8 +52,7 @@ class DocumentController extends Controller{ } $filename = isset($sessionData['genesis_url']) ? $sessionData['genesis_url'] : ''; - $documentsView = new View('/' . $sessionData['owner']); - $download = new Download($documentsView->initDocumentsView($sessionData['owner']), $filename); + $download = new Download($sessionData['owner'], $filename); $download->sendResponse(); } diff --git a/ajax/sessionController.php b/ajax/sessionController.php index 4af868d5..34464dad 100644 --- a/ajax/sessionController.php +++ b/ajax/sessionController.php @@ -41,7 +41,7 @@ class SessionController extends Controller{ } } - /** + /** * Store the document content to its origin */ public static function save(){ @@ -58,7 +58,7 @@ class SessionController extends Controller{ if (!$content){ throw new \Exception('New conent missing'); } - + $session = new Db_Session(); $session->load($esId); diff --git a/appinfo/version b/appinfo/version index 0e2c9395..7deb86fe 100755 --- a/appinfo/version +++ b/appinfo/version @@ -1 +1 @@ -0.7 \ No newline at end of file +0.7.1 \ No newline at end of file diff --git a/lib/db/session.php b/lib/db/session.php index ba5c7781..7002c2b2 100644 --- a/lib/db/session.php +++ b/lib/db/session.php @@ -39,28 +39,19 @@ class Db_Session extends \OCA\Documents\Db { list($ownerView, $path) = $file->getOwnerViewAndPath(); // Create a directory to store genesis - $docView = $ownerView->initDocumentsView($file->getOwner()); + + $genesis = new Genesis($ownerView, $path, $file->getOwner()); $oldSession = new Db_Session(); $oldSession->loadBy('file_id', $file->getFileId()); //If there is no existing session we need to start a new one if (!$oldSession->hasData()){ - - //TODO: check if genesis document is a valid odt - $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($file->getOwner(), $genesisPath); - $newSession = new Db_Session(array( - $genesisPath, $hash, $file->getOwner(), $file->getFileId() + $genesis->getPath(), + $genesis->getHash(), + $file->getOwner(), + $file->getFileId() )); if (!$newSession->insert()){ @@ -71,7 +62,7 @@ class Db_Session extends \OCA\Documents\Db { $session = $oldSession ->loadBy('file_id', $file->getFileId()) ->getData() - ; + ; $member = new Db_Member(array( $session['es_id'], diff --git a/lib/download.php b/lib/download.php index a7b0f1d0..6d4ff3d2 100644 --- a/lib/download.php +++ b/lib/download.php @@ -39,15 +39,20 @@ class Download { * @param type $view - filesystem view * @param type $filepath - path to the file relative to this view root */ - public function __construct($view, $filepath){ + public function __construct($owner, $filepath){ $this->filepath = $filepath; - $this->view = $view; if (isset($_SERVER['HTTP_RANGE'])) { - $this->instance = new Download_Range($view, $filepath); + $this->instance = new Download_Range($owner, $filepath); } else { - $this->instance = new Download_Simple($view, $filepath); + $this->instance = new Download_Simple($owner, $filepath); } + + $this->view = $this->getView($owner); + } + + protected function getView($owner){ + return new View('/' . $owner); } /** diff --git a/lib/download/range.php b/lib/download/range.php index 5947db4b..d7ab37e0 100644 --- a/lib/download/range.php +++ b/lib/download/range.php @@ -26,8 +26,8 @@ class Download_Range extends \OCA\Documents\Download { * @param type $view - filesystem view * @param type $filepath - path to the file relative to this view root */ - public function __construct($view, $filepath){ - $this->view = $view; + public function __construct($owner, $filepath){ + $this->view = $this->getView($owner); $this->filepath = $filepath; } diff --git a/lib/download/simple.php b/lib/download/simple.php index 1f35bf52..61255e1d 100644 --- a/lib/download/simple.php +++ b/lib/download/simple.php @@ -16,8 +16,8 @@ namespace OCA\Documents; */ class Download_Simple extends \OCA\Documents\Download { - public function __construct($view, $filepath){ - $this->view = $view; + public function __construct($owner, $filepath){ + $this->view = $this->getView($owner); $this->filepath = $filepath; } diff --git a/lib/view.php b/lib/view.php index 3f6ea8fd..3250b19e 100644 --- a/lib/view.php +++ b/lib/view.php @@ -12,16 +12,6 @@ namespace OCA\Documents; class View extends \OC\Files\View{ - const DOCUMENTS_DIRNAME='/documents'; - protected static $documentsView; - - public function initDocumentsView($owner){ - $ownerView = new View('/' . $owner); - if (!$ownerView->is_dir(self::DOCUMENTS_DIRNAME)) { - $ownerView->mkdir(self::DOCUMENTS_DIRNAME); - } - return new View('/' . $owner . self::DOCUMENTS_DIRNAME); - } public function getFilePermissions($path){ $permissions = 0; @@ -33,35 +23,5 @@ class View extends \OC\Files\View{ } return $permissions; } - - 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'); - } - - if (!$ownerView->is_file($filePath)){ - throw new \Exception('Object ' . $filePath . ' is not a file.'); - } - - $newName = '/' . sha1($ownerView->file_get_contents($filePath)) . '.odt'; - - $ownerView->copy($filePath, self::DOCUMENTS_DIRNAME . $newName); - if (!$ownerView->file_exists(self::DOCUMENTS_DIRNAME . $newName)){ - throw new \Exception('Failed to copy genesis'); - } - - \OC_FileProxy::$enabled = $proxyStatus; - return $newName; - } - public function getHashByGenesis($owner, $genesisPath){ - $ownerView = new View('/' . $owner); - return sha1($ownerView->file_get_contents(self::DOCUMENTS_DIRNAME . $genesisPath)); - } }