Skip to content

Commit

Permalink
Ensure the content and media handler don't do doube lookups post Umbr…
Browse files Browse the repository at this point in the history
…aco 8.4.
  • Loading branch information
Kevin Jump committed Jan 6, 2020
1 parent 17cb81e commit 52c78a0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
23 changes: 17 additions & 6 deletions uSync8.ContentEdition/Handlers/ContentHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;

using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
Expand All @@ -24,6 +24,7 @@ public class ContentHandler : SyncHandlerTreeBase<IContent, IContentService>, IS
public override string Group => uSyncBackOfficeConstants.Groups.Content;

private readonly IContentService contentService;
private bool performDoubleLookup = true;

public ContentHandler(
IEntityService entityService,
Expand All @@ -36,6 +37,9 @@ public ContentHandler(
: base(entityService, logger, serializer, tracker, checker, syncFileService)
{
this.contentService = contentService;

performDoubleLookup = UmbracoVersion.LocalVersion.Major != 8 || UmbracoVersion.LocalVersion.Minor < 4;

}


Expand All @@ -47,12 +51,19 @@ protected override IContent GetFromService(int id)

protected override IContent GetFromService(Guid key)
{
// FIX: alpha bug - getby key is not always uptodate
var entity = entityService.Get(key);
if (entity != null)
return contentService.GetById(entity.Id);
if (performDoubleLookup)
{
// FIX: alpha bug - getby key is not always uptodate
var entity = entityService.Get(key);
if (entity != null)
return contentService.GetById(entity.Id);

return null;
return null;
}
else
{
return contentService.GetById(key);
}
}

protected override IContent GetFromService(string alias)
Expand Down
21 changes: 16 additions & 5 deletions uSync8.ContentEdition/Handlers/MediaHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;

using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
Expand All @@ -25,6 +25,8 @@ public class MediaHandler : SyncHandlerTreeBase<IMedia, IMediaService>, ISyncHan

private readonly IMediaService mediaService;

private readonly bool performDoubleLookup;

public MediaHandler(
IEntityService entityService,
IProfilingLogger logger,
Expand All @@ -36,6 +38,8 @@ public MediaHandler(
: base(entityService, logger, serializer, tracker, checker, syncFileService)
{
this.mediaService = mediaService;
performDoubleLookup = UmbracoVersion.LocalVersion.Major != 8 || UmbracoVersion.LocalVersion.Minor < 4;

}

protected override void DeleteViaService(IMedia item)
Expand All @@ -46,10 +50,17 @@ protected override IMedia GetFromService(int id)

protected override IMedia GetFromService(Guid key)
{
// FIX: alpha bug - getby key is not always uptodate
var entity = entityService.Get(key);
if (entity != null)
return mediaService.GetById(entity.Id);
if (performDoubleLookup)
{
// fixed v8.4+ by https://github.com/umbraco/Umbraco-CMS/issues/2997
var entity = entityService.Get(key);
if (entity != null)
return mediaService.GetById(entity.Id);
}
else
{
return mediaService.GetById(key);
}

return null;
}
Expand Down

0 comments on commit 52c78a0

Please sign in to comment.