Merge branch 'temp8' into temp8-backoffice-search-with-variants

This commit is contained in:
Stephan
2018-12-18 17:05:17 +01:00
36 changed files with 254 additions and 377 deletions

View File

@@ -41,7 +41,7 @@ namespace Umbraco.Web.Install.Controllers
public bool PostValidateDatabaseConnection(DatabaseModel model)
{
var canConnect = _databaseBuilder.CheckConnection(model.DatabaseType.ToString(), model.ConnectionString, model.Server, model.DatabaseName, model.Login, model.Password, model.IntegratedAuth);
var canConnect = _databaseBuilder.CanConnect(model.DatabaseType.ToString(), model.ConnectionString, model.Server, model.DatabaseName, model.Login, model.Password, model.IntegratedAuth);
return canConnect;
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Configuration;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Migrations.Install;
using Umbraco.Web.Install.Models;
@@ -29,7 +28,7 @@ namespace Umbraco.Web.Install.InstallSteps
database = new DatabaseModel();
}
if (_databaseBuilder.CheckConnection(database.DatabaseType.ToString(), database.ConnectionString, database.Server, database.DatabaseName, database.Login, database.Password, database.IntegratedAuth) == false)
if (_databaseBuilder.CanConnect(database.DatabaseType.ToString(), database.ConnectionString, database.Server, database.DatabaseName, database.Login, database.Password, database.IntegratedAuth) == false)
{
throw new InstallException("Could not connect to the database");
}
@@ -79,8 +78,7 @@ namespace Umbraco.Web.Install.InstallSteps
try
{
//Since a connection string was present we verify the db can connect and query
var result = _databaseBuilder.ValidateDatabaseSchema();
result.DetermineInstalledVersion();
_ = _databaseBuilder.ValidateSchema();
return false;
}
catch (Exception ex)

View File

@@ -29,7 +29,7 @@ namespace Umbraco.Web.Install.InstallSteps
if (_runtime.Level == RuntimeLevel.Run)
throw new Exception("Umbraco is already configured!");
var result = _databaseBuilder.CreateDatabaseSchemaAndData();
var result = _databaseBuilder.CreateSchemaAndData();
if (result.Success == false)
{

View File

@@ -63,18 +63,10 @@ namespace Umbraco.Web.Install.InstallSteps
if (_databaseBuilder.IsConnectionStringConfigured(databaseSettings))
{
//Since a connection string was present we verify whether this is an upgrade or an empty db
var result = _databaseBuilder.ValidateDatabaseSchema();
var determinedVersion = result.DetermineInstalledVersion();
if (determinedVersion.Equals(new Version(0, 0, 0)))
{
//Fresh install
return false;
}
//Upgrade
return true;
// a connection string was present, determine whether this is an install/upgrade
// return true (upgrade) if there is an installed version, else false (install)
var result = _databaseBuilder.ValidateSchema();
return result.DetermineHasInstalledVersion();
}
//no connection string configured, probably a fresh install

View File

@@ -142,7 +142,7 @@ namespace Umbraco.Web.Models
public abstract PublishedItemType ItemType { get; }
/// <inheritdoc />
public abstract bool IsDraft { get; }
public abstract bool IsDraft(string culture = null);
#endregion

View File

@@ -147,7 +147,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
var urlSegment = n.GetUrlSegment(culture);
var hasDomains = _domainHelper.NodeHasDomains(n.Id);
while (hasDomains == false && n != null) // n is null at root
{
{
// no segment indicates this is not published when this is a variant
if (urlSegment.IsNullOrWhiteSpace()) return null;
@@ -173,7 +173,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
var path = "/" + string.Join("/", pathParts); // will be "/" or "/foo" or "/foo/bar" etc
//prefix the root node id containing the domain if it exists (this is a standard way of creating route paths)
//and is done so that we know the ID of the domain node for the path
var route = (n?.Id.ToString(CultureInfo.InvariantCulture) ?? "") + path;
var route = (n?.Id.ToString(CultureInfo.InvariantCulture) ?? "") + path;
return route;
}
@@ -223,24 +223,14 @@ namespace Umbraco.Web.PublishedCache.NuCache
public override IPublishedContent GetById(bool preview, int contentId)
{
var n = _snapshot.Get(contentId);
if (n == null) return null;
// both .Draft and .Published cannot be null at the same time
return preview
? n.Draft ?? GetPublishedContentAsPreviewing(n.Published)
: n.Published;
var node = _snapshot.Get(contentId);
return GetNodePublishedContent(node, preview);
}
public override IPublishedContent GetById(bool preview, Guid contentId)
{
var n = _snapshot.Get(contentId);
if (n == null) return null;
// both .Draft and .Published cannot be null at the same time
return preview
? n.Draft ?? GetPublishedContentAsPreviewing(n.Published)
: n.Published;
var node = _snapshot.Get(contentId);
return GetNodePublishedContent(node, preview);
}
public override bool HasById(bool preview, int contentId)
@@ -274,14 +264,24 @@ namespace Umbraco.Web.PublishedCache.NuCache
var c = _snapshot.GetAtRoot();
// both .Draft and .Published cannot be null at the same time
return c.Select(n => preview
? n.Draft ?? GetPublishedContentAsPreviewing(n.Published)
: n.Published).WhereNotNull().OrderBy(x => x.SortOrder);
return c.Select(n => GetNodePublishedContent(n, preview)).WhereNotNull().OrderBy(x => x.SortOrder);
}
private static IPublishedContent GetNodePublishedContent(ContentNode node, bool preview)
{
if (node == null)
return null;
// both .Draft and .Published cannot be null at the same time
return preview
? node.Draft ?? GetPublishedContentAsDraft(node.Published)
: node.Published;
}
// gets a published content as a previewing draft, if preview is true
// this is for published content when previewing
internal static IPublishedContent GetPublishedContentAsPreviewing(IPublishedContent content /*, bool preview*/)
private static IPublishedContent GetPublishedContentAsDraft(IPublishedContent content /*, bool preview*/)
{
if (content == null /*|| preview == false*/) return null; //content;
@@ -290,7 +290,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
// case we need to unwrap to get to the original IPublishedContentOrMedia.
var inner = PublishedContent.UnwrapIPublishedContent(content);
return inner.AsPreviewingModel();
return inner.AsDraft();
}
public override bool HasContent(bool preview)

View File

@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using Umbraco.Core.Serialization;
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
{
@@ -9,9 +10,11 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
internal class ContentNestedData
{
[JsonProperty("properties")]
[JsonConverter(typeof(CaseInsensitiveDictionaryConverter<PropertyData[]>))]
public Dictionary<string, PropertyData[]> PropertyData { get; set; }
[JsonProperty("cultureData")]
[JsonConverter(typeof(CaseInsensitiveDictionaryConverter<CultureVariation>))]
public Dictionary<string, CultureVariation> CultureData { get; set; }
}
}

View File

@@ -13,5 +13,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
[JsonProperty("date")]
public DateTime Date { get; set; }
[JsonProperty("isDraft")]
public bool IsDraft { get; set; }
}
}

View File

@@ -182,27 +182,30 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
ContentData d = null;
ContentData p = null;
if (dto.EditData == null)
if (dto.Edited)
{
if (Debugger.IsAttached)
throw new Exception("Missing cmsContentNu edited content for node " + dto.Id + ", consider rebuilding.");
Current.Logger.Warn<DatabaseDataSource>("Missing cmsContentNu edited content for node {NodeId}, consider rebuilding.", dto.Id);
}
else
{
var nested = DeserializeNestedData(dto.EditData);
d = new ContentData
if (dto.EditData == null)
{
Name = dto.EditName,
Published = false,
TemplateId = dto.EditTemplateId,
VersionId = dto.VersionId,
VersionDate = dto.EditVersionDate,
WriterId = dto.EditWriterId,
Properties = nested.PropertyData,
CultureInfos = nested.CultureData
};
if (Debugger.IsAttached)
throw new Exception("Missing cmsContentNu edited content for node " + dto.Id + ", consider rebuilding.");
Current.Logger.Warn<DatabaseDataSource>("Missing cmsContentNu edited content for node {NodeId}, consider rebuilding.", dto.Id);
}
else
{
var nested = DeserializeNestedData(dto.EditData);
d = new ContentData
{
Name = dto.EditName,
Published = false,
TemplateId = dto.EditTemplateId,
VersionId = dto.VersionId,
VersionDate = dto.EditVersionDate,
WriterId = dto.EditWriterId,
Properties = nested.PropertyData,
CultureInfos = nested.CultureData
};
}
}
if (dto.Published)

View File

@@ -29,7 +29,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.Navigable
XmlString(i++, _content.WriterId),
XmlString(i++, _content.CreatorId),
XmlString(i++, _content.UrlSegment),
XmlString(i, _content.IsDraft)
XmlString(i, _content.IsDraft())
};
}

View File

@@ -273,8 +273,27 @@ namespace Umbraco.Web.PublishedCache.NuCache
/// <inheritdoc />
public override PublishedItemType ItemType => _contentNode.ContentType.ItemType;
// fixme
// was => _contentData.Published == false;
/// <inheritdoc />
public override bool IsDraft => _contentData.Published == false;
public override bool IsDraft(string culture = null)
{
// if this is the 'published' published content, nothing can be draft
if (_contentData.Published)
return false;
// not the 'published' published content, and does not vary = must be draft
if (!ContentType.VariesByCulture())
return true;
// handle context culture
if (culture == null)
culture = VariationContextAccessor?.VariationContext?.Culture ?? "";
// not the 'published' published content, and varies
// = depends on the culture
return _contentData.CultureInfos.TryGetValue(culture, out var cvar) && cvar.IsDraft;
}
#endregion
@@ -410,7 +429,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
private string AsPreviewingCacheKey => _asPreviewingCacheKey ?? (_asPreviewingCacheKey = CacheKeys.PublishedContentAsPreviewing(Key));
// used by ContentCache
internal IPublishedContent AsPreviewingModel()
internal IPublishedContent AsDraft()
{
if (IsPreviewing)
return this;

View File

@@ -1206,7 +1206,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
foreach (var (culture, info) in infos)
{
cultureData[culture] = new CultureVariation { Name = info.Name, Date = content.GetUpdateDate(culture) ?? DateTime.MinValue };
var cultureIsDraft = !published && content is IContent d && d.IsCultureEdited(culture);
cultureData[culture] = new CultureVariation { Name = info.Name, Date = content.GetUpdateDate(culture) ?? DateTime.MinValue, IsDraft = cultureIsDraft };
}
}

View File

@@ -79,7 +79,7 @@ namespace Umbraco.Web.PublishedCache
public override PublishedItemType ItemType => PublishedItemType.Member;
public override bool IsDraft => false;
public override bool IsDraft(string culture = null) => false;
public override IPublishedContent Parent => null;

View File

@@ -176,7 +176,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
public override int Level => _level;
public override bool IsDraft => false;
public override bool IsDraft(string culture = null) => false;
public override IEnumerable<IPublishedProperty> Properties => _properties;

View File

@@ -221,13 +221,10 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
}
}
public override bool IsDraft
public override bool IsDraft(string culture = null)
{
get
{
EnsureNodeInitialized();
return _isDraft;
}
EnsureNodeInitialized();
return _isDraft; // bah
}
public override IEnumerable<IPublishedProperty> Properties

View File

@@ -141,50 +141,35 @@ namespace Umbraco.Web
#endregion
// fixme - .HasValue() and .Value() refactoring - in progress - see exceptions below
#region HasValue
#region HasValue, Value, Value<T>
/// <summary>
/// Gets a value indicating whether the content has a value for a property identified by its alias.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="alias">The property alias.</param>
/// <param name="recurse">A value indicating whether to navigate the tree upwards until a property with a value is found.</param>
/// <param name="culture">The variation language.</param>
/// <param name="segment">The variation segment.</param>
/// <param name="fallback">Optional fallback strategy.</param>
/// <returns>A value indicating whether the content has a value for the property identified by the alias.</returns>
/// <remarks>Returns true if <c>GetProperty(alias, recurse)</c> is not <c>null</c> and <c>GetProperty(alias, recurse).HasValue</c> is <c>true</c>.</remarks>
public static bool HasValue(this IPublishedContent content, string alias, bool recurse)
/// <remarks>Returns true if HasValue is true, or a fallback strategy can provide a value.</remarks>
public static bool HasValue(this IPublishedContent content, string alias, string culture = null, string segment = null, Fallback fallback = default)
{
throw new NotImplementedException("WorkInProgress");
var property = content.GetProperty(alias);
//var prop = content.GetProperty(alias, recurse);
//return prop != null && prop.HasValue();
// if we have a property, and it has a value, return that value
if (property != null && property.HasValue(culture, segment))
return true;
// else let fallback try to get a value
// fixme - really?
if (PublishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, null, out _))
return true;
// else... no
return false;
}
/// <summary>
/// Returns one of two strings depending on whether the content has a value for a property identified by its alias.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="alias">The property alias.</param>
/// <param name="recurse">A value indicating whether to navigate the tree upwards until a property with a value is found.</param>
/// <param name="valueIfTrue">The value to return if the content has a value for the property.</param>
/// <param name="valueIfFalse">The value to return if the content has no value for the property.</param>
/// <returns>Either <paramref name="valueIfTrue"/> or <paramref name="valueIfFalse"/> depending on whether the content
/// has a value for the property identified by the alias.</returns>
public static IHtmlString HasValue(this IPublishedContent content, string alias, bool recurse,
string valueIfTrue, string valueIfFalse = null)
{
throw new NotImplementedException("WorkInProgress");
//return content.HasValue(alias, recurse)
// ? new HtmlString(valueIfTrue)
// : new HtmlString(valueIfFalse ?? string.Empty);
}
#endregion
#region Value
/// <summary>
/// Gets the value of a content's property identified by its alias, if it exists, otherwise a default value.
/// </summary>
@@ -207,15 +192,14 @@ namespace Umbraco.Web
if (PublishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, defaultValue, out var value))
return value;
if (property == null)
return null;
// else... if we have a property, at least let the converter return its own
// vision of 'no value' (could be an empty enumerable) - otherwise, default
return property?.GetValue(culture, segment);
// vision of 'no value' (could be an empty enumerable)
return property.GetValue(culture, segment);
}
#endregion
#region Value<T>
/// <summary>
/// Gets the value of a content's property identified by its alias, converted to a specified type.
/// </summary>
@@ -383,16 +367,6 @@ namespace Umbraco.Web
return recursive && content.IsComposedOf(docTypeAlias);
}
public static bool IsNull(this IPublishedContent content, string alias, bool recurse)
{
return content.HasValue(alias, recurse) == false;
}
public static bool IsNull(this IPublishedContent content, string alias)
{
return content.HasValue(alias) == false;
}
#endregion
#region IsSomething: equality

View File

@@ -467,9 +467,9 @@ namespace umbraco
get { return PublishedItemType.Content; }
}
public bool IsDraft
public bool IsDraft(string culture = null)
{
get { throw new NotImplementedException(); }
throw new NotImplementedException();
}
public IPublishedContent Parent