diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-01-14 08:34:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-14 08:34:39 +0100 |
commit | e7b308cf0a20f21b804430e86dc1eca3757769ec (patch) | |
tree | 2fb4166a6b90d9793fca712f1ce082afe6edbee1 /lib/private | |
parent | 0f6e7a7b2287bc712f56c9ae4fdffc04cdb31857 (diff) | |
parent | ab4b9a6df5b031174f4e3bdd62069d7ec26c6066 (diff) | |
download | nextcloud-server-e7b308cf0a20f21b804430e86dc1eca3757769ec.tar.gz nextcloud-server-e7b308cf0a20f21b804430e86dc1eca3757769ec.zip |
Merge pull request #18805 from nextcloud/bugfix/direct-edit-create
Check if file already exists during file creation
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/DirectEditing/Manager.php | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php index 03bdba43564..ac85e62cb72 100644 --- a/lib/private/DirectEditing/Manager.php +++ b/lib/private/DirectEditing/Manager.php @@ -124,15 +124,21 @@ class Manager implements IManager { public function create(string $path, string $editorId, string $creatorId, $templateId = null): string { $userFolder = $this->rootFolder->getUserFolder($this->userId); - $file = $userFolder->newFile($path); - $editor = $this->getEditor($editorId); - $creators = $editor->getCreators(); - foreach ($creators as $creator) { - if ($creator->getId() === $creatorId) { - $creator->create($file, $creatorId, $templateId); - return $this->createToken($editorId, $file, $path); + try { + $file = $userFolder->get($path); + throw new \RuntimeException('File already exists'); + } catch (\OCP\Files\NotFoundException $e) { + $file = $userFolder->newFile($path); + $editor = $this->getEditor($editorId); + $creators = $editor->getCreators(); + foreach ($creators as $creator) { + if ($creator->getId() === $creatorId) { + $creator->create($file, $creatorId, $templateId); + return $this->createToken($editorId, $file, $path); + } } } + throw new \RuntimeException('No creator found'); } |