From 7aea7c4278980227eaf029f819e9f462153c7ce9 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 28 Mar 2024 11:25:58 -0700 Subject: [PATCH] Fix Taxonomy Serialization (#15615) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --------- Co-authored-by: Sébastien Ros --- .../OrchardCore.Taxonomies/Controllers/AdminController.cs | 7 ++++--- .../ContentItemConverter.cs | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs index ffc2d45e3fc..882b33e6350 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs @@ -1,12 +1,10 @@ using System.Linq; -using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Settings; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Localization; -using Microsoft.Extensions.Options; using OrchardCore.Admin; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display; @@ -321,7 +319,10 @@ public async Task Delete(string taxonomyContentItemId, string tax return NotFound(); } - taxonomy.As().Content.Remove(taxonomyItemId); + taxonomy.Alter(part => + { + part.Terms = part.Terms.Where(x => x.ContentItemId != taxonomyItemId).ToList(); + }); await _session.SaveAsync(taxonomy); diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentItemConverter.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentItemConverter.cs index fa4b82c08e9..7e26f0bea82 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentItemConverter.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentItemConverter.cs @@ -91,10 +91,11 @@ public override ContentItem Read(ref Utf8JsonReader reader, Type typeToConvert, contentItem.Owner = reader.TokenType == JsonTokenType.String ? reader.GetString() : null; break; default: - if (reader.TokenType == JsonTokenType.StartObject) + if (reader.TokenType == JsonTokenType.StartObject || + reader.TokenType == JsonTokenType.StartArray) { var property = JNode.Load(ref reader); - contentItem.Data.Add(propertyName, property); + contentItem.Data[propertyName] = property; } break;