From ab19f9c79df0a602a0c06e9dc86ff0ab9e2b09ad Mon Sep 17 00:00:00 2001 From: Phie Date: Wed, 20 Jan 2021 17:41:32 +0100 Subject: new option to create folder notes by default --- appinfo/routes.php | 5 ++++ lib/Controller/NoteController.php | 59 +++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 30a2f98..d1c3226 100755 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -71,5 +71,10 @@ return [ ['name' => 'note#importArchive', 'url' => '/note/import_archive', 'verb' => 'POST'], ['name' => 'note#getNote', 'url' => '/note/get_note', 'verb' => 'GET'], + + ['name' => 'note#setShouldUseFolderNotes', 'url' => '/settings/note_folder', 'verb' => 'POST' ], + ['name' => 'note#shouldUseFolderNotes', 'url' => '/settings/note_folder', 'verb' => 'GET' ], + + ] ]; \ No newline at end of file diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index b28f1dc..be4a6e1 100755 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -777,21 +777,52 @@ public function getOpusEncoder(){ try{ $outFolder = $this->CarnetFolder->get($path); if($this->CarnetFolder->get($path)->getType() === "dir"){ - $meta = array(); - foreach($files as $file){ - $inFolder->get($file)->copy($outFolder->getFullPath($file)); - } - - - return $outFolder->getFileInfo()->getMtime(); + return $this->saveOpenNoteAsDir($inFolder, $files, $path, $id); + } else { + $this->saveOpenNote($_POST['path'],$id); + return false; } } catch(\OCP\Files\NotFoundException $e) { + if($this->shouldUseFolderNotes()){ + return $this->saveOpenNoteAsDir($inFolder, $files, $path, $id); + } else { + $this->saveOpenNote($_POST['path'],$id); + return false; + } } - $this->saveOpenNote($_POST['path'],$id); + return false; } + private function saveOpenNoteAsDir($inFolder, $files, $path, $id){ + if($this->CarnetFolder->nodeExists($path)){ + $outFolder = $this->CarnetFolder->get($path); + } + else { + $outFolder = $this->CarnetFolder->newFolder($path); + } + + + + $meta = array(); + foreach($files as $file){ + $parent = dirname($file); + if($parent != "/" AND $parent != "" AND $parent != Null AND !empty($parent) AND $parent != "."){ + if(!$outFolder->nodeExists($parent)){ + $outFolder->newFolder($parent); + + } + + // + + + } + $inFolder->get($file)->copy($outFolder->getFullPath($file)); + } + return $outFolder->getFileInfo()->getMtime(); + } + /* returns false if target note is not a folder or mTime if it is */ @@ -1250,6 +1281,18 @@ public function getOpusEncoder(){ // empty for now } + public function shouldUseFolderNotes(){ + return $this->Config->getUserValue($this->userId, $this->appName, "should_use_folder_notes",false); + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function setShouldUseFolderNotes($useFolder){ + return $this->Config->setUserValue($this->userId, $this->appName, "should_use_folder_notes", $useFolder); + } + /** * @NoAdminRequired * @NoCSRFRequired -- cgit v1.2.3