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

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-01-14 10:34:39 +0300
committerGitHub <noreply@github.com>2020-01-14 10:34:39 +0300
commite7b308cf0a20f21b804430e86dc1eca3757769ec (patch)
tree2fb4166a6b90d9793fca712f1ce082afe6edbee1 /lib
parent0f6e7a7b2287bc712f56c9ae4fdffc04cdb31857 (diff)
parentab4b9a6df5b031174f4e3bdd62069d7ec26c6066 (diff)
Merge pull request #18805 from nextcloud/bugfix/direct-edit-create
Check if file already exists during file creation
Diffstat (limited to 'lib')
-rw-r--r--lib/private/DirectEditing/Manager.php20
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');
}