diff --git a/build/Build.bat b/build/Build.bat index bcacc995e1..d1335ea93e 100644 --- a/build/Build.bat +++ b/build/Build.bat @@ -1,5 +1,5 @@ @ECHO OFF -SET release=6.1.3 +SET release=6.1.4 SET comment= SET version=%release% diff --git a/build/NuSpecs/UmbracoCms.Core.nuspec b/build/NuSpecs/UmbracoCms.Core.nuspec index 996f05936a..009b47b89b 100644 --- a/build/NuSpecs/UmbracoCms.Core.nuspec +++ b/build/NuSpecs/UmbracoCms.Core.nuspec @@ -23,6 +23,7 @@ + diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Core/Configuration/UmbracoVersion.cs index dc50952f8d..9863edfee3 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/UmbracoVersion.cs @@ -5,7 +5,7 @@ namespace Umbraco.Core.Configuration { public class UmbracoVersion { - private static readonly Version Version = new Version("6.1.3"); + private static readonly Version Version = new Version("6.1.4"); /// /// Gets the current version of Umbraco. diff --git a/src/Umbraco.Core/DatabaseContext.cs b/src/Umbraco.Core/DatabaseContext.cs index 4f52f61683..1311593e90 100644 --- a/src/Umbraco.Core/DatabaseContext.cs +++ b/src/Umbraco.Core/DatabaseContext.cs @@ -296,16 +296,13 @@ namespace Umbraco.Core if (databaseSettings != null && string.IsNullOrWhiteSpace(databaseSettings.ConnectionString) == false && string.IsNullOrWhiteSpace(databaseSettings.ProviderName) == false) { var providerName = "System.Data.SqlClient"; + string connString = null; if (!string.IsNullOrEmpty(ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName].ProviderName)) { providerName = ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName].ProviderName; - - _connectionString = - ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName].ConnectionString; - + connString = ConfigurationManager.ConnectionStrings[GlobalSettings.UmbracoConnectionName].ConnectionString; } - - Initialize(providerName); + Initialize(providerName, connString); } else if (ConfigurationManager.AppSettings.ContainsKey(GlobalSettings.UmbracoConnectionName) && string.IsNullOrEmpty(ConfigurationManager.AppSettings[GlobalSettings.UmbracoConnectionName]) == false) { @@ -369,6 +366,12 @@ namespace Umbraco.Core } } + internal void Initialize(string providerName, string connectionString) + { + _connectionString = connectionString; + Initialize(providerName); + } + internal DatabaseSchemaResult ValidateDatabaseSchema() { if (_configured == false || (string.IsNullOrEmpty(_connectionString) || string.IsNullOrEmpty(ProviderName))) diff --git a/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs b/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs index 1a723166e6..2014ceb1cf 100644 --- a/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs +++ b/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs @@ -14,9 +14,9 @@ namespace Umbraco.Core.Persistence /// internal class DefaultDatabaseFactory : DisposableObject, IDatabaseFactory { - private readonly string _connectionStringName; - private readonly string _connectionString; - private readonly string _providerName; + private readonly string _connectionStringName; + public string ConnectionString { get; private set; } + public string ProviderName { get; private set; } //very important to have ThreadStatic: // see: http://issues.umbraco.org/issue/U4-2172 @@ -52,8 +52,8 @@ namespace Umbraco.Core.Persistence { Mandate.ParameterNotNullOrEmpty(connectionString, "connectionString"); Mandate.ParameterNotNullOrEmpty(providerName, "providerName"); - _connectionString = connectionString; - _providerName = providerName; + ConnectionString = connectionString; + ProviderName = providerName; } public UmbracoDatabase CreateDatabase() @@ -68,8 +68,8 @@ namespace Umbraco.Core.Persistence //double check if (_nonHttpInstance == null) { - _nonHttpInstance = string.IsNullOrEmpty(_connectionString) == false && string.IsNullOrEmpty(_providerName) == false - ? new UmbracoDatabase(_connectionString, _providerName) + _nonHttpInstance = string.IsNullOrEmpty(ConnectionString) == false && string.IsNullOrEmpty(ProviderName) == false + ? new UmbracoDatabase(ConnectionString, ProviderName) : new UmbracoDatabase(_connectionStringName); } } @@ -81,8 +81,8 @@ namespace Umbraco.Core.Persistence if (HttpContext.Current.Items.Contains(typeof(DefaultDatabaseFactory)) == false) { HttpContext.Current.Items.Add(typeof (DefaultDatabaseFactory), - string.IsNullOrEmpty(_connectionString) == false && string.IsNullOrEmpty(_providerName) == false - ? new UmbracoDatabase(_connectionString, _providerName) + string.IsNullOrEmpty(ConnectionString) == false && string.IsNullOrEmpty(ProviderName) == false + ? new UmbracoDatabase(ConnectionString, ProviderName) : new UmbracoDatabase(_connectionStringName)); } return (UmbracoDatabase)HttpContext.Current.Items[typeof(DefaultDatabaseFactory)]; diff --git a/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs b/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs index 51ae2638b0..c962224689 100644 --- a/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs +++ b/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs @@ -6,6 +6,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Persistence.Migrations.Initial; +using Umbraco.Core.Persistence.Querying; using Umbraco.Core.Persistence.SqlSyntax; namespace Umbraco.Core.Persistence @@ -32,76 +33,142 @@ namespace Umbraco.Core.Persistence public static void BulkInsertRecords(this Database db, IEnumerable collection) { + //don't do anything if there are no records. + if (collection.Any() == false) + return; + using (var tr = db.GetTransaction()) { - try - { - if (SqlSyntaxContext.SqlSyntaxProvider is SqlCeSyntaxProvider) - { - //SqlCe doesn't support bulk insert statements! - - foreach (var poco in collection) - { - db.Insert(poco); - } - - } - else - { - string sql; - using (var cmd = db.GenerateBulkInsertCommand(collection, db.Connection, out sql)) - { - cmd.CommandText = sql; - cmd.ExecuteNonQuery(); - } - } - - tr.Complete(); - } - catch - { - tr.Dispose(); - throw; - } + db.BulkInsertRecords(collection, tr); } } - internal static IDbCommand GenerateBulkInsertCommand(this Database db, IEnumerable collection, IDbConnection connection, out string sql) + public static void BulkInsertRecords(this Database db, IEnumerable collection, Transaction tr) { + //don't do anything if there are no records. + if (collection.Any() == false) + return; + + try + { + if (SqlSyntaxContext.SqlSyntaxProvider is SqlCeSyntaxProvider) + { + //SqlCe doesn't support bulk insert statements! + + foreach (var poco in collection) + { + db.Insert(poco); + } + } + else + { + string[] sqlStatements; + var cmds = db.GenerateBulkInsertCommand(collection, db.Connection, out sqlStatements); + for (var i = 0; i < sqlStatements.Length; i++) + { + using (var cmd = cmds[i]) + { + cmd.CommandText = sqlStatements[i]; + cmd.ExecuteNonQuery(); + } + } + } + + tr.Complete(); + } + catch + { + tr.Dispose(); + throw; + } + } + + /// + /// Creates a bulk insert command + /// + /// + /// + /// + /// + /// + /// Sql commands with populated command parameters required to execute the sql statement + /// + /// The limits for number of parameters are 2100 (in sql server, I think there's many more allowed in mysql). So + /// we need to detect that many params and split somehow. + /// For some reason the 2100 limit is not actually allowed even though the exception from sql server mentions 2100 as a max, perhaps it is 2099 + /// that is max. I've reduced it to 2000 anyways. + /// + internal static IDbCommand[] GenerateBulkInsertCommand( + this Database db, + IEnumerable collection, + IDbConnection connection, + out string[] sql) + { + //A filter used below a few times to get all columns except result cols and not the primary key if it is auto-incremental + Func, bool> includeColumn = (data, column) => + { + if (column.Value.ResultColumn) return false; + if (data.TableInfo.AutoIncrement && column.Key == data.TableInfo.PrimaryKey) return false; + return true; + }; + var pd = Database.PocoData.ForType(typeof(T)); var tableName = db.EscapeTableName(pd.TableInfo.TableName); - //get all columns but not the primary key if it is auto-incremental - var cols = string.Join(", ", ( - from c in pd.Columns - where - //don't return ResultColumns - !c.Value.ResultColumn - //if the table is auto-incremental, don't return the primary key - && (pd.TableInfo.AutoIncrement && c.Key != pd.TableInfo.PrimaryKey) - select tableName + "." + db.EscapeSqlIdentifier(c.Key)) - .ToArray()); + //get all columns to include and format for sql + var cols = string.Join(", ", + pd.Columns + .Where(c => includeColumn(pd, c)) + .Select(c => tableName + "." + db.EscapeSqlIdentifier(c.Key)).ToArray()); - var cmd = db.CreateCommand(connection, ""); + var itemArray = collection.ToArray(); - var pocoValues = new List(); - var index = 0; - foreach (var poco in collection) + //calculate number of parameters per item + var paramsPerItem = pd.Columns.Count(i => includeColumn(pd, i)); + + //Example calc: + // Given: we have 4168 items in the itemArray, each item contains 8 command parameters (values to be inserterted) + // 2100 / 8 = 262.5 + // Math.Floor(2100 / 8) = 262 items per trans + // 4168 / 262 = 15.908... = there will be 16 trans in total + + //all items will be included if we have disabled db parameters + var itemsPerTrans = Math.Floor(2000.00 / paramsPerItem); + //there will only be one transaction if we have disabled db parameters + var numTrans = Math.Ceiling(itemArray.Length / itemsPerTrans); + + var sqlQueries = new List(); + var commands = new List(); + + for (var tIndex = 0; tIndex < numTrans; tIndex++) { - var values = new List(); - foreach (var i in pd.Columns) + var itemsForTrans = itemArray + .Skip(tIndex * (int)itemsPerTrans) + .Take((int)itemsPerTrans); + + var cmd = db.CreateCommand(connection, ""); + var pocoValues = new List(); + var index = 0; + foreach (var poco in itemsForTrans) { - if (pd.TableInfo.AutoIncrement && i.Key == pd.TableInfo.PrimaryKey) + var values = new List(); + //get all columns except result cols and not the primary key if it is auto-incremental + foreach (var i in pd.Columns.Where(x => includeColumn(pd, x))) { - continue; + db.AddParam(cmd, i.Value.GetValue(poco), "@"); + values.Add(string.Format("{0}{1}", "@", index++)); } - values.Add(string.Format("{0}{1}", "@", index++)); - db.AddParam(cmd, i.Value.GetValue(poco), "@"); + pocoValues.Add("(" + string.Join(",", values.ToArray()) + ")"); } - pocoValues.Add("(" + string.Join(",", values.ToArray()) + ")"); + + var sqlResult = string.Format("INSERT INTO {0} ({1}) VALUES {2}", tableName, cols, string.Join(", ", pocoValues)); + sqlQueries.Add(sqlResult); + commands.Add(cmd); } - sql = string.Format("INSERT INTO {0} ({1}) VALUES {2}", tableName, cols, string.Join(", ", pocoValues)); - return cmd; + + sql = sqlQueries.ToArray(); + + return commands.ToArray(); } public static void CreateTable(this Database db, bool overwrite, Type modelType) diff --git a/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionHelper.cs b/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionHelper.cs index 470a098fd8..559b978721 100644 --- a/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionHelper.cs +++ b/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionHelper.cs @@ -435,38 +435,7 @@ namespace Umbraco.Core.Persistence.Querying public virtual string GetQuotedValue(object value, Type fieldType) { - if (value == null) return "NULL"; - - if (!fieldType.UnderlyingSystemType.IsValueType && fieldType != typeof(string)) - { - throw new NotSupportedException( - string.Format("Property of type: {0} is not supported", fieldType.FullName)); - } - - if (fieldType == typeof(int)) - return ((int)value).ToString(CultureInfo.InvariantCulture); - - if (fieldType == typeof(float)) - return ((float)value).ToString(CultureInfo.InvariantCulture); - - if (fieldType == typeof(double)) - return ((double)value).ToString(CultureInfo.InvariantCulture); - - if (fieldType == typeof(decimal)) - return ((decimal)value).ToString(CultureInfo.InvariantCulture); - - if (fieldType == typeof (DateTime)) - { - return "'" + EscapeParam(((DateTime)value).ToIsoString()) + "'"; - } - - - if (fieldType == typeof(bool)) - return ((bool)value) ? Convert.ToString(1, CultureInfo.InvariantCulture) : Convert.ToString(0, CultureInfo.InvariantCulture); - - return ShouldQuoteValue(fieldType) - ? "'" + EscapeParam(value) + "'" - : value.ToString(); + return QueryHelper.GetQuotedValue(value, fieldType, EscapeParam, ShouldQuoteValue); } public virtual string EscapeParam(object paramValue) diff --git a/src/Umbraco.Core/Persistence/Querying/PocoToSqlExpressionHelper.cs b/src/Umbraco.Core/Persistence/Querying/PocoToSqlExpressionHelper.cs index d065849102..f84933b3e7 100644 --- a/src/Umbraco.Core/Persistence/Querying/PocoToSqlExpressionHelper.cs +++ b/src/Umbraco.Core/Persistence/Querying/PocoToSqlExpressionHelper.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Text; @@ -440,43 +439,7 @@ namespace Umbraco.Core.Persistence.Querying public virtual string GetQuotedValue(object value, Type fieldType) { - if (value == null) return "NULL"; - - if (!fieldType.UnderlyingSystemType.IsValueType && fieldType != typeof(string)) - { - //if (TypeSerializer.CanCreateFromString(fieldType)) - //{ - // return "'" + EscapeParam(TypeSerializer.SerializeToString(value)) + "'"; - //} - - throw new NotSupportedException( - string.Format("Property of type: {0} is not supported", fieldType.FullName)); - } - - if (fieldType == typeof(int)) - return ((int)value).ToString(CultureInfo.InvariantCulture); - - if (fieldType == typeof(float)) - return ((float)value).ToString(CultureInfo.InvariantCulture); - - if (fieldType == typeof(double)) - return ((double)value).ToString(CultureInfo.InvariantCulture); - - if (fieldType == typeof(decimal)) - return ((decimal)value).ToString(CultureInfo.InvariantCulture); - - if (fieldType == typeof (DateTime)) - { - return "'" + EscapeParam(((DateTime)value).ToIsoString()) + "'"; - } - - - if (fieldType == typeof(bool)) - return ((bool)value) ? Convert.ToString(1, CultureInfo.InvariantCulture) : Convert.ToString(0, CultureInfo.InvariantCulture); - - return ShouldQuoteValue(fieldType) - ? "'" + EscapeParam(value) + "'" - : value.ToString(); + return QueryHelper.GetQuotedValue(value, fieldType, EscapeParam, ShouldQuoteValue); } public virtual string EscapeParam(object paramValue) diff --git a/src/Umbraco.Core/Persistence/Querying/QueryHelper.cs b/src/Umbraco.Core/Persistence/Querying/QueryHelper.cs new file mode 100644 index 0000000000..f69e106f57 --- /dev/null +++ b/src/Umbraco.Core/Persistence/Querying/QueryHelper.cs @@ -0,0 +1,70 @@ +using System; +using System.Globalization; + +namespace Umbraco.Core.Persistence.Querying +{ + /// + /// Logic that is shared with the expression helpers + /// + internal class QueryHelper + { + public static string GetQuotedValue(object value, Type fieldType, Func escapeCallback = null, Func shouldQuoteCallback = null) + { + if (value == null) return "NULL"; + + if (escapeCallback == null) + { + escapeCallback = EscapeParam; + } + if (shouldQuoteCallback == null) + { + shouldQuoteCallback = ShouldQuoteValue; + } + + if (!fieldType.UnderlyingSystemType.IsValueType && fieldType != typeof(string)) + { + //if (TypeSerializer.CanCreateFromString(fieldType)) + //{ + // return "'" + EscapeParam(TypeSerializer.SerializeToString(value)) + "'"; + //} + + throw new NotSupportedException( + string.Format("Property of type: {0} is not supported", fieldType.FullName)); + } + + if (fieldType == typeof(int)) + return ((int)value).ToString(CultureInfo.InvariantCulture); + + if (fieldType == typeof(float)) + return ((float)value).ToString(CultureInfo.InvariantCulture); + + if (fieldType == typeof(double)) + return ((double)value).ToString(CultureInfo.InvariantCulture); + + if (fieldType == typeof(decimal)) + return ((decimal)value).ToString(CultureInfo.InvariantCulture); + + if (fieldType == typeof(DateTime)) + { + return "'" + EscapeParam(((DateTime)value).ToIsoString()) + "'"; + } + + if (fieldType == typeof(bool)) + return ((bool)value) ? Convert.ToString(1, CultureInfo.InvariantCulture) : Convert.ToString(0, CultureInfo.InvariantCulture); + + return ShouldQuoteValue(fieldType) + ? "'" + EscapeParam(value) + "'" + : value.ToString(); + } + + public static string EscapeParam(object paramValue) + { + return paramValue.ToString().Replace("'", "''"); + } + + public static bool ShouldQuoteValue(Type fieldType) + { + return true; + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs index 755fc5f04a..e2c981f62d 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs @@ -449,7 +449,19 @@ namespace Umbraco.Core.Persistence.Repositories foreach (var dto in dtos) { - yield return CreateContentFromDto(dto, dto.VersionId); + //Check in the cache first. If it exists there AND it is published + // then we can use that entity. Otherwise if it is not published (which can be the case + // because we only store the 'latest' entries in the cache which might not be the published + // version) + var fromCache = TryGetFromCache(dto.NodeId); + if (fromCache.Success && fromCache.Result.Published) + { + yield return fromCache.Result; + } + else + { + yield return CreateContentFromDto(dto, dto.VersionId); + } } } diff --git a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs index 8453bcd6da..667395c3b4 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Interfaces/IContentRepository.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.Persistence.Repositories IContent GetByLanguage(int id, string language); /// - /// Gets all published Content byh the specified query + /// Gets all published Content by the specified query /// /// Query to execute against published versions /// An enumerable list of diff --git a/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs index 98f8434047..06fa303123 100644 --- a/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs @@ -86,11 +86,10 @@ namespace Umbraco.Core.Persistence.Repositories /// public TEntity Get(TId id) { - Guid key = id is int ? ConvertIdToGuid(id) : ConvertStringIdToGuid(id.ToString()); - var rEntity = _cache.GetById(typeof(TEntity), key); - if (rEntity != null) + var fromCache = TryGetFromCache(id); + if (fromCache.Success) { - return (TEntity)rEntity; + return fromCache.Result; } var entity = PerformGet(id); @@ -113,6 +112,17 @@ namespace Umbraco.Core.Persistence.Repositories return entity; } + protected Attempt TryGetFromCache(TId id) + { + Guid key = id is int ? ConvertIdToGuid(id) : ConvertStringIdToGuid(id.ToString()); + var rEntity = _cache.GetById(typeof(TEntity), key); + if (rEntity != null) + { + return new Attempt(true, (TEntity) rEntity); + } + return Attempt.False; + } + protected abstract IEnumerable PerformGetAll(params TId[] ids); /// /// Gets all entities of type TEntity or a list according to the passed in Ids @@ -174,14 +184,12 @@ namespace Umbraco.Core.Persistence.Repositories /// public bool Exists(TId id) { - Guid key = id is int ? ConvertIdToGuid(id) : ConvertStringIdToGuid(id.ToString()); - var rEntity = _cache.GetById(typeof(TEntity), key); - if (rEntity != null) + var fromCache = TryGetFromCache(id); + if (fromCache.Success) { return true; } - - return PerformExists(id); + return PerformExists(id); } protected abstract int PerformCount(IQuery query); diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 6aaf82601c..7d26a52867 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -13,6 +13,7 @@ using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Caching; using Umbraco.Core.Persistence.Querying; +using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Publishing; @@ -263,6 +264,17 @@ namespace Umbraco.Core.Services } } + internal IEnumerable GetPublishedContentOfContentType(int id) + { + using (var repository = _repositoryFactory.CreateContentRepository(_uowProvider.GetUnitOfWork())) + { + var query = Query.Builder.Where(x => x.ContentTypeId == id); + var contents = repository.GetByPublishedVersion(query); + + return contents; + } + } + /// /// Gets a collection of objects by Level /// @@ -444,6 +456,19 @@ namespace Umbraco.Core.Services } } + /// + /// Gets all published content items + /// + /// + internal IEnumerable GetAllPublished() + { + using (var repository = _repositoryFactory.CreateContentRepository(_uowProvider.GetUnitOfWork())) + { + var query = Query.Builder.Where(x => x.Trashed == false); + return repository.GetByPublishedVersion(query); + } + } + /// /// Gets a collection of objects, which has an expiration date less than or equal to today. /// @@ -1367,46 +1392,45 @@ namespace Umbraco.Core.Services var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateContentRepository(uow)) { - if (contentTypeIds.Any() == false) - { - //Remove all Document records from the cmsContentXml table (DO NOT REMOVE Media/Members!) - uow.Database.Execute(@"DELETE FROM cmsContentXml WHERE nodeId IN - (SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml - INNER JOIN cmsDocument ON cmsContentXml.nodeId = cmsDocument.nodeId)"); - - //get all content items that are published - // Consider creating a Path query instead of recursive method: - // var query = Query.Builder.Where(x => x.Path.StartsWith("-1")); - var rootContent = GetRootContent(); - foreach (var content in rootContent.Where(content => content.Published)) - { - list.Add(content); - list.AddRange(GetPublishedDescendants(content)); - } - } - else - { - foreach (var id in contentTypeIds) - { - //first we'll clear out the data from the cmsContentXml table for this type - uow.Database.Execute(@"delete from cmsContentXml where nodeId in -(select cmsDocument.nodeId from cmsDocument - inner join cmsContent on cmsDocument.nodeId = cmsContent.nodeId - where published = 1 and contentType = @contentTypeId)", new {contentTypeId = id}); + //First we're going to get the data that needs to be inserted before clearing anything, this + //ensures that we don't accidentally leave the content xml table empty if something happens + //during the lookup process. - //now get all published content objects of this type and add to the list - list.AddRange(GetContentOfContentType(id).Where(content => content.Published)); - } - } + list.AddRange(contentTypeIds.Any() == false + ? GetAllPublished() + : contentTypeIds.SelectMany(GetPublishedContentOfContentType)); + var xmlItems = new List(); foreach (var c in list) { - //generate the xml var xml = c.ToXml(); - //create the dto to insert - var poco = new ContentXmlDto { NodeId = c.Id, Xml = xml.ToString(SaveOptions.None) }; - //insert it into the database - uow.Database.Insert(poco); + xmlItems.Add(new ContentXmlDto {NodeId = c.Id, Xml = xml.ToString(SaveOptions.None)}); + } + + //Ok, now we need to remove the data and re-insert it, we'll do this all in one transaction too. + using (var tr = uow.Database.GetTransaction()) + { + if (contentTypeIds.Any() == false) + { + //Remove all Document records from the cmsContentXml table (DO NOT REMOVE Media/Members!) + uow.Database.Execute(@"DELETE FROM cmsContentXml WHERE nodeId IN + (SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml + INNER JOIN cmsDocument ON cmsContentXml.nodeId = cmsDocument.nodeId)"); + } + else + { + foreach (var id in contentTypeIds) + { + //first we'll clear out the data from the cmsContentXml table for this type + uow.Database.Execute(@"delete from cmsContentXml where nodeId in +(select cmsDocument.nodeId from cmsDocument + inner join cmsContent on cmsDocument.nodeId = cmsContent.nodeId + where published = 1 and contentType = @contentTypeId)", new { contentTypeId = id }); + } + } + + //bulk insert it into the database + uow.Database.BulkInsertRecords(xmlItems, tr); } } Audit.Add(AuditTypes.Publish, "RebuildXmlStructures completed, the xml has been regenerated in the database", 0, -1); diff --git a/src/Umbraco.Core/Services/MediaService.cs b/src/Umbraco.Core/Services/MediaService.cs index 0e35802961..34f4000d4b 100644 --- a/src/Umbraco.Core/Services/MediaService.cs +++ b/src/Umbraco.Core/Services/MediaService.cs @@ -11,10 +11,11 @@ using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Querying; using Umbraco.Core.Persistence.UnitOfWork; +using Umbraco.Core.Publishing; namespace Umbraco.Core.Services { - /// + /// /// Represents the Media Service, which is an easy access to operations involving /// public class MediaService : IMediaService @@ -875,15 +876,16 @@ namespace Umbraco.Core.Services } } + var xmlItems = new List(); foreach (var c in list) { //generate the xml var xml = c.ToXml(); //create the dto to insert - var poco = new ContentXmlDto { NodeId = c.Id, Xml = xml.ToString(SaveOptions.None) }; - //insert it into the database - uow.Database.Insert(poco); + xmlItems.Add(new ContentXmlDto { NodeId = c.Id, Xml = xml.ToString(SaveOptions.None) }); } + //bulk insert it into the database + uow.Database.BulkInsertRecords(xmlItems); } Audit.Add(AuditTypes.Publish, "RebuildXmlStructures completed, the xml has been regenerated in the database", 0, -1); } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 385f1fcc50..f6e7c85c53 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -483,6 +483,7 @@ + diff --git a/src/Umbraco.Tests/Persistence/PetaPocoExtensionsTest.cs b/src/Umbraco.Tests/Persistence/PetaPocoExtensionsTest.cs index 1cf6aff7b0..3a76e29139 100644 --- a/src/Umbraco.Tests/Persistence/PetaPocoExtensionsTest.cs +++ b/src/Umbraco.Tests/Persistence/PetaPocoExtensionsTest.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text.RegularExpressions; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Models.Rdbms; @@ -73,13 +74,47 @@ namespace Umbraco.Tests.Persistence db.OpenSharedConnection(); // Act - string sql; + string[] sql; db.GenerateBulkInsertCommand(servers, db.Connection, out sql); db.CloseSharedConnection(); // Assert - Assert.That(sql, + Assert.That(sql[0], Is.EqualTo("INSERT INTO [umbracoServer] ([umbracoServer].[address], [umbracoServer].[computerName], [umbracoServer].[registeredDate], [umbracoServer].[lastNotifiedDate], [umbracoServer].[isActive]) VALUES (@0,@1,@2,@3,@4), (@5,@6,@7,@8,@9)")); } + + + [Test] + public void Generate_Bulk_Import_Sql_Exceeding_Max_Params() + { + // Arrange + var db = DatabaseContext.Database; + + var servers = new List(); + for (var i = 0; i < 1500; i++) + { + servers.Add(new ServerRegistrationDto + { + Address = "address" + i, + ComputerName = "computer" + i, + DateRegistered = DateTime.Now, + IsActive = true, + LastNotified = DateTime.Now + }); + } + db.OpenSharedConnection(); + + // Act + string[] sql; + db.GenerateBulkInsertCommand(servers, db.Connection, out sql); + db.CloseSharedConnection(); + + // Assert + Assert.That(sql.Length, Is.EqualTo(4)); + foreach (var s in sql) + { + Assert.LessOrEqual(Regex.Matches(s, "@\\d+").Count, 2000); + } + } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs index b85c4c05b1..b087d42827 100644 --- a/src/Umbraco.Tests/Services/ContentServiceTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs @@ -306,12 +306,13 @@ namespace Umbraco.Tests.Services public void Can_RePublish_All_Content() { // Arrange - var contentService = ServiceContext.ContentService; + var contentService = (ContentService)ServiceContext.ContentService; var rootContent = contentService.GetRootContent(); foreach (var c in rootContent) { contentService.PublishWithChildren(c); } + var allContent = rootContent.Concat(rootContent.SelectMany(x => x.Descendants())); //for testing we need to clear out the contentXml table so we can see if it worked var provider = new PetaPocoUnitOfWorkProvider(); var uow = provider.GetUnitOfWork(); @@ -319,13 +320,49 @@ namespace Umbraco.Tests.Services { uow.Database.TruncateTable("cmsContentXml"); } - + //for this test we are also going to save a revision for a content item that is not published, this is to ensure + //that it's published version still makes it into the cmsContentXml table! + contentService.Save(allContent.Last()); + // Act var published = contentService.RePublishAll(0); // Assert Assert.IsTrue(published); + uow = provider.GetUnitOfWork(); + using (var repo = RepositoryResolver.Current.ResolveByType(uow)) + { + Assert.AreEqual(allContent.Count(), uow.Database.ExecuteScalar("select count(*) from cmsContentXml")); + } + } + + [Test] + public void Can_RePublish_All_Content_Of_Type() + { + // Arrange + var contentService = (ContentService)ServiceContext.ContentService; + var rootContent = contentService.GetRootContent(); + foreach (var c in rootContent) + { + contentService.PublishWithChildren(c); + } var allContent = rootContent.Concat(rootContent.SelectMany(x => x.Descendants())); + //for testing we need to clear out the contentXml table so we can see if it worked + var provider = new PetaPocoUnitOfWorkProvider(); + var uow = provider.GetUnitOfWork(); + using (RepositoryResolver.Current.ResolveByType(uow)) + { + uow.Database.TruncateTable("cmsContentXml"); + } + //for this test we are also going to save a revision for a content item that is not published, this is to ensure + //that it's published version still makes it into the cmsContentXml table! + contentService.Save(allContent.Last()); + + + // Act + contentService.RePublishAll(new int[]{allContent.Last().ContentTypeId}); + + // Assert uow = provider.GetUnitOfWork(); using (var repo = RepositoryResolver.Current.ResolveByType(uow)) { diff --git a/src/Umbraco.Tests/Services/PerformanceTests.cs b/src/Umbraco.Tests/Services/PerformanceTests.cs new file mode 100644 index 0000000000..4a7ad2026a --- /dev/null +++ b/src/Umbraco.Tests/Services/PerformanceTests.cs @@ -0,0 +1,362 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data.SqlServerCe; +using System.Globalization; +using System.Linq; +using System.Threading; +using System.Xml.Linq; +using NUnit.Framework; +using Umbraco.Core; +using Umbraco.Core.Models; +using Umbraco.Core.Models.Rdbms; +using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.Caching; +using Umbraco.Core.Persistence.Repositories; +using Umbraco.Core.Persistence.SqlSyntax; +using Umbraco.Core.Persistence.UnitOfWork; +using Umbraco.Core.Services; +using Umbraco.Tests.TestHelpers; +using Umbraco.Tests.TestHelpers.Entities; + +namespace Umbraco.Tests.Services +{ + /// + /// Tests covering all methods in the ContentService class. + /// This is more of an integration test as it involves multiple layers + /// as well as configuration. + /// + [TestFixture, RequiresSTA] + [NUnit.Framework.Ignore("These should not be run by the server, only directly as they are only benchmark tests")] + public class PerformanceTests : BaseDatabaseFactoryTest + { + [SetUp] + public override void Initialize() + { + base.Initialize(); + } + + protected override string GetDbConnectionString() + { + return @"server=.\SQLEXPRESS;database=UmbTest;user id=sa;password=test"; + } + + protected override string GetDbProviderName() + { + return "System.Data.SqlClient"; + } + + /// + /// new schema per test + /// + protected override DatabaseBehavior DatabaseTestBehavior + { + get { return DatabaseBehavior.NewSchemaPerTest; } + } + + /// + /// don't create anything, we're testing against our own server + /// + protected override void CreateSqlCeDatabase() + { + } + + [TearDown] + public override void TearDown() + { + base.TearDown(); + } + + [Test] + public void Get_All_Published_Content() + { + var result = PrimeDbWithLotsOfContent(); + var contentSvc = (ContentService) ServiceContext.ContentService; + + var countOfPublished = result.Count(x => x.Published); + var contentTypeId = result.First().ContentTypeId; + + using (DisposableTimer.DebugDuration("Getting published content normally")) + { + //do this 10x! + for (var i = 0; i < 10; i++) + { + //clear the cache to make this test valid + RuntimeCacheProvider.Current.Clear(); + + var published = new List(); + //get all content items that are published + var rootContent = contentSvc.GetRootContent(); + foreach (var content in rootContent.Where(content => content.Published)) + { + published.Add(content); + published.AddRange(contentSvc.GetPublishedDescendants(content)); + } + Assert.AreEqual(countOfPublished, published.Count(x => x.ContentTypeId == contentTypeId)); + } + + } + + using (DisposableTimer.DebugDuration("Getting published content optimized")) + { + + //do this 10x! + for (var i = 0; i < 10; i++) + { + //clear the cache to make this test valid + RuntimeCacheProvider.Current.Clear(); + + //get all content items that are published + var published = contentSvc.GetAllPublished(); + + Assert.AreEqual(countOfPublished, published.Count(x => x.ContentTypeId == contentTypeId)); + } + } + } + + [Test] + public void Get_All_Published_Content_Of_Type() + { + var result = PrimeDbWithLotsOfContent(); + var contentSvc = (ContentService)ServiceContext.ContentService; + + var countOfPublished = result.Count(x => x.Published); + var contentTypeId = result.First().ContentTypeId; + + using (DisposableTimer.DebugDuration("Getting published content of type normally")) + { + //do this 10x! + for (var i = 0; i < 10; i++) + { + //clear the cache to make this test valid + RuntimeCacheProvider.Current.Clear(); + //get all content items that are published of this type + var published = contentSvc.GetContentOfContentType(contentTypeId).Where(content => content.Published); + Assert.AreEqual(countOfPublished, published.Count(x => x.ContentTypeId == contentTypeId)); + } + } + + using (DisposableTimer.DebugDuration("Getting published content of type optimized")) + { + + //do this 10x! + for (var i = 0; i < 10; i++) + { + //clear the cache to make this test valid + RuntimeCacheProvider.Current.Clear(); + //get all content items that are published of this type + var published = contentSvc.GetPublishedContentOfContentType(contentTypeId); + Assert.AreEqual(countOfPublished, published.Count(x => x.ContentTypeId == contentTypeId)); + } + } + } + + [Test] + public void Truncate_Insert_Vs_Update_Insert() + { + var customObjectType = Guid.NewGuid(); + //chuck lots of data in the db + var nodes = PrimeDbWithLotsOfContentXmlRecords(customObjectType); + + //now we need to test the difference between truncating all records and re-inserting them as we do now, + //vs updating them (which might result in checking if they exist for or listening on an exception). + using (DisposableTimer.DebugDuration("Starting truncate + normal insert test")) + { + //do this 10x! + for (var i = 0; i < 10; i++) + { + //clear all the xml entries + DatabaseContext.Database.Execute(@"DELETE FROM cmsContentXml WHERE nodeId IN + (SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml + INNER JOIN cmsContent ON cmsContentXml.nodeId = cmsContent.nodeId)"); + + //now we insert each record for the ones we've deleted like we do in the content service. + var xmlItems = nodes.Select(node => new ContentXmlDto { NodeId = node.NodeId, Xml = UpdatedXmlStructure }).ToList(); + foreach (var xml in xmlItems) + { + var result = DatabaseContext.Database.Insert(xml); + } + } + } + + //now, isntead of truncating, we'll attempt to update and if it doesn't work then we insert + using (DisposableTimer.DebugDuration("Starting update test")) + { + //do this 10x! + for (var i = 0; i < 10; i++) + { + //now we insert each record for the ones we've deleted like we do in the content service. + var xmlItems = nodes.Select(node => new ContentXmlDto { NodeId = node.NodeId, Xml = UpdatedXmlStructure }).ToList(); + foreach (var xml in xmlItems) + { + var result = DatabaseContext.Database.Update(xml); + } + } + } + + //now, test truncating but then do bulk insertion of records + using (DisposableTimer.DebugDuration("Starting truncate + bulk insert test")) + { + //do this 10x! + for (var i = 0; i < 10; i++) + { + //clear all the xml entries + DatabaseContext.Database.Execute(@"DELETE FROM cmsContentXml WHERE nodeId IN + (SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml + INNER JOIN cmsContent ON cmsContentXml.nodeId = cmsContent.nodeId)"); + + //now we insert each record for the ones we've deleted like we do in the content service. + var xmlItems = nodes.Select(node => new ContentXmlDto { NodeId = node.NodeId, Xml = UpdatedXmlStructure }).ToList(); + DatabaseContext.Database.BulkInsertRecords(xmlItems); + } + } + + //now, test truncating but then do bulk insertion of records + using (DisposableTimer.DebugDuration("Starting truncate + bulk insert test in one transaction")) + { + //do this 10x! + for (var i = 0; i < 10; i++) + { + //now we insert each record for the ones we've deleted like we do in the content service. + var xmlItems = nodes.Select(node => new ContentXmlDto { NodeId = node.NodeId, Xml = UpdatedXmlStructure }).ToList(); + + using (var tr = DatabaseContext.Database.GetTransaction()) + { + //clear all the xml entries + DatabaseContext.Database.Execute(@"DELETE FROM cmsContentXml WHERE nodeId IN + (SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml + INNER JOIN cmsContent ON cmsContentXml.nodeId = cmsContent.nodeId)"); + + + DatabaseContext.Database.BulkInsertRecords(xmlItems, tr); + } + } + } + + + } + + private IEnumerable PrimeDbWithLotsOfContent() + { + var contentType1 = MockedContentTypes.CreateSimpleContentType(); + contentType1.AllowedAsRoot = true; + ServiceContext.ContentTypeService.Save(contentType1); + contentType1.AllowedContentTypes = new List + { + new ContentTypeSort + { + Alias = contentType1.Alias, + Id = new Lazy(() => contentType1.Id), + SortOrder = 0 + } + }; + var result = new List(); + ServiceContext.ContentTypeService.Save(contentType1); + IContent lastParent = MockedContent.CreateSimpleContent(contentType1); + ServiceContext.ContentService.SaveAndPublish(lastParent); + result.Add(lastParent); + //create 20 deep + for (var i = 0; i < 20; i++) + { + //for each level, create 20 + IContent content = null; + for (var j = 1; j <= 10; j++) + { + content = MockedContent.CreateSimpleContent(contentType1, "Name" + j, lastParent); + //only publish evens + if (j % 2 == 0) + { + ServiceContext.ContentService.SaveAndPublish(content); + } + else + { + ServiceContext.ContentService.Save(content); + } + result.Add(content); + } + + //assign the last one as the next parent + lastParent = content; + } + return result; + } + + private IEnumerable PrimeDbWithLotsOfContentXmlRecords(Guid customObjectType) + { + var nodes = new List(); + for (var i = 1; i < 10000; i++) + { + nodes.Add(new NodeDto + { + Level = 1, + ParentId = -1, + NodeObjectType = customObjectType, + Text = i.ToString(CultureInfo.InvariantCulture), + UserId = 0, + CreateDate = DateTime.Now, + Trashed = false, + SortOrder = 0, + Path = "" + }); + } + DatabaseContext.Database.BulkInsertRecords(nodes); + + //re-get the nodes with ids + var sql = new Sql(); + sql.Select("*").From().Where(x => x.NodeObjectType == customObjectType); + nodes = DatabaseContext.Database.Fetch(sql); + + //create the cmsContent data, each with a new content type id (so we can query on it later if needed) + var contentTypeId = 0; + var cmsContentItems = nodes.Select(node => new ContentDto { NodeId = node.NodeId, ContentTypeId = contentTypeId++ }).ToList(); + DatabaseContext.Database.BulkInsertRecords(cmsContentItems); + + //create the xml data + var xmlItems = nodes.Select(node => new ContentXmlDto { NodeId = node.NodeId, Xml = TestXmlStructure }).ToList(); + DatabaseContext.Database.BulkInsertRecords(xmlItems); + + return nodes; + } + + private const string TestXmlStructure = @" + 0 + Standard Site for Umbraco by Koiak + + + + Built by Creative Founds +

Web ApplicationsCreative Founds design and build first class software solutions that deliver big results. We provide ASP.NET web and mobile applications, Umbraco development service & technical consultancy.

+

www.creativefounds.co.uk

]]>
+ Umbraco Development +

UmbracoUmbraco the the leading ASP.NET open source CMS, under pinning over 150,000 websites. Our Certified Developers are experts in developing high performance and feature rich websites.

]]>
+ Contact Us +

Contact Us on TwitterWe'd love to hear how this package has helped you and how it can be improved. Get in touch on the project website or via twitter

]]>
+ +
Standard Website MVC, Company Address, Glasgow, Postcode
+ Copyright &copy; 2012 Your Company + http://www.umbraco.org + /media/1477/umbraco_logo.png + + + + + + + 2013-07-01T00:00:00 +
"; + + private const string UpdatedXmlStructure = @" + 0 + + + + Clients +

This is a standard content page.

+

Vestibulum malesuada aliquet ante, vitae ullamcorper felis faucibus vel. Vestibulum condimentum faucibus tellus porta ultrices. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

+

Cras at auctor orci. Praesent facilisis erat nec odio consequat at posuere ligula pretium. Nulla eget felis id nisl volutpat pellentesque. Ut id augue id ligula placerat rutrum a nec purus. Maecenas sed lectus ac mi pellentesque luctus quis sit amet turpis. Vestibulum adipiscing convallis vestibulum.

+

Duis condimentum lectus at orci placerat vitae imperdiet lorem cursus. Duis hendrerit porta lorem, non suscipit quam consectetur vitae. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean elit augue, tincidunt nec tincidunt id, elementum vel est.

]]>
+ +
"; + + } +} \ No newline at end of file diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index 7db1a236f6..163e0eba1c 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -57,9 +57,23 @@ namespace Umbraco.Tests.TestHelpers var path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", path); - DatabaseContext.Initialize(); + var dbFactory = new DefaultDatabaseFactory( + GetDbConnectionString(), + GetDbProviderName()); + ApplicationContext.Current = new ApplicationContext( + //assign the db context + new DatabaseContext(dbFactory), + //assign the service context + new ServiceContext(new PetaPocoUnitOfWorkProvider(dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy()), + //disable cache + false) + { + IsReady = true + }; - CreateDatabase(); + DatabaseContext.Initialize(dbFactory.ProviderName, dbFactory.ConnectionString); + + CreateSqlCeDatabase(); InitializeDatabase(); @@ -75,10 +89,23 @@ namespace Umbraco.Tests.TestHelpers get { return DatabaseBehavior.NewSchemaPerTest; } } + protected virtual string GetDbProviderName() + { + return "System.Data.SqlServerCe.4.0"; + } + + /// + /// Get the db conn string + /// + protected virtual string GetDbConnectionString() + { + return @"Datasource=|DataDirectory|UmbracoPetaPocoTests.sdf"; + } + /// /// Creates the SqlCe database if required /// - protected virtual void CreateDatabase() + protected virtual void CreateSqlCeDatabase() { if (DatabaseTestBehavior == DatabaseBehavior.NoDatabasePerFixture) return; @@ -87,7 +114,9 @@ namespace Umbraco.Tests.TestHelpers //Get the connectionstring settings from config var settings = ConfigurationManager.ConnectionStrings[Core.Configuration.GlobalSettings.UmbracoConnectionName]; - ConfigurationManager.AppSettings.Set(Core.Configuration.GlobalSettings.UmbracoConnectionName, @"datalayer=SQLCE4Umbraco.SqlCEHelper,SQLCE4Umbraco;data source=|DataDirectory|\UmbracoPetaPocoTests.sdf"); + ConfigurationManager.AppSettings.Set( + Core.Configuration.GlobalSettings.UmbracoConnectionName, + GetDbConnectionString()); string dbFilePath = string.Concat(path, "\\UmbracoPetaPocoTests.sdf"); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 86072083d6..a872fdfd75 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -201,6 +201,7 @@ + diff --git a/src/Umbraco.Tests/unit-test-log4net.config b/src/Umbraco.Tests/unit-test-log4net.config index ce3f527e3c..0922e4d932 100644 --- a/src/Umbraco.Tests/unit-test-log4net.config +++ b/src/Umbraco.Tests/unit-test-log4net.config @@ -5,6 +5,10 @@ + + + + @@ -13,6 +17,10 @@ + + + + diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 9a8e3f7012..92b5e584bf 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -2597,7 +2597,7 @@ xcopy "$(ProjectDir)"..\packages\SqlServerCE.4.0.0.0\x86\*.* "$(TargetDir)x86\" True True - 6130 + 6140 / http://localhost:6230 False diff --git a/src/Umbraco.Web.UI/umbraco/settings/EditNodeTypeNew.aspx b/src/Umbraco.Web.UI/umbraco/settings/EditNodeTypeNew.aspx index cdda810a57..4ae6523dc6 100644 --- a/src/Umbraco.Web.UI/umbraco/settings/EditNodeTypeNew.aspx +++ b/src/Umbraco.Web.UI/umbraco/settings/EditNodeTypeNew.aspx @@ -1,4 +1,4 @@ -<%@ Page Language="c#" CodeBehind="EditNodeTypeNew.aspx.cs" AutoEventWireup="True" +<%@ Page Language="c#" CodeBehind="EditNodeTypeNew.aspx.cs" AutoEventWireup="True" ValidateRequest="false" Async="true" AsyncTimeOut="300" Trace="false" Inherits="Umbraco.Web.UI.Umbraco.Settings.EditNodeTypeNew" MasterPageFile="../masterpages/umbracoPage.Master" %> <%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %> diff --git a/src/Umbraco.Web.UI/umbraco_client/FolderBrowser/Js/folderbrowser.js b/src/Umbraco.Web.UI/umbraco_client/FolderBrowser/Js/folderbrowser.js index 438a04344a..497c1843b0 100644 --- a/src/Umbraco.Web.UI/umbraco_client/FolderBrowser/Js/folderbrowser.js +++ b/src/Umbraco.Web.UI/umbraco_client/FolderBrowser/Js/folderbrowser.js @@ -374,17 +374,30 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls"); if (self._viewModel.filterTerm().length > 0) { $(this).sortable("cancel"); alert("Can't sort items which have been filtered"); - } else { - $.post(self._opts.umbracoPath + "/webservices/nodeSorter.asmx/UpdateSortOrder", { - ParentId: self._parentId, - SortOrder: self._viewModel.itemIds().join(","), - app: "media" - }, function (data, textStatus) { - if (textStatus == "error") { - alert("Oops. Could not update sort order"); + } + else { + + $.ajax({ + url: self._opts.umbracoPath + "/umbracoapi/media/postsort", + type: 'POST', + contentType: "application/json; charset=utf-8", + dataType: 'json', + data: JSON.stringify({ + parentId: self._parentId, + idSortOrder: self._viewModel.itemIds() + }), + processData: false, + success: function (data, textStatus) { + if (textStatus == "error") { + alert("Oops. Could not update sort order"); + self._getChildNodes(); + } + }, + error: function(data) { + alert("Oops. Could not update sort order. Err: " + data.statusText); self._getChildNodes(); } - }, "json"); + }); } } }); diff --git a/src/Umbraco.Web.UI/web.Template.Debug.config b/src/Umbraco.Web.UI/web.Template.Debug.config index de074b944e..02ab0ac83e 100644 --- a/src/Umbraco.Web.UI/web.Template.Debug.config +++ b/src/Umbraco.Web.UI/web.Template.Debug.config @@ -64,7 +64,16 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Umbraco.Web.UI/web.Template.config b/src/Umbraco.Web.UI/web.Template.config index db9007f728..bc0fd45487 100644 --- a/src/Umbraco.Web.UI/web.Template.config +++ b/src/Umbraco.Web.UI/web.Template.config @@ -261,6 +261,12 @@ + + + + + + diff --git a/src/Umbraco.Web/Install/UmbracoInstallAuthorizeAttribute.cs b/src/Umbraco.Web/Install/UmbracoInstallAuthorizeAttribute.cs index 1ea41f6e58..2c4b2cc732 100644 --- a/src/Umbraco.Web/Install/UmbracoInstallAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Install/UmbracoInstallAuthorizeAttribute.cs @@ -13,7 +13,7 @@ namespace Umbraco.Web.Install ///
internal class UmbracoInstallAuthorizeAttribute : AuthorizeAttribute { - private readonly ApplicationContext _applicationContext; + private readonly ApplicationContext _applicationContext; private readonly UmbracoContext _umbracoContext; private ApplicationContext GetApplicationContext() @@ -37,9 +37,9 @@ namespace Umbraco.Web.Install _applicationContext = _umbracoContext.Application; } - public UmbracoInstallAuthorizeAttribute() + public UmbracoInstallAuthorizeAttribute() { - } + } /// /// Ensures that the user must be logged in or that the application is not configured just yet. @@ -57,7 +57,7 @@ namespace Umbraco.Web.Install { return true; } - + var umbCtx = GetUmbracoContext(); //otherwise we need to ensure that a user is logged in var isLoggedIn = GetUmbracoContext().Security.ValidateCurrentUser(); if (isLoggedIn) diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentSortOrder.cs b/src/Umbraco.Web/Models/ContentEditing/ContentSortOrder.cs new file mode 100644 index 0000000000..d6cd7b3a3e --- /dev/null +++ b/src/Umbraco.Web/Models/ContentEditing/ContentSortOrder.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; + +namespace Umbraco.Web.Models.ContentEditing +{ + /// + /// A model representing a new sort order for a content/media item + /// + [DataContract(Name = "content", Namespace = "")] + public class ContentSortOrder + { + /// + /// The parent Id of the nodes being sorted + /// + /// + /// This is nullable because currently we don't require this for media sorting + /// + [DataMember(Name = "parentId")] + public int? ParentId { get; set; } + + /// + /// An array of integer Ids representing the sort order + /// + /// + /// Of course all of these Ids should be at the same level in the heirarchy!! + /// + [DataMember(Name = "idSortOrder")] + public int[] IdSortOrder { get; set; } + + } + +} diff --git a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs index fe55d69d29..e9344d34da 100644 --- a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs @@ -36,9 +36,9 @@ namespace Umbraco.Web.Mvc _applicationContext = _umbracoContext.Application; } - public UmbracoAuthorizeAttribute() - { - } + public UmbracoAuthorizeAttribute() + { + } /// /// Ensures that the user must be in the Administrator or the Install role @@ -58,6 +58,7 @@ namespace Umbraco.Web.Mvc if (!appContext.IsConfigured) return false; var isLoggedIn = umbContext.Security.ValidateCurrentUser(); + var isLoggedIn = umbCtx.Security.ValidateUserContextId(umbCtx.Security.UmbracoUserContextId); return isLoggedIn; } catch (Exception) diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 929e9eeadd..71466f443b 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -296,8 +296,7 @@ - - + diff --git a/src/Umbraco.Web/WebApi/MemberAuthorizeAttribute.cs b/src/Umbraco.Web/WebApi/MemberAuthorizeAttribute.cs index a0dcdd033c..88bb2107de 100644 --- a/src/Umbraco.Web/WebApi/MemberAuthorizeAttribute.cs +++ b/src/Umbraco.Web/WebApi/MemberAuthorizeAttribute.cs @@ -33,9 +33,9 @@ namespace Umbraco.Web.WebApi } public MemberAuthorizeAttribute() - { + { - } + } /// /// Flag for whether to allow all site visitors or just authenticated members diff --git a/src/Umbraco.Web/WebApi/UmbracoApiController.cs b/src/Umbraco.Web/WebApi/UmbracoApiController.cs index 152fd89cfc..0c35c5c406 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiController.cs @@ -98,5 +98,13 @@ namespace Umbraco.Web.WebApi /// Useful for debugging /// internal Guid InstanceId { get; private set; } + + /// + /// Returns the WebSecurity instance + /// + public WebSecurity Security + { + get { return UmbracoContext.Security; } + } } } \ No newline at end of file diff --git a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs index d03c52e158..3bcda7e17c 100644 --- a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs @@ -33,6 +33,8 @@ namespace Umbraco.Web.WebApi if (!_userisValidated) { Security.ValidateCurrentUser(true); + throw new InvalidOperationException("To get a current user, this method must occur in a web request"); + Security.ValidateCurrentUser(ctx.Result, true); _userisValidated = true; } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/SkinModule.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/SkinModule.cs index ed20f5796b..2405b37695 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/SkinModule.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/SkinModule.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; using umbraco.presentation.LiveEditing.Modules; using ClientDependency.Core; using System.Web.UI.WebControls; @@ -13,9 +10,6 @@ using ClientDependency.Core.Controls; using umbraco.presentation.umbraco.controls; using HtmlAgilityPack; using umbraco.cms.businesslogic.template; -using System.Text; -using System.IO; -using System.Collections; namespace umbraco.presentation.umbraco.LiveEditing.Modules.SkinModule { diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/DataTypes/editDatatype.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/DataTypes/editDatatype.aspx.cs index 5d7bb8e909..67792c4f11 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/DataTypes/editDatatype.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/DataTypes/editDatatype.aspx.cs @@ -62,6 +62,12 @@ namespace umbraco.cms.presentation.developer Value = item.Key.ToString() }; + //SJ Fixes U4-2488 Edit datatype: Media Picker appears incorrectly + //Apparently in some installs the media picker rendercontrol is installed twice with + //the exact same ID so we need to check for duplicates + if (ddlRenderControl.Items.Contains(li)) + continue; + if (_dataTypeDefinition.ControlId != default(Guid) && li.Value == _dataTypeDefinition.ControlId.ToString()) { li.Selected = true; diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/republish.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/republish.aspx.cs index 23ce0cd650..9142e38c1d 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/republish.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/republish.aspx.cs @@ -27,7 +27,7 @@ namespace umbraco.cms.presentation if (Request.GetItemAsString("xml") != "") { Server.ScriptTimeout = 100000; - umbraco.cms.businesslogic.web.Document.RePublishAll(); + Services.ContentService.RePublishAll(); } else if (Request.GetItemAsString("previews") != "") { diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs index a5b2102640..b18e34292f 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs @@ -160,13 +160,6 @@ namespace umbraco.presentation.webservices if (parentNode != null) content.SortNodes(ref parentNode); - // Load balancing - then refresh entire cache - // NOTE: SD: This seems a bit excessive to do simply for sorting! I'm going to leave this here for now but - // the sort order should be updated in distributed calls when an item is Published (and it most likely is) - // but I guess this was put here for a reason at some point. - if (UmbracoSettings.UseDistributedCalls) - library.RefreshContent(); - // fire actionhandler, check for content BusinessLogic.Actions.Action.RunActionHandlers(new Document(parentId), ActionSort.Instance); } diff --git a/src/umbraco.MacroEngines/RazorDynamicNode/RazorLibraryCore.cs b/src/umbraco.MacroEngines/RazorDynamicNode/RazorLibraryCore.cs index 5921ff220a..6ab1bad3d8 100644 --- a/src/umbraco.MacroEngines/RazorDynamicNode/RazorLibraryCore.cs +++ b/src/umbraco.MacroEngines/RazorDynamicNode/RazorLibraryCore.cs @@ -1,18 +1,11 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; using System.Web.Mvc; -using Umbraco.Core.Dynamics; -using Umbraco.Core.Models; using Umbraco.Web; -using Umbraco.Web.Models; using umbraco.interfaces; using System.Xml.Linq; using System.Xml.XPath; using System.Web; -using System.IO; -using HtmlAgilityPack; namespace umbraco.MacroEngines.Library { diff --git a/src/umbraco.cms/businesslogic/skinning/tasks/AddStyleSheetToTemplate.cs b/src/umbraco.cms/businesslogic/skinning/tasks/AddStyleSheetToTemplate.cs index 7e2fce58ff..44f67d4506 100644 --- a/src/umbraco.cms/businesslogic/skinning/tasks/AddStyleSheetToTemplate.cs +++ b/src/umbraco.cms/businesslogic/skinning/tasks/AddStyleSheetToTemplate.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using umbraco.interfaces.skinning; using HtmlAgilityPack; using umbraco.IO; diff --git a/src/umbraco.cms/businesslogic/skinning/tasks/ModifyTemplate.cs b/src/umbraco.cms/businesslogic/skinning/tasks/ModifyTemplate.cs index e098f00af2..7d3d7a7c63 100644 --- a/src/umbraco.cms/businesslogic/skinning/tasks/ModifyTemplate.cs +++ b/src/umbraco.cms/businesslogic/skinning/tasks/ModifyTemplate.cs @@ -1,14 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using umbraco.interfaces.skinning; -using System.Text.RegularExpressions; -using System.IO; -using System.Web; using umbraco.IO; -using umbraco.cms.businesslogic.packager.standardPackageActions; -using System.Xml; using HtmlAgilityPack; namespace umbraco.cms.businesslogic.skinning.tasks diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs index 724ca09b34..66e6db5080 100644 --- a/src/umbraco.cms/businesslogic/web/Document.cs +++ b/src/umbraco.cms/businesslogic/web/Document.cs @@ -428,48 +428,7 @@ namespace umbraco.cms.businesslogic.web [Obsolete("Obsolete, Use Umbraco.Core.Services.ContentService.RePublishAll()", false)] public static void RePublishAll() { - var xd = new XmlDocument(); - - //Remove all Documents (not media or members), only Documents are stored in the cmsDocument table - SqlHelper.ExecuteNonQuery(@"DELETE FROM cmsContentXml WHERE nodeId IN - (SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml - INNER JOIN cmsDocument ON cmsContentXml.nodeId = cmsDocument.nodeId)"); - - var dr = SqlHelper.ExecuteReader("select nodeId from cmsDocument where published = 1"); - - while (dr.Read()) - { - try - { - //create the document in optimized mode! - // (not sure why we wouldn't always do that ?!) - - new Document(true, dr.GetInt("nodeId")) - .XmlGenerate(xd); - - //The benchmark results that I found based contructing the Document object with 'true' for optimized - //mode, vs using the normal ctor. Clearly optimized mode is better! - /* - * The average page rendering time (after 10 iterations) for submitting /umbraco/dialogs/republish?xml=true when using - * optimized mode is - * - * 0.060400555555556 - * - * The average page rendering time (after 10 iterations) for submitting /umbraco/dialogs/republish?xml=true when not - * using optimized mode is - * - * 0.107037777777778 - * - * This means that by simply changing this to use optimized mode, it is a 45% improvement! - * - */ - } - catch (Exception ee) - { - LogHelper.Error("Error generating xml", ee); - } - } - dr.Close(); + ApplicationContext.Current.Services.ContentService.RePublishAll(); } public static void RegeneratePreviews()