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 lib/AppInfo/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getCapabilities(): array {
Application::APP_ID => [
'api_version' => Application::$API_VERSIONS,
'version' => $this->appManager->getAppVersion(Application::APP_ID),
'notes_path' => $this->userId !== null && $this->userId !== ' ' ? $this->noteUtil->getNotesFolderUserPath($this->userId) : null,
'notes_path' => $this->userId !== null && $this->userId !== ' ' ? $this->noteUtil->getNotesFolderUserPath($this->userId, true) : null,
],
];
}
Expand Down
8 changes: 3 additions & 5 deletions lib/Service/NoteUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,14 @@ public function getOrCreateFolder(string $path, bool $create = true) : Folder {
return $folder;
}

public function getNotesFolderUserPath(string $userId): ?string {
/** @psalm-suppress MissingDependency */
$userFolder = $this->getRoot()->getUserFolder($userId);
public function getNotesFolderUserPath(string $userId, bool $saveInitial = false): ?string {
try {
$nodesFolder = $this->getOrCreateNotesFolder($userId, false);
$notesFolder = $this->settingsService->get($userId, 'notesPath', $saveInitial);
return $notesFolder;
} catch (NotesFolderException $e) {
$this->util->logger->debug("Failed to get notes folder for user $userId: " . $e->getMessage());
return null;
}
return $userFolder->getRelativePath($nodesFolder->getPath());
}

public function getOrCreateNotesFolder(string $userId, bool $create = true) : Folder {
Expand Down
7 changes: 5 additions & 2 deletions lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public function set(string $uid, array $settings, bool $writeDefaults = false) :
if ($value !== null && array_key_exists($name, $this->attrs)) {
$settings[$name] = $value = $this->attrs[$name]['validate']($value);
}
if ($name === 'notesPath' && $value !== null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to limit this to the notesPath or could we just skip getting the default if the value is not null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason we compute $default anyway is to compare that with the current $value and skip having write redundantly if they're the same. So yes, we can just skip the comparison $value === $default and always write the setting value whenever it's not null. I assume calling config->setUserValue() is cheap

continue;
}
$default = is_callable($this->attrs[$name]['default']) ? $this->attrs[$name]['default']($uid) : $this->attrs[$name]['default'];
if (!$writeDefaults && (!array_key_exists($name, $this->attrs)
|| $value === null
Expand Down Expand Up @@ -169,8 +172,8 @@ public function getAll(string $uid, $saveInitial = false) : \stdClass {
/**
* @throws \OCP\PreConditionNotMetException
*/
public function get(string $uid, string $name) : string {
$settings = $this->getAll($uid);
public function get(string $uid, string $name, bool $saveInitial = false) : string {
$settings = $this->getAll($uid, $saveInitial);
if (property_exists($settings, $name)) {
return $settings->{$name};
} else {
Expand Down