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

XPath "in-use" language retrieval issues on unpublished nodes #95

Merged
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
64 changes: 35 additions & 29 deletions src/Our.Umbraco.Vorto/Web/Controllers/VortoApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,36 +99,42 @@ public IEnumerable<object> GetLanguages(string section, int id, int parentId, Gu

if (languageSource == "inuse")
{
var xpath = preValues.ContainsKey("xpath") ? preValues["xpath"].Value : "";

// Grab languages by xpath (only if in content section)
if (!string.IsNullOrWhiteSpace(xpath) && section == "content")
{
xpath = xpath.Replace("$currentPage",
string.Format("//*[@id={0} and @isDoc]", id)).Replace("$parentPage",
string.Format("//*[@id={0} and @isDoc]", parentId)).Replace("$ancestorOrSelf",
string.Format("//*[@id={0} and @isDoc]", id != 0 ? id : parentId));

// Lookup language nodes
var nodeIds = uQuery.GetNodesByXPath(xpath).Select(x => x.Id).ToArray();
if (nodeIds.Any())
{
var db = ApplicationContext.Current.DatabaseContext.Database;
languages.AddRange(db.Query<string>(
string.Format(
"SELECT DISTINCT [languageISOCode] FROM [umbracoLanguage] JOIN [umbracoDomains] ON [umbracoDomains].[domainDefaultLanguage] = [umbracoLanguage].[id] WHERE [umbracoDomains].[domainRootStructureID] in ({0})",
string.Join(",", nodeIds)))
.Select(CultureInfo.GetCultureInfo)
.Select(x => new Language
{
IsoCode = x.Name,
Name = x.DisplayName,
NativeName = x.NativeName,
var currentNode = id != 0 ? Umbraco.TypedContent(id) : null;
var currentNodeIsUnpublished = currentNode == null;

//trying to add/publish a home node, so no "in use" languages have been defined/are accessible - display all installed in the interim
var currentNodeIsUnpublishedRootNode = currentNodeIsUnpublished && parentId == -1;

var xpath = preValues.ContainsKey("xpath") ? preValues["xpath"].Value : "";

// Grab languages by xpath (only if in content section)
if (!currentNodeIsUnpublishedRootNode && !string.IsNullOrWhiteSpace(xpath) && section == "content")
{
xpath = xpath.Replace("$currentPage",
string.Format("//*[@id={0} and @isDoc]", id)).Replace("$parentPage",
string.Format("//*[@id={0} and @isDoc]", parentId)).Replace("$ancestorOrSelf",
string.Format("//*[@id={0} and @isDoc]", currentNodeIsUnpublished ? parentId : id));

// Lookup language nodes
var nodeIds = uQuery.GetNodesByXPath(xpath).Select(x => x.Id).ToArray();
if (nodeIds.Any())
{
var db = ApplicationContext.Current.DatabaseContext.Database;
languages.AddRange(db.Query<string>(
string.Format(
"SELECT DISTINCT [languageISOCode] FROM [umbracoLanguage] JOIN [umbracoDomains] ON [umbracoDomains].[domainDefaultLanguage] = [umbracoLanguage].[id] WHERE [umbracoDomains].[domainRootStructureID] in ({0})",
string.Join(",", nodeIds)))
.Select(CultureInfo.GetCultureInfo)
.Select(x => new Language
{
IsoCode = x.Name,
Name = x.DisplayName,
NativeName = x.NativeName,
IsRightToLeft = x.TextInfo.IsRightToLeft
}));
}
}
else
}));
}
}
else
{
// No language node xpath so just return a list of all languages in use
var db = ApplicationContext.Current.DatabaseContext.Database;
Expand Down