Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,15 @@ protected override string ApplySystemOrdering(ref Sql<ISqlContext> sql, Ordering

if (ordering.OrderBy.InvariantEquals("published"))
{
// no culture = can only work on the global 'published' flag
// no culture, assume invariant and simply order by published.
if (ordering.Culture.IsNullOrWhiteSpace())
{
// see notes in ApplyOrdering: the field MUST be selected + aliased, and we cannot have
// the whole CASE fragment in ORDER BY due to it not being detected by NPoco
sql = Sql(InsertBefore(sql, "FROM", ", (CASE WHEN pcv.id IS NULL THEN 0 ELSE 1 END) AS ordering "),
sql.Arguments);
return "ordering";
return SqlSyntax.GetFieldName<DocumentDto>(x => x.Published);
}

// invariant: left join will yield NULL and we must use pcv to determine published
// variant: left join may yield NULL or something, and that determines published


Sql<ISqlContext> joins = Sql()
.InnerJoin<ContentTypeDto>("ctype").On<ContentDto, ContentTypeDto>(
(content, contentType) => content.ContentTypeId == contentType.NodeId, aliasRight: "ctype")
Expand All @@ -185,9 +180,9 @@ protected override string ApplySystemOrdering(ref Sql<ISqlContext> sql, Ordering
// the whole CASE fragment in ORDER BY due to it not being detected by NPoco
var sqlText = InsertBefore(sql.SQL, "FROM",

// when invariant, ie 'variations' does not have the culture flag (value 1), use the global 'published' flag on pcv.id,
// when invariant, ie 'variations' does not have the culture flag (value 1), it should be safe to simply use the published flag on umbracoDocument,
// otherwise check if there's a version culture variation for the lang, via ccv.id
", (CASE WHEN (ctype.variations & 1) = 0 THEN (CASE WHEN pcv.id IS NULL THEN 0 ELSE 1 END) ELSE (CASE WHEN ccvp.id IS NULL THEN 0 ELSE 1 END) END) AS ordering "); // trailing space is important!
$", (CASE WHEN (ctype.variations & 1) = 0 THEN ({SqlSyntax.GetFieldName<DocumentDto>(x => x.Published)}) ELSE (CASE WHEN ccvp.id IS NULL THEN 0 ELSE 1 END) END) AS ordering "); // trailing space is important!

sql = Sql(sqlText, sql.Arguments);

Expand Down