Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controller/notescontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct($AppName, IRequest $request,
* @NoAdminRequired
*/
public function index() {
return new DataResponse($this->notesService->getAll($this->userId));
return new DataResponse($this->notesService->getAll($this->userId, true));
}


Expand Down
16 changes: 10 additions & 6 deletions db/note.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ public function __construct() {
* @param File $file
* @return static
*/
public static function fromFile(File $file, Folder $notesFolder, $tags=[]){
public static function fromFile(File $file, Folder $notesFolder, $tags=[], $onlyMeta=false) {
$note = new static();
$note->setId($file->getId());
$fileContent=$file->getContent();
if($fileContent===false){
throw new FileNotFoundException("File not found");
if(!$onlyMeta) {
$fileContent=$file->getContent();
if($fileContent===false){
throw new FileNotFoundException("File not found");
}
$note->setContent(self::convertEncoding($fileContent));
}
$note->setContent(self::convertEncoding($fileContent));
$note->setModified($file->getMTime());
$note->setTitle(pathinfo($file->getName(),PATHINFO_FILENAME)); // remove extension
$subdir = substr(dirname($file->getPath()), strlen($notesFolder->getPath())+1);
Expand All @@ -72,7 +74,9 @@ public static function fromFile(File $file, Folder $notesFolder, $tags=[]){
$note->setFavorite(true);
//unset($tags[array_search(\OC\Tags::TAG_FAVORITE, $tags)]);
}
$note->updateETag();
if(!$onlyMeta) {
$note->updateETag();
}
$note->resetUpdatedFields();
return $note;
}
Expand Down
19 changes: 10 additions & 9 deletions service/notesservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct (IRootFolder $root, IL10N $l10n, ILogger $logger, IC
* @param string $userId
* @return array with all notes in the current directory
*/
public function getAll ($userId){
public function getAll ($userId, $onlyMeta=false) {
$notesFolder = $this->getFolderForUser($userId);
$notes = $this->gatherNoteFiles($notesFolder);
$filesById = [];
Expand All @@ -76,7 +76,7 @@ public function getAll ($userId){

$notes = [];
foreach($filesById as $id=>$file) {
$notes[] = $this->getNote($file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
$notes[] = $this->getNote($file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : [], $onlyMeta);
}

return $notes;
Expand Down Expand Up @@ -104,21 +104,22 @@ private function getTags ($id) {
}
return array_key_exists($id, $tags) ? $tags[$id] : [];
}
private function getNote($file,$notesFolder,$tags=[]){

private function getNote($file, $notesFolder, $tags=[], $onlyMeta=false) {
$id=$file->getId();

try{
$note=Note::fromFile($file, $notesFolder, $tags);
}catch(FileNotFoundException $e){
try {
$note=Note::fromFile($file, $notesFolder, $tags, $onlyMeta);
} catch(FileNotFoundException $e){
$note = Note::fromException($this->l10n->t('File error').': ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
}catch(DecryptionFailedException $e){
} catch(DecryptionFailedException $e) {
$note = Note::fromException($this->l10n->t('Encryption Error').': ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
}catch(\Exception $e){
} catch(\Exception $e) {
$note = Note::fromException($this->l10n->t('Error').': ('.$file->getName().') '.$e->getMessage(), $file, $notesFolder, array_key_exists($id, $tags) ? $tags[$id] : []);
}
return $note;
}


/**
* Creates a note and returns the empty note
* @param string $userId
Expand Down