Skip to content

Commit b68a743

Browse files
committed
Implement DB and EF changes for new static attribute Guids #3196
1 parent b43eb64 commit b68a743

File tree

6 files changed

+51
-4
lines changed

6 files changed

+51
-4
lines changed

ToSic.Eav.Core/Serialization/IDataDeserializer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,13 @@ public interface IDataDeserializer: IHasLog
5555
/// </param>
5656
/// <returns>A list of entity objects</returns>
5757
List<IEntity> Deserialize(List<string> serialized, bool allowDynamic = false);
58+
59+
60+
/// <summary>
61+
/// De-serialize ContentTypeAttributeSysSettings from SysSettings string field in ToSicEavAttributes and ToSicEavAttributeSets (EF/DB)
62+
/// </summary>
63+
/// <param name="serialized"></param>
64+
/// <returns>ContentTypeAttributeSysSettings or null</returns>
65+
ContentTypeAttributeSysSettings DeserializeAttributeSysSettings(string serialized);
5866
}
5967
}

ToSic.Eav.ImportExport/Json/JsonDeserializer_ContentType.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using ToSic.Eav.Data;
55
using ToSic.Eav.Data.Source;
66
using ToSic.Eav.ImportExport.Json.V1;
7+
using ToSic.Eav.Plumbing;
8+
using ToSic.Eav.Serialization;
79
using ToSic.Lib.Logging;
810
using IEntity = ToSic.Eav.Data.IEntity;
911

@@ -100,5 +102,20 @@ IEntity ConvertPart(JsonEntity e) =>
100102
});
101103
return lMain.ReturnAsOk(contentType);
102104
}
105+
106+
public ContentTypeAttributeSysSettings DeserializeAttributeSysSettings(string serialized)
107+
{
108+
var l = Log.Fn<ContentTypeAttributeSysSettings>($"{serialized?.Substring(0, Math.Min(50, serialized.Length))}...");
109+
if (serialized.IsEmpty()) return l.Return(null, "empty serialized");
110+
try
111+
{
112+
var json = System.Text.Json.JsonSerializer.Deserialize<JsonAttributeSysSettings>(serialized, JsonOptions.UnsafeJsonWithoutEncodingHtml);
113+
return l.Return(json.ToSysSettings(), $"deserialized sysSettings");
114+
}
115+
catch (Exception e)
116+
{
117+
throw l.Done(e);
118+
}
119+
}
103120
}
104121
}

ToSic.Eav.Persistence.Efc/Efc11Loader_ContentTypes.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System.Collections.Immutable;
33
using System.Diagnostics;
44
using System.Linq;
5+
using System.Text.Json;
56
using Microsoft.EntityFrameworkCore;
67
using ToSic.Eav.Apps;
78
using ToSic.Eav.Data;
89
using ToSic.Lib.Logging;
910
using ToSic.Eav.Metadata;
11+
using ToSic.Eav.Serialization;
1012

1113
namespace ToSic.Eav.Persistence.Efc
1214
{
@@ -90,6 +92,9 @@ private ImmutableList<IContentType> LoadContentTypesIntoLocalCache(int appId, IH
9092
var query = _dbContext.ToSicEavAttributeSets
9193
.Where(set => set.AppId == appId && set.ChangeLogDeleted == null);
9294

95+
var serializer = _dataDeserializer.New();
96+
serializer.Initialize(appId, new List<IContentType>(), null);
97+
9398
var contentTypes = query
9499
.Include(set => set.ToSicEavAttributesInSets)
95100
.ThenInclude(attrs => attrs.Attribute)
@@ -112,7 +117,9 @@ private ImmutableList<IContentType> LoadContentTypesIntoLocalCache(int appId, IH
112117
isTitle: a.IsTitle,
113118
id: a.AttributeId,
114119
sortOrder: a.SortOrder,
115-
metaSourceFinder: () => source)),
120+
metaSourceFinder: () => source,
121+
guid: a.Attribute.Guid,
122+
sysSettings: serializer.DeserializeAttributeSysSettings(a.Attribute.SysSettings))),
116123
IsGhost = set.UsesConfigurationOfAttributeSet,
117124
SharedDefinitionId = set.UsesConfigurationOfAttributeSet,
118125
AppId = set.UsesConfigurationOfAttributeSetNavigation?.AppId ?? set.AppId,
@@ -142,7 +149,8 @@ private ImmutableList<IContentType> LoadContentTypesIntoLocalCache(int appId, IH
142149
id: a.AttributeId,
143150
sortOrder: a.SortOrder,
144151
// Must get own MetaSourceFinder since they come from other apps
145-
metaSourceFinder: () => _appStates.Get(s.AppId)))
152+
metaSourceFinder: () => _appStates.Get(s.AppId),
153+
sysSettings: serializer.DeserializeAttributeSysSettings(a.Attribute.SysSettings)))
146154
);
147155
sqlTime.Stop();
148156

@@ -177,6 +185,5 @@ private ImmutableList<IContentType> LoadContentTypesIntoLocalCache(int appId, IH
177185

178186
return wrapLog.Return(newTypes.ToImmutableList());
179187
}
180-
181188
}
182189
}

ToSic.Eav.Persistence.Efc/Models/EavDbContext.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
167167
.HasForeignKey(d => d.UsesConfigurationOfAttributeSet)
168168
.HasConstraintName("FK_ToSIC_EAV_AttributeSets_ToSIC_EAV_AttributeSets");
169169

170+
entity.Property(e => e.SysSettings)
171+
.HasColumnName("SysSettings")
172+
.HasColumnType("nvarchar(MAX)");
170173
});
171174

172175
modelBuilder.Entity<ToSicEavAttributeTypes>(entity =>
@@ -212,6 +215,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
212215
.HasForeignKey(d => d.Type)
213216
.OnDelete(DeleteBehavior.Restrict)
214217
.HasConstraintName("FK_ToSIC_EAV_Attributes_ToSIC_EAV_Types");
218+
219+
entity.Property(e => e.Guid)
220+
.HasColumnName("Guid")
221+
.HasColumnType("uniqueidentifier");
222+
223+
entity.Property(e => e.SysSettings)
224+
.HasColumnName("SysSettings")
225+
.HasColumnType("nvarchar(MAX)");
215226
});
216227

217228
modelBuilder.Entity<ToSicEavAttributesInSets>(entity =>

ToSic.Eav.Persistence.Efc/Models/ToSicEavAttributeSets.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public ToSicEavAttributeSets()
2222
public int AppId { get; set; }
2323
public int? UsesConfigurationOfAttributeSet { get; set; }
2424
public bool AlwaysShareConfiguration { get; set; }
25+
public string SysSettings { get; set; }
2526

2627
public virtual ICollection<ToSicEavAttributeGroups> ToSicEavAttributeGroups { get; set; }
2728
public virtual ICollection<ToSicEavAttributesInSets> ToSicEavAttributesInSets { get; set; }

ToSic.Eav.Persistence.Efc/Models/ToSicEavAttributes.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23

34
namespace ToSic.Eav.Persistence.Efc.Models
45
{
@@ -16,6 +17,8 @@ public ToSicEavAttributes()
1617
public string Type { get; set; }
1718
public int ChangeLogCreated { get; set; }
1819
public int? ChangeLogDeleted { get; set; }
20+
public Guid? Guid { get; set; }
21+
public string SysSettings { get; set; }
1922

2023
public virtual ICollection<ToSicEavAttributesInSets> ToSicEavAttributesInSets { get; set; }
2124
public virtual ICollection<ToSicEavEntityRelationships> ToSicEavEntityRelationships { get; set; }

0 commit comments

Comments
 (0)