diff --git a/composer.json b/composer.json index 36eec62..fc60831 100755 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "xp-forge/yaml": "^8.0", "xp-forge/hashing": "^2.1", "xp-forge/inject": "^5.4", - "xp-forge/mongodb": "^2.0" + "xp-forge/mongodb": "^2.2" }, "require-dev": { diff --git a/src/main/php/de/thekid/dialog/Modification.php b/src/main/php/de/thekid/dialog/Modification.php deleted file mode 100755 index a78305e..0000000 --- a/src/main/php/de/thekid/dialog/Modification.php +++ /dev/null @@ -1,15 +0,0 @@ - $result) { } - - /** Returns whether the operation created a new entry */ - public function created(): bool { return isset($this->result['lastErrorObject']['upserted']); } - - /** Returns the modified entry */ - public function entry(): Document { return new Document($this->result['value']); } -} \ No newline at end of file diff --git a/src/main/php/de/thekid/dialog/Repository.php b/src/main/php/de/thekid/dialog/Repository.php index 25aae48..1a4c914 100755 --- a/src/main/php/de/thekid/dialog/Repository.php +++ b/src/main/php/de/thekid/dialog/Repository.php @@ -1,6 +1,6 @@ $entity): Modification { - $arguments= [ - 'query' => ['slug' => $slug], - 'update' => ['$set' => ['slug' => $slug, ...$entity]], - 'new' => true, // Return modified document - 'upsert' => true, - ]; - return new Modification($this->database->collection('entries')->run('findAndModify', $arguments)->value()); + return $this->database->collection('entries')->modify( + ['slug' => $slug], + ['$set' => ['slug' => $slug, ...$entity]], + upsert: true, + ); } /** Modify an entry identified by a given slug with MongoDB statements */ diff --git a/src/main/php/de/thekid/dialog/api/Entries.php b/src/main/php/de/thekid/dialog/api/Entries.php index 621a40d..ab05db2 100755 --- a/src/main/php/de/thekid/dialog/api/Entries.php +++ b/src/main/php/de/thekid/dialog/api/Entries.php @@ -35,11 +35,11 @@ public function create(#[Value] $user, string $id, #[Entity] arraycreated()) { + if ($result->upserted()) { $this->storage->folder($id)->create(); } - return $result->entry(); + return $result->document(); } #[Put('/{id:.+(/.+)?}/images/{name}')]