diff --git a/lib/Manager.php b/lib/Manager.php index 0d611c7..9dbd9f9 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -608,13 +608,11 @@ class Manager { throw new InvalidArgumentException("Service '{$service->identifier()}' is not capable of creating collections"); } // convert properties if necessary - if (is_array($properties)) { - $collection = $service->collectionFresh()->getProperties()->jsonDeserialize($properties); - } else { - $collection = $properties; + if ($properties instanceof CollectionPropertiesMutableInterface === false) { + $properties = $service->collectionFresh()->getProperties()->jsonDeserialize($properties); } // Create collection - return $service->collectionCreate($target, $collection, $options); + return $service->collectionCreate($target, $properties, $options); } /** @@ -642,13 +640,11 @@ class Manager { throw new InvalidArgumentException("Service '{$service->identifier()}' is not capable of updating collections"); } // convert properties if necessary - if (is_array($properties)) { - $mutation = $service->collectionFresh()->getProperties()->jsonDeserialize($properties); - } else { - $mutation = $properties; + if ($properties instanceof CollectionPropertiesMutableInterface === false) { + $properties = $service->collectionFresh()->getProperties()->jsonDeserialize($properties); } // Update collection - return $service->collectionUpdate($target, $mutation); + return $service->collectionUpdate($target, $properties); } /** diff --git a/src/stores/collectionsStore.ts b/src/stores/collectionsStore.ts index 3223983..99855d1 100644 --- a/src/stores/collectionsStore.ts +++ b/src/stores/collectionsStore.ts @@ -296,9 +296,10 @@ export const useCollectionsStore = defineStore('mailCollectionsStore', () => { properties: properties.toJson() }) - // Merge created collection into state - _collections.value[response.identifier] = response - indexCollection(response) + if (response instanceof CollectionObject) { + _collections.value[response.identifier] = response + indexCollection(response) + } console.debug('[Mail Manager][Store] - Successfully created collection:', response.identifier) return response @@ -326,12 +327,14 @@ export const useCollectionsStore = defineStore('mailCollectionsStore', () => { properties: properties.toJson() }) - if (_collections.value[response.identifier]) { - deindexCollection(_collections.value[response.identifier]) + if (_collections.value[target]) { + deindexCollection(_collections.value[target]) } - _collections.value[response.identifier] = response - indexCollection(response) + if (response instanceof CollectionObject) { + _collections.value[response.identifier] = response + indexCollection(response) + } console.debug('[Mail Manager][Store] - Successfully updated collection:', response.identifier) return response