diff options
author | Phie <phie@phie.ovh> | 2019-11-08 22:24:54 +0300 |
---|---|---|
committer | Phie <phie@phie.ovh> | 2019-11-08 22:24:54 +0300 |
commit | b95d465bc68be173476c4878b8cff831673ebda4 (patch) | |
tree | da8e2b5ed49ed78943a97ba6e1267f506af6252a /lib | |
parent | d016777a6a675da7f5f04a920c1a5ab8050a278e (diff) |
folder note : save text and metadata + fix open zipped notes
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Controller/NoteController.php | 43 | ||||
-rw-r--r-- | lib/Misc/CacheManager.php | 2 |
2 files changed, 43 insertions, 2 deletions
diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index c0bd031..2e58f86 100755 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -703,8 +703,48 @@ public function getOpusEncoder(){ $file = $folder->newFile("metadata.json"); } $file->putContent($_POST['metadata']); + $path = $_POST['path']; + $mtime = $this->saveFiles($folder, array(0 => "index.html", 1 =>"metadata.json"), $_POST['path'], $id); + if($mtime !== false){ + //we need to refresh cache + $cache = new CacheManager($this->db, $this->CarnetFolder); + $cached = $cache->getFromCache(array(0=>$path)); + $meta = array(); + if(isset($cached[$path])){ + $meta = $cached[$path]; + } + + + + $meta['shorttext'] = NoteUtils::getShortTextFromHTML($_POST['html']); + $meta['metadata'] = json_decode($_POST['metadata']); + $cache->addToCache($path, $meta, $mtime); + + } + + } + /* + returns false if target note is not a folder or mTime if it is + */ + private function saveFiles($inFolder, $files, $path, $id){ + + 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(); + } + } catch(\OCP\Files\NotFoundException $e) { + } + $this->saveOpenNote($_POST['path'],$id); + return false; } @@ -972,7 +1012,7 @@ public function getOpusEncoder(){ $folder = $noteNode->copy($cache->getFullPath($noteFolderName)); } else{ - $folder = $cache->newFolder($noteFolderNam); + $folder = $cache->newFolder($noteFolderName); $tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip"); file_put_contents($tmppath,$noteNode->fopen("r")); $zipFile = new \PhpZip\ZipFile(); @@ -994,6 +1034,7 @@ public function getOpusEncoder(){ unlink($tmppath); } } catch(\OCP\Files\NotFoundException $e) { + $folder = $cache->newFolder($noteFolderName); } try{ diff --git a/lib/Misc/CacheManager.php b/lib/Misc/CacheManager.php index 579bc85..ceeb17c 100644 --- a/lib/Misc/CacheManager.php +++ b/lib/Misc/CacheManager.php @@ -124,7 +124,7 @@ class CacheManager{ $stmt->execute($arrayFullPath); $fetched = $stmt->fetchAll(); foreach ($fetched as $row){ - $array[substr($row['path'], strlen($this->carnetFolder->getPath())+1)] = json_decode($row['metadata']); + $array[substr($row['path'], strlen($this->carnetFolder->getPath())+1)] = json_decode($row['metadata'], true); } $stmt->closeCursor(); |