From 22ca8bed70f6677f5d0171118228c36baacfafb9 Mon Sep 17 00:00:00 2001 From: Phie Date: Sun, 9 May 2021 22:39:49 +0200 Subject: nextcloud isn't rising exceptions right, try to fix it' --- lib/Controller/NoteController.php | 63 +++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index a87e9d6..ae42835 100755 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -1057,19 +1057,21 @@ public function getOpusEncoder(){ foreach($res['media'] as $media){ array_push($meta['media'], "./note/getmedia?note=".$path."&media=".$media); } - $file = $this->CarnetFolder->newFile($path); //tried to do with a direct fopen on $file but lead to bad size on nextcloud $tmppath = tempnam(sys_get_temp_dir(), uniqid().".sqd"); $zipFile->saveAsFile($tmppath); $tmph = fopen($tmppath, "r"); if($tmph){ - try{ - $this->CarnetFolder->get($path)->delete(); - $file = $this->CarnetFolder->newFile($path); + if($this->CarnetFolder->nodeExists($path)){ + try{ + $this->CarnetFolder->get($path)->delete(); - } catch(\OCP\Files\NotFoundException $e) { + } catch(\OCP\Files\NotFoundException $e) { + } } - + + $file = $this->CarnetFolder->newFile($path); + $file->putContent($tmph); // Do not close $tmph, it is closed by putContent, and a log is displayed as // fclose can not work @@ -1222,33 +1224,36 @@ public function getOpusEncoder(){ $noteFolderName = "currentnote".$editUniqueID; try{ - - $noteNode = $this->CarnetFolder->get($path); - if($noteNode->getType() === "dir"){ - $folder = $noteNode->copy($cache->getFullPath($noteFolderName)); - } - else{ - $folder = $cache->newFolder($noteFolderName); - $tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip"); - file_put_contents($tmppath,$noteNode->fopen("r")); - $zipFile = new \PhpZip\ZipFile(); - $zipFile->openFile($tmppath); - foreach($zipFile as $entryName => $contents){ - if($entryName === ".extraction_finished") - continue; - if($contents === "" AND $zipFile->isDirectory($entryName)){ - $folder->newFolder($entryName); - } - else if($contents !== "" && $contents !== NULL){ - $parent = dirname($entryName); - if($parent !== "." && !$folder->nodeExists($parent)){ - $folder->newFolder($parent); + if($this->CarnetFolder->nodeExists($path)){ + $noteNode = $this->CarnetFolder->get($path); + if($noteNode->getType() === "dir"){ + $folder = $noteNode->copy($cache->getFullPath($noteFolderName)); + } + else{ + $folder = $cache->newFolder($noteFolderName); + $tmppath = tempnam(sys_get_temp_dir(), uniqid().".zip"); + file_put_contents($tmppath,$noteNode->fopen("r")); + $zipFile = new \PhpZip\ZipFile(); + $zipFile->openFile($tmppath); + foreach($zipFile as $entryName => $contents){ + if($entryName === ".extraction_finished") + continue; + if($contents === "" AND $zipFile->isDirectory($entryName)){ + $folder->newFolder($entryName); + } + else if($contents !== "" && $contents !== NULL){ + $parent = dirname($entryName); + if($parent !== "." && !$folder->nodeExists($parent)){ + $folder->newFolder($parent); + } + $folder->newFile($entryName)->putContent($contents); } - $folder->newFile($entryName)->putContent($contents); } + unlink($tmppath); } - unlink($tmppath); } + else + $folder = $cache->newFolder($noteFolderName); } catch(\OCP\Files\NotFoundException $e) { $folder = $cache->newFolder($noteFolderName); } -- cgit v1.2.3