|
12 | 12 | use OCA\Notes\AppInfo\Application; |
13 | 13 |
|
14 | 14 | use OCP\App\IAppManager; |
| 15 | +use OCP\Files\Folder; |
15 | 16 | use OCP\Files\IRootFolder; |
| 17 | +use OCP\Files\NotFoundException; |
16 | 18 | use OCP\IConfig; |
17 | 19 | use OCP\IL10N; |
18 | 20 |
|
@@ -41,7 +43,7 @@ public function __construct( |
41 | 43 | 'fileSuffix' => $this->getListAttrs('fileSuffix', [...$this->defaultSuffixes, 'custom']), |
42 | 44 | 'notesPath' => [ |
43 | 45 | 'default' => function (string $uid) { |
44 | | - return $this->getDefaultNotesPath($uid); |
| 46 | + return $this->getDefaultNotesNode($uid)['path']; |
45 | 47 | }, |
46 | 48 | 'validate' => function ($value) { |
47 | 49 | $value = str_replace([ '/', '\\' ], DIRECTORY_SEPARATOR, $value); |
@@ -86,13 +88,46 @@ private function getListAttrs(string $attributeName, array $values) : array { |
86 | 88 | ]; |
87 | 89 | } |
88 | 90 |
|
89 | | - public function getDefaultNotesPath(string $uid) : string { |
| 91 | + /** |
| 92 | + * Return the default notes node if it exists and the expected path if it exists |
| 93 | + * @return array{ |
| 94 | + * path: string, |
| 95 | + * folder: ?Folder |
| 96 | + * } |
| 97 | + */ |
| 98 | + public function getDefaultNotesNode(string $uid): array { |
90 | 99 | $defaultFolder = $this->config->getAppValue(Application::APP_ID, 'defaultFolder', 'Notes'); |
91 | | - $defaultExists = $this->root->getUserFolder($uid)->nodeExists($defaultFolder); |
92 | | - if ($defaultExists) { |
93 | | - return $defaultFolder; |
94 | | - } else { |
95 | | - return $this->l10n->t($defaultFolder); |
| 100 | + $userFolder = $this->root->getUserFolder($uid); |
| 101 | + try { |
| 102 | + /** @var Folder $node */ |
| 103 | + $node = $userFolder->get($defaultFolder); |
| 104 | + return [ |
| 105 | + 'path' => $defaultFolder, |
| 106 | + 'folder' => $node, |
| 107 | + ]; |
| 108 | + } catch (NotFoundException) { |
| 109 | + $path = $this->l10n->t($defaultFolder); |
| 110 | + |
| 111 | + if ($path == $defaultFolder) { |
| 112 | + // English locale, still non-existing |
| 113 | + return [ |
| 114 | + 'path' => $path, |
| 115 | + 'folder' => null, |
| 116 | + ]; |
| 117 | + } |
| 118 | + |
| 119 | + try { |
| 120 | + $node = $userFolder->get($path); |
| 121 | + return [ |
| 122 | + 'path' => $path, |
| 123 | + 'folder' => $node, |
| 124 | + ]; |
| 125 | + } catch (NotFoundException) { |
| 126 | + return [ |
| 127 | + 'path' => $path, |
| 128 | + 'folder' => null, |
| 129 | + ]; |
| 130 | + } |
96 | 131 | } |
97 | 132 | } |
98 | 133 |
|
|
0 commit comments