Make sure fs has subdir documents always
This commit is contained in:
parent
e63943cc52
commit
bfa914d8b2
@ -52,8 +52,7 @@ class DocumentController extends Controller{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$filename = isset($sessionData['genesis_url']) ? $sessionData['genesis_url'] : '';
|
$filename = isset($sessionData['genesis_url']) ? $sessionData['genesis_url'] : '';
|
||||||
$documentsView = new View('/' . $sessionData['owner']);
|
$download = new Download($sessionData['owner'], $filename);
|
||||||
$download = new Download($documentsView->initDocumentsView($sessionData['owner']), $filename);
|
|
||||||
$download->sendResponse();
|
$download->sendResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
0.7
|
0.7.1
|
@ -39,28 +39,19 @@ class Db_Session extends \OCA\Documents\Db {
|
|||||||
list($ownerView, $path) = $file->getOwnerViewAndPath();
|
list($ownerView, $path) = $file->getOwnerViewAndPath();
|
||||||
|
|
||||||
// Create a directory to store genesis
|
// Create a directory to store genesis
|
||||||
$docView = $ownerView->initDocumentsView($file->getOwner());
|
|
||||||
|
$genesis = new Genesis($ownerView, $path, $file->getOwner());
|
||||||
|
|
||||||
$oldSession = new Db_Session();
|
$oldSession = new Db_Session();
|
||||||
$oldSession->loadBy('file_id', $file->getFileId());
|
$oldSession->loadBy('file_id', $file->getFileId());
|
||||||
|
|
||||||
//If there is no existing session we need to start a new one
|
//If there is no existing session we need to start a new one
|
||||||
if (!$oldSession->hasData()){
|
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(
|
$newSession = new Db_Session(array(
|
||||||
$genesisPath, $hash, $file->getOwner(), $file->getFileId()
|
$genesis->getPath(),
|
||||||
|
$genesis->getHash(),
|
||||||
|
$file->getOwner(),
|
||||||
|
$file->getFileId()
|
||||||
));
|
));
|
||||||
|
|
||||||
if (!$newSession->insert()){
|
if (!$newSession->insert()){
|
||||||
|
@ -39,15 +39,20 @@ class Download {
|
|||||||
* @param type $view - filesystem view
|
* @param type $view - filesystem view
|
||||||
* @param type $filepath - path to the file relative to this view root
|
* @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->filepath = $filepath;
|
||||||
$this->view = $view;
|
|
||||||
|
|
||||||
if (isset($_SERVER['HTTP_RANGE'])) {
|
if (isset($_SERVER['HTTP_RANGE'])) {
|
||||||
$this->instance = new Download_Range($view, $filepath);
|
$this->instance = new Download_Range($owner, $filepath);
|
||||||
} else {
|
} 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,8 +26,8 @@ class Download_Range extends \OCA\Documents\Download {
|
|||||||
* @param type $view - filesystem view
|
* @param type $view - filesystem view
|
||||||
* @param type $filepath - path to the file relative to this view root
|
* @param type $filepath - path to the file relative to this view root
|
||||||
*/
|
*/
|
||||||
public function __construct($view, $filepath){
|
public function __construct($owner, $filepath){
|
||||||
$this->view = $view;
|
$this->view = $this->getView($owner);
|
||||||
$this->filepath = $filepath;
|
$this->filepath = $filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ namespace OCA\Documents;
|
|||||||
*/
|
*/
|
||||||
class Download_Simple extends \OCA\Documents\Download {
|
class Download_Simple extends \OCA\Documents\Download {
|
||||||
|
|
||||||
public function __construct($view, $filepath){
|
public function __construct($owner, $filepath){
|
||||||
$this->view = $view;
|
$this->view = $this->getView($owner);
|
||||||
$this->filepath = $filepath;
|
$this->filepath = $filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
40
lib/view.php
40
lib/view.php
@ -12,16 +12,6 @@
|
|||||||
namespace OCA\Documents;
|
namespace OCA\Documents;
|
||||||
|
|
||||||
class View extends \OC\Files\View{
|
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){
|
public function getFilePermissions($path){
|
||||||
$permissions = 0;
|
$permissions = 0;
|
||||||
@ -34,34 +24,4 @@ class View extends \OC\Files\View{
|
|||||||
return $permissions;
|
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user