Skip to content

Commit 7d5b0da

Browse files
committed
Merge branch 'out-of-support-main' of https://github.com/KevinJump/uSync-Legacy into out-of-support-main
2 parents b131675 + ff2df33 commit 7d5b0da

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

Jumoo.uSync.ContentMappers/ArchetypeContentMapper.cs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public string GetExportValue(int dataTypeDefinitionId, string value)
4545
if (mapper != null)
4646
{
4747
typedContent.Fieldsets.AsQueryable()
48+
.Where(fs => fs.Alias == fieldSet.Alias)
4849
.SelectMany(fs => fs.Properties)
4950
.Where(p => p.Alias == property.Alias)
5051
.ForEach(pm => pm.Value = mapper.GetExportValue(dataType.Id, pm.Value.ToString()));

Jumoo.uSync.ContentMappers/Jumoo.uSync.ContentMappers.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@
284284
<Compile Include="NestedContentMapper.cs" />
285285
<Compile Include="PackageActions.cs" />
286286
<Compile Include="Properties\AssemblyInfo.cs" />
287+
<Compile Include="RelatedLinksMapper.cs" />
287288
<Compile Include="RJPMapper.cs" />
288289
<Compile Include="StackedContentMapper.cs" />
289290
<Compile Include="VortoContentMapper.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using Jumoo.uSync.Core;
2+
using Jumoo.uSync.Core.Mappers;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
5+
using Newtonsoft.Json.Serialization;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using Umbraco.Core;
10+
using Umbraco.Core.Models;
11+
using Umbraco.Core.Services;
12+
using Umbraco.Web.Models;
13+
14+
namespace Jumoo.uSync.ContentMappers
15+
{
16+
public class RelatedLinksMapper : IContentMapper2
17+
{
18+
private readonly IEntityService _entityService;
19+
private readonly JsonSerializerSettings _serializerSettings;
20+
21+
public RelatedLinksMapper()
22+
{
23+
_entityService = ApplicationContext.Current.Services.EntityService;
24+
25+
_serializerSettings = new JsonSerializerSettings
26+
{
27+
ContractResolver = new CamelCasePropertyNamesContractResolver(),
28+
Converters = new List<JsonConverter> { new StringEnumConverter() },
29+
Formatting = Formatting.Indented,
30+
NullValueHandling = NullValueHandling.Ignore,
31+
};
32+
}
33+
34+
#pragma warning disable CS0618 // Type or member is obsolete
35+
public string[] PropertyEditorAliases => new[]
36+
{
37+
Constants.PropertyEditors.RelatedLinksAlias,
38+
Constants.PropertyEditors.RelatedLinks2Alias,
39+
};
40+
#pragma warning restore CS0618 // Type or member is obsolete
41+
42+
public string GetExportValue(int dataTypeDefinitionId, string value)
43+
{
44+
var links = JsonConvert.DeserializeObject<List<RelatedLink>>(value, _serializerSettings);
45+
46+
if (links?.Any() == true)
47+
{
48+
foreach (var link in links)
49+
{
50+
if (link.Type == RelatedLinkType.Internal &&
51+
int.TryParse(link.Link, out var id) == true &&
52+
id > 0)
53+
{
54+
var attempt = _entityService.uSyncGetKeyForId(id);
55+
if (attempt.Success == true)
56+
{
57+
link.Link = attempt.Result.ToString();
58+
}
59+
}
60+
}
61+
}
62+
63+
return JsonConvert.SerializeObject(links, _serializerSettings);
64+
}
65+
66+
public string GetImportValue(int dataTypeDefinitionId, string content)
67+
{
68+
var links = JsonConvert.DeserializeObject<List<RelatedLink>>(content, _serializerSettings);
69+
70+
if (links?.Any() == true)
71+
{
72+
foreach (var link in links)
73+
{
74+
if (link.Type == RelatedLinkType.Internal &&
75+
Guid.TryParse(link.Link, out var guid) == true &&
76+
guid.Equals(Guid.Empty) == false)
77+
{
78+
var attempt = _entityService.GetIdForKey(guid, UmbracoObjectTypes.Document);
79+
if (attempt.Success)
80+
{
81+
link.Link = attempt.Result.ToString();
82+
}
83+
}
84+
}
85+
}
86+
87+
return JsonConvert.SerializeObject(links, _serializerSettings);
88+
}
89+
}
90+
}

Jumoo.uSync.Core/Mappers/ContentIdMapping.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ internal int GetIdFromGuid(Guid guid)
9696
/// to specify type.
9797
var mediaAttempt = ApplicationContext.Current.Services.EntityService.GetIdForKey(guid, UmbracoObjectTypes.Media);
9898
if (mediaAttempt.Success)
99-
return attempt.Result;
99+
return mediaAttempt.Result;
100100

101101
return -1;
102102
}

0 commit comments

Comments
 (0)