Skip to content

Commit

Permalink
Merge pull request #51 from KalikoCMS/1.0.0-final
Browse files Browse the repository at this point in the history
Minor fixes for 1.0.0-final
  • Loading branch information
fschultz committed Aug 18, 2015
2 parents 6154b4c + d321dca commit 77b1805
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
2 changes: 1 addition & 1 deletion KalikoCMS.Engine/Core/CmsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public string ShortUrl {

public PageCollection ParentPath {
get {
return _parentPath ?? (_parentPath = PageFactory.GetPagePath(this));
return _parentPath ?? (_parentPath = PageFactory.GetAncestors(this));
}
}

Expand Down
10 changes: 6 additions & 4 deletions KalikoCMS.Engine/Core/PageIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -633,12 +633,14 @@ internal PageCollection GetPageTreeFromPage(Guid rootPageId, Guid leafPageId, Pu
}

// TODO: Cache-candidate
internal PageCollection GetPagePath(Guid pageId) {
internal PageCollection GetPagePath(Guid pageId, bool includeCurrentPage = true) {
var pathList = new PageCollection();
Guid currentPageId = pageId;
var currentPageId = pageId;

for (int i = 0; i < 10000; i++) {
pathList.Add(currentPageId);
for (var i = 0; i < 10000; i++) {
if (i > 0 || includeCurrentPage) {
pathList.Add(currentPageId);
}
currentPageId = GetPageIndexItem(currentPageId).ParentId;
if (currentPageId == Guid.Empty) {
break;
Expand Down
5 changes: 4 additions & 1 deletion KalikoCMS.Engine/Data/PageInstanceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace KalikoCMS.Data {
using System.Collections.Generic;
using Entities;

// TODO: Fixa access
public class PageInstanceData {
internal static PageInstanceEntity GetByStatus(Guid pageId, int languageId, PageInstanceStatus status) {
return DataManager.FirstOrDefault<PageInstanceEntity>(p => p.Status == status && p.PageId == pageId && p.LanguageId == languageId);
Expand All @@ -35,5 +34,9 @@ internal static PageInstanceEntity GetByVersion(Guid pageId, int languageId, int
public static List<PageInstanceEntity> GetById(Guid pageId, int languageId) {
return DataManager.Select<PageInstanceEntity>(p => p.PageId == pageId && p.LanguageId == languageId);
}

internal static PageInstanceEntity GetById(int pageInstanceId) {
return DataManager.FirstOrDefault<PageInstanceEntity>(p => p.PageInstanceId == pageInstanceId);
}
}
}
29 changes: 28 additions & 1 deletion KalikoCMS.Engine/PageFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,22 @@ private static PageCollection GetPagePath(Guid pageId, int languageId) {
}


public static PageCollection GetAncestors(CmsPage page) {
return GetAncestors(page.PageId, page.LanguageId);
}


public static PageCollection GetAncestors(Guid pageId) {
var languageId = Language.CurrentLanguageId;
return GetAncestors(pageId, languageId);
}

private static PageCollection GetAncestors(Guid pageId, int languageId)
{
var pageIndex = GetPageIndex(languageId);
return pageIndex.GetPagePath(pageId, false);
}

public static CmsPage GetParentAtLevel(Guid pageId, int level) {
var pageCollection = GetPagePath(pageId);
level++;
Expand Down Expand Up @@ -598,7 +614,18 @@ internal static string GetUrlForPageInstanceId(int pageInstanceId) {
}
}

return string.Empty;
// If above fails, try to get from database (this occurs when a newer version is published)
var pageInstance = PageInstanceData.GetById(pageInstanceId);
if (pageInstance == null) {
return string.Empty;
}

var page = GetPage(pageInstance.PageId, pageInstance.LanguageId);
if (page == null) {
return string.Empty;
}

return page.PageUrl.ToString();
}


Expand Down

0 comments on commit 77b1805

Please sign in to comment.