Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkorelstar <korelstar@users.noreply.github.com>2022-08-05 22:17:43 +0300
committerkorelstar <korelstar@users.noreply.github.com>2022-08-05 23:02:39 +0300
commit493cf2a00f73a76ab7463b7297e7423fb2005f33 (patch)
tree817824027242a08c25f24566c96809faa73ccb12
parent558c0c84ee166f2db8a45e0013dc9577ba322b44 (diff)
auto create notes folder only if app is opened
-rw-r--r--lib/Controller/Helper.php2
-rw-r--r--lib/Controller/NotesController.php2
-rw-r--r--lib/Service/NoteUtil.php4
-rw-r--r--lib/Service/NotesService.php27
-rw-r--r--lib/Service/SettingsService.php4
5 files changed, 22 insertions, 17 deletions
diff --git a/lib/Controller/Helper.php b/lib/Controller/Helper.php
index 05dc07ce..ff416e80 100644
--- a/lib/Controller/Helper.php
+++ b/lib/Controller/Helper.php
@@ -74,7 +74,7 @@ class Helper {
$userId = $this->getUID();
$chunkCursor = $chunkCursorStr ? ChunkCursor::fromString($chunkCursorStr) : null;
$lastUpdate = $chunkCursor->timeStart ?? new \DateTime();
- $data = $this->notesService->getAll($userId);
+ $data = $this->notesService->getAll($userId, true);
$metaNotes = $this->metaService->getAll($userId, $data['notes']);
// if a category is requested, then ignore all other notes
diff --git a/lib/Controller/NotesController.php b/lib/Controller/NotesController.php
index 4d8858ce..a78aa50c 100644
--- a/lib/Controller/NotesController.php
+++ b/lib/Controller/NotesController.php
@@ -49,7 +49,7 @@ class NotesController extends Controller {
public function index(int $pruneBefore = 0) : JSONResponse {
return $this->helper->handleErrorResponse(function () use ($pruneBefore) {
$userId = $this->helper->getUID();
- $settings = $this->settingsService->getAll($userId);
+ $settings = $this->settingsService->getAll($userId, true);
$lastViewedNote = (int) $this->settings->getUserValue(
$userId,
diff --git a/lib/Service/NoteUtil.php b/lib/Service/NoteUtil.php
index 92ea284c..58bb4ec9 100644
--- a/lib/Service/NoteUtil.php
+++ b/lib/Service/NoteUtil.php
@@ -145,10 +145,10 @@ class NoteUtil {
* @param string $path path to the folder
* @return Folder
*/
- public function getOrCreateFolder(string $path) : Folder {
+ public function getOrCreateFolder(string $path, bool $create = true) : Folder {
if ($this->root->nodeExists($path)) {
$folder = $this->root->get($path);
- } else {
+ } elseif ($create) {
$folder = $this->root->newFolder($path);
}
if (!($folder instanceof Folder)) {
diff --git a/lib/Service/NotesService.php b/lib/Service/NotesService.php
index 2474f2bf..f5696ca7 100644
--- a/lib/Service/NotesService.php
+++ b/lib/Service/NotesService.php
@@ -24,16 +24,21 @@ class NotesService {
$this->noteUtil = $noteUtil;
}
- public function getAll(string $userId) : array {
+ public function getAll(string $userId, bool $autoCreateNotesFolder = false) : array {
$customExtension = $this->getCustomExtension($userId);
- $notesFolder = $this->getNotesFolder($userId);
- $data = self::gatherNoteFiles($customExtension, $notesFolder);
- $fileIds = array_keys($data['files']);
- // pre-load tags for all notes (performance improvement)
- $this->noteUtil->getTagService()->loadTags($fileIds);
- $notes = array_map(function (File $file) use ($notesFolder) : Note {
- return new Note($file, $notesFolder, $this->noteUtil);
- }, $data['files']);
+ try {
+ $notesFolder = $this->getNotesFolder($userId, $autoCreateNotesFolder);
+ $data = self::gatherNoteFiles($customExtension, $notesFolder);
+ $fileIds = array_keys($data['files']);
+ // pre-load tags for all notes (performance improvement)
+ $this->noteUtil->getTagService()->loadTags($fileIds);
+ $notes = array_map(function (File $file) use ($notesFolder) : Note {
+ return new Note($file, $notesFolder, $this->noteUtil);
+ }, $data['files']);
+ } catch (NotesFolderException $e) {
+ $notes = [];
+ $data = [ 'categories' => [] ];
+ }
return [ 'notes' => $notes, 'categories' => $data['categories'] ];
}
@@ -142,10 +147,10 @@ class NotesService {
* @param string $userId the user id
* @return Folder
*/
- private function getNotesFolder(string $userId) : Folder {
+ private function getNotesFolder(string $userId, bool $create = true) : Folder {
$userPath = $this->noteUtil->getRoot()->getUserFolder($userId)->getPath();
$path = $userPath . '/' . $this->settings->get($userId, 'notesPath');
- $folder = $this->noteUtil->getOrCreateFolder($path);
+ $folder = $this->noteUtil->getOrCreateFolder($path, $create);
return $folder;
}
diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php
index 6cdd5ae1..bbc8e718 100644
--- a/lib/Service/SettingsService.php
+++ b/lib/Service/SettingsService.php
@@ -134,7 +134,7 @@ class SettingsService {
return $settings;
}
- public function getAll(string $uid) : \stdClass {
+ public function getAll(string $uid, $saveInitial = false) : \stdClass {
$settings = $this->getSettingsFromDB($uid);
// use default for empty settings
$toBeSaved = false;
@@ -143,7 +143,7 @@ class SettingsService {
$defaultValue = $attr['default'];
if (is_callable($defaultValue)) {
$settings->{$name} = $defaultValue($uid);
- $toBeSaved = true;
+ $toBeSaved = $saveInitial;
} else {
$settings->{$name} = $defaultValue;
}