Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix returning null as content usage url #70

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ namespace Forte.Optimizely.ContentUsage.Api.Features.ContentType;

public class ContentTypeUsagesRepository
{
private readonly ServiceAccessor<IAsyncDatabaseExecutor> dataExecutorAccessor;
private readonly ServiceAccessor<IAsyncDatabaseExecutor> _dataExecutorAccessor;

public ContentTypeUsagesRepository(ServiceAccessor<IAsyncDatabaseExecutor> dataExecutorAccessor)
{
this.dataExecutorAccessor = dataExecutorAccessor;
_dataExecutorAccessor = dataExecutorAccessor;
}

public async Task<IEnumerable<ContentTypeUsageCounter>> ListContentTypesUsagesCounters(
CancellationToken cancellationToken)
{
var executor = this.dataExecutorAccessor();
var executor = _dataExecutorAccessor();
return await executor.ExecuteAsync((Func<Task<IEnumerable<ContentTypeUsageCounter>>>)(async () =>
{
var command1 = executor.CreateCommand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace Forte.Optimizely.ContentUsage.Api.Services;
public class ContentTypeService
{
private readonly IContentTypeRepository _contentTypeRepository;
private readonly ContentTypeUsagesRepository contentTypeUsagesRepository;
private readonly ContentTypeUsagesRepository _contentTypeUsagesRepository;


public ContentTypeService(IContentTypeRepository contentTypeRepository, ContentTypeUsagesRepository contentTypeUsagesRepository)
{
_contentTypeRepository = contentTypeRepository;
this.contentTypeUsagesRepository = contentTypeUsagesRepository;
_contentTypeUsagesRepository = contentTypeUsagesRepository;
}

public IEnumerable<ContentType> GetAll(ContentTypesFilterCriteria? filterCriteria)
Expand All @@ -34,7 +34,7 @@ public IEnumerable<ContentType> GetAll(ContentTypesFilterCriteria? filterCriteri

public async Task<IEnumerable<ContentTypeUsageCounter>> GetAllCounters(CancellationToken cancellationToken)
{
return await contentTypeUsagesRepository.ListContentTypesUsagesCounters(cancellationToken);
return await _contentTypeUsagesRepository.ListContentTypesUsagesCounters(cancellationToken);
}

public ContentType? Get(Guid guid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,28 @@ public ContentUsageService(IUrlResolver urlResolver, IContentSoftLinkRepository
public IEnumerable<string> GetPageUrls(EPiServerContentUsage contentUsage)
{
var contentLink = contentUsage.ContentLink;
var url = _urlResolver.GetUrl(contentLink, contentUsage.LanguageBranch);

var pageUrls = SearchForPageUrls(contentLink, contentUsage.LanguageBranch);

return pageUrls;
}

private IEnumerable<string> SearchForPageUrls(ContentReference contentLink, string languageBranch)
{
var url = _urlResolver.GetUrl(contentLink, languageBranch);

if (!string.IsNullOrEmpty(url))
return CheckIsPublished(contentLink) ? new[] { url } : new string[] { };

var pageLinks = _contentSoftLinkRepository.Load(contentLink, true)
var softLinks = _contentSoftLinkRepository.Load(contentLink, true);
var pageLinks = softLinks
.Where(softLink => softLink.SoftLinkType == ReferenceType.PageLinkReference)
.Select(softLink => softLink.OwnerContentLink)
.Where(ownerContentLink => ownerContentLink != null && CheckIsPublished(ownerContentLink));

return pageLinks.Select(pageLink => _urlResolver.GetUrl(pageLink, contentUsage.LanguageBranch));
var pageUrls = pageLinks.SelectMany(pageLink => SearchForPageUrls(pageLink, languageBranch));

return pageUrls;
}

public string GetEditUrl(EPiServerContentUsage contentUsage)
Expand Down