From dc336728b5483cabef10b161f742be6b0c273e2d Mon Sep 17 00:00:00 2001 From: Jeremy Pyne Date: Mon, 28 Oct 2013 14:32:18 -0400 Subject: [PATCH 01/20] Fix for missing Id's on FileService.GetStylesheets() call. This is needed as sytlesheets can only be loaded in the editor via their Id so listing stylesheets needs to list there Id as well for custom plugins to render the build in editor. --- .../Repositories/StylesheetRepository.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs b/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs index 9acfff4e8b..f5c780311e 100644 --- a/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs @@ -53,7 +53,8 @@ namespace Umbraco.Core.Persistence.Repositories Content = content, Key = path.EncodeAsGuid(), CreateDate = created, - UpdateDate = updated + UpdateDate = updated, + Id = GetStylesheetId(path) }; //on initial construction we don't want to have dirty properties tracked @@ -61,6 +62,17 @@ namespace Umbraco.Core.Persistence.Repositories stylesheet.ResetDirtyProperties(false); return stylesheet; + + + } + + // Fix for missing Id's on FileService.GetStylesheets() call. This is needed as sytlesheets can only bo loaded in the editor via + // their Id so listing stylesheets needs to list there Id as well for custom plugins to render the build in editor. + // http://issues.umbraco.org/issue/U4-3258 + private static int GetStylesheetId(string path) + { + var ss = ApplicationContext.Current.Services.EntityService.GetRootEntities(UmbracoObjectTypes.Stylesheet).SingleOrDefault(s => s.Name == path.TrimEnd(".css").Replace("\\", "/")); + return ss == null ? 0 : ss.Id; } public override IEnumerable GetAll(params string[] ids) From 7cd6882f28296abe0d54f8ca0b9cfd5963cd79da Mon Sep 17 00:00:00 2001 From: Jeremy Pyne Date: Tue, 29 Oct 2013 09:24:05 -0400 Subject: [PATCH 02/20] Removed dependence in Stylesheet repository on Entity Service. --- .../Repositories/StylesheetRepository.cs | 25 +++++++++++++------ .../Persistence/RepositoryFactory.cs | 4 +-- src/Umbraco.Core/Services/FileService.cs | 8 +++--- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs b/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs index f5c780311e..bce0e9bcc1 100644 --- a/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs @@ -14,14 +14,16 @@ namespace Umbraco.Core.Persistence.Repositories /// internal class StylesheetRepository : FileRepository, IStylesheetRepository { - internal StylesheetRepository(IUnitOfWork work, IFileSystem fileSystem) + private readonly IDatabaseUnitOfWork _dbwork; + + internal StylesheetRepository(IUnitOfWork work, IDatabaseUnitOfWork db, IFileSystem fileSystem) : base(work, fileSystem) { - + _dbwork = db; } - public StylesheetRepository(IUnitOfWork work) - : this(work, new PhysicalFileSystem(SystemDirectories.Css)) + public StylesheetRepository(IUnitOfWork work, IDatabaseUnitOfWork db) + : this(work, db, new PhysicalFileSystem(SystemDirectories.Css)) { } @@ -63,16 +65,23 @@ namespace Umbraco.Core.Persistence.Repositories return stylesheet; - } // Fix for missing Id's on FileService.GetStylesheets() call. This is needed as sytlesheets can only bo loaded in the editor via // their Id so listing stylesheets needs to list there Id as well for custom plugins to render the build in editor. // http://issues.umbraco.org/issue/U4-3258 - private static int GetStylesheetId(string path) + private int GetStylesheetId(string path) { - var ss = ApplicationContext.Current.Services.EntityService.GetRootEntities(UmbracoObjectTypes.Stylesheet).SingleOrDefault(s => s.Name == path.TrimEnd(".css").Replace("\\", "/")); - return ss == null ? 0 : ss.Id; + var sql = new Sql() + .Select("nodeId") + .From("umbracoNode") + .Where("umbracoNode.nodeObjectType = @NodeObjectType && umbracoNode.text = @Alias", + new { NodeObjectType = UmbracoObjectTypes.Stylesheet, Alias = path.TrimEnd(".css").Replace("\\", "/") }); + var nodeDto = _dbwork.Database.FirstOrDefault(sql); + return nodeDto == null ? 0 : nodeDto.NodeId; + + //var ss = ApplicationContext.Current.Services.EntityService.GetRootEntities(UmbracoObjectTypes.Stylesheet).SingleOrDefault(s => s.Name == path.TrimEnd(".css").Replace("\\", "/")); + //return ss == null ? 0 : ss.Id; } public override IEnumerable GetAll(params string[] ids) diff --git a/src/Umbraco.Core/Persistence/RepositoryFactory.cs b/src/Umbraco.Core/Persistence/RepositoryFactory.cs index ab0a5e8e65..db6bc32009 100644 --- a/src/Umbraco.Core/Persistence/RepositoryFactory.cs +++ b/src/Umbraco.Core/Persistence/RepositoryFactory.cs @@ -97,9 +97,9 @@ namespace Umbraco.Core.Persistence return new ScriptRepository(uow); } - public virtual IStylesheetRepository CreateStylesheetRepository(IUnitOfWork uow) + public virtual IStylesheetRepository CreateStylesheetRepository(IUnitOfWork uow, IDatabaseUnitOfWork db) { - return new StylesheetRepository(uow); + return new StylesheetRepository(uow, db); } public virtual ITemplateRepository CreateTemplateRepository(IDatabaseUnitOfWork uow) diff --git a/src/Umbraco.Core/Services/FileService.cs b/src/Umbraco.Core/Services/FileService.cs index 53ac74b3a2..c912793e05 100644 --- a/src/Umbraco.Core/Services/FileService.cs +++ b/src/Umbraco.Core/Services/FileService.cs @@ -39,7 +39,7 @@ namespace Umbraco.Core.Services /// An enumerable list of objects public IEnumerable GetStylesheets(params string[] names) { - using (var repository = _repositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork())) + using (var repository = _repositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork(), _dataUowProvider.GetUnitOfWork())) { return repository.GetAll(names); } @@ -52,7 +52,7 @@ namespace Umbraco.Core.Services /// A object public Stylesheet GetStylesheetByName(string name) { - using (var repository = _repositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork())) + using (var repository = _repositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork(), _dataUowProvider.GetUnitOfWork())) { return repository.Get(name); } @@ -69,7 +69,7 @@ namespace Umbraco.Core.Services return; var uow = _fileUowProvider.GetUnitOfWork(); - using (var repository = _repositoryFactory.CreateStylesheetRepository(uow)) + using (var repository = _repositoryFactory.CreateStylesheetRepository(uow, _dataUowProvider.GetUnitOfWork())) { repository.AddOrUpdate(stylesheet); uow.Commit(); @@ -88,7 +88,7 @@ namespace Umbraco.Core.Services public void DeleteStylesheet(string name, int userId = 0) { var uow = _fileUowProvider.GetUnitOfWork(); - using (var repository = _repositoryFactory.CreateStylesheetRepository(uow)) + using (var repository = _repositoryFactory.CreateStylesheetRepository(uow, _dataUowProvider.GetUnitOfWork())) { var stylesheet = repository.Get(name); From 6451f6ad68f4c4b199e3b93bd7610e4cb469f9cf Mon Sep 17 00:00:00 2001 From: Jeremy Pyne Date: Tue, 29 Oct 2013 10:00:25 -0400 Subject: [PATCH 03/20] Fix sql errors in prev change. --- .../Persistence/Repositories/StylesheetRepository.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs b/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs index bce0e9bcc1..56148b14a8 100644 --- a/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs @@ -73,15 +73,12 @@ namespace Umbraco.Core.Persistence.Repositories private int GetStylesheetId(string path) { var sql = new Sql() - .Select("nodeId") + .Select("id") .From("umbracoNode") - .Where("umbracoNode.nodeObjectType = @NodeObjectType && umbracoNode.text = @Alias", - new { NodeObjectType = UmbracoObjectTypes.Stylesheet, Alias = path.TrimEnd(".css").Replace("\\", "/") }); + .Where("umbracoNode.nodeObjectType = @NodeObjectType AND umbracoNode.text = @Alias", + new { NodeObjectType = UmbracoObjectTypes.Stylesheet.GetGuid(), Alias = path.TrimEnd(".css").Replace("\\", "/") }); var nodeDto = _dbwork.Database.FirstOrDefault(sql); return nodeDto == null ? 0 : nodeDto.NodeId; - - //var ss = ApplicationContext.Current.Services.EntityService.GetRootEntities(UmbracoObjectTypes.Stylesheet).SingleOrDefault(s => s.Name == path.TrimEnd(".css").Replace("\\", "/")); - //return ss == null ? 0 : ss.Id; } public override IEnumerable GetAll(params string[] ids) From 6b006e6fd7479bffb857bfbc515b35d02307d8ad Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Thu, 7 Nov 2013 11:00:19 +0100 Subject: [PATCH 04/20] Refactoring GetUserNotifications method in the Notification class --- .../businesslogic/workflow/Notification.cs | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/umbraco.cms/businesslogic/workflow/Notification.cs b/src/umbraco.cms/businesslogic/workflow/Notification.cs index 6302438bf6..c47a7bb6bd 100644 --- a/src/umbraco.cms/businesslogic/workflow/Notification.cs +++ b/src/umbraco.cms/businesslogic/workflow/Notification.cs @@ -4,10 +4,12 @@ using System.Net.Mail; using System.Runtime.CompilerServices; using System.Text; using System.Web; +using Umbraco.Core; using Umbraco.Core.Logging; using umbraco.BusinessLogic; using umbraco.cms.businesslogic.property; using umbraco.cms.businesslogic.web; +using Umbraco.Core.Models.Rdbms; using umbraco.DataLayer; using umbraco.interfaces; using Umbraco.Core.IO; @@ -210,22 +212,19 @@ namespace umbraco.cms.businesslogic.workflow public static IEnumerable GetUserNotifications(User user) { var items = new List(); - using ( - IRecordsReader dr = - SqlHelper.ExecuteReader( - "select * from umbracoUser2NodeNotify where userId = @userId order by nodeId", - SqlHelper.CreateParameter("@userId", user.Id))) + var dtos = ApplicationContext.Current.DatabaseContext.Database.Fetch( + "WHERE userId = @UserId ORDER BY nodeId", new { UserId = user.Id }); + + foreach (var dto in dtos) { - while (dr.Read()) - { - items.Add(new Notification - { - NodeId = dr.GetInt("nodeId"), - ActionId = Convert.ToChar(dr.GetString("action")), - UserId = dr.GetInt("userId") - }); - } + items.Add(new Notification + { + NodeId = dto.NodeId, + ActionId = Convert.ToChar(dto.Action), + UserId = dto.UserId + }); } + return items; } From 4ea04f5ffe5c5f33a50cb3797f88717f2309772b Mon Sep 17 00:00:00 2001 From: Tim Payne Date: Thu, 7 Nov 2013 10:08:11 +0000 Subject: [PATCH 05/20] Fixes issue U4-2708 --- src/Umbraco.Web.UI/config/splashes/noNodes.aspx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI/config/splashes/noNodes.aspx b/src/Umbraco.Web.UI/config/splashes/noNodes.aspx index 6a71a740cb..6afb331bc7 100644 --- a/src/Umbraco.Web.UI/config/splashes/noNodes.aspx +++ b/src/Umbraco.Web.UI/config/splashes/noNodes.aspx @@ -27,7 +27,7 @@ From 64a73ef528e4dd2024b02d3e331543a881b5507d Mon Sep 17 00:00:00 2001 From: Robert Stocks Date: Thu, 7 Nov 2013 10:20:55 +0000 Subject: [PATCH 06/20] Refactoring umbraco.cms.businesslogic.language.Item class --- .../businesslogic/language/Item.cs | 70 ++++++++++--------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/src/umbraco.cms/businesslogic/language/Item.cs b/src/umbraco.cms/businesslogic/language/Item.cs index 30ce7089f7..9f9e6658f2 100644 --- a/src/umbraco.cms/businesslogic/language/Item.cs +++ b/src/umbraco.cms/businesslogic/language/Item.cs @@ -3,9 +3,13 @@ using System.Collections; using System.Collections.Concurrent; using System.Data; using System.Linq; + +using Umbraco.Core; + using umbraco.DataLayer; using umbraco.BusinessLogic; using System.Collections.Generic; +using Umbraco.Core.Models.Rdbms; namespace umbraco.cms.businesslogic.language { @@ -27,6 +31,7 @@ namespace umbraco.cms.businesslogic.language /// Gets the SQL helper. /// /// The SQL helper. + [Obsolete("Obsolete, For querying the database use the new UmbracoDatabase object ApplicationContext.Current.DatabaseContext.Database", false)] protected static ISqlHelper SqlHelper { get { return Application.SqlHelper; } @@ -44,27 +49,26 @@ namespace umbraco.cms.businesslogic.language //double check if (!_isInitialize) { - // load all data - using (IRecordsReader dr = SqlHelper.ExecuteReader("Select LanguageId, UniqueId,[value] from cmsLanguageText order by UniqueId")) - { - while (dr.Read()) - { - var languageId = dr.GetInt("LanguageId"); - var uniqueId = dr.GetGuid("UniqueId"); - var text = dr.GetString("value"); - Items.AddOrUpdate(uniqueId, guid => - { - var languagevalues = new Dictionary { { languageId, text } }; - return languagevalues; - }, (guid, dictionary) => - { - // add/update the text for the id - dictionary[languageId] = text; - return dictionary; - }); - } - } + var dtos = ApplicationContext.Current.DatabaseContext.Database.Fetch("ORDER BY UniqueId"); + foreach (var dto in dtos) + { + var languageId = dto.LanguageId; + var uniqueId = dto.UniqueId; + var text = dto.Value; + + Items.AddOrUpdate(uniqueId, guid => + { + var languagevalues = new Dictionary { { languageId, text } }; + return languagevalues; + }, (guid, dictionary) => + { + // add/update the text for the id + dictionary[languageId] = text; + return dictionary; + }); + } + _isInitialize = true; } } @@ -130,10 +134,9 @@ namespace umbraco.cms.businesslogic.language { if (!hasText(key, languageId)) throw new ArgumentException("Key does not exist"); - SqlHelper.ExecuteNonQuery("Update cmsLanguageText set [value] = @value where LanguageId = @languageId And UniqueId = @key", - SqlHelper.CreateParameter("@value", value), - SqlHelper.CreateParameter("@languageId", languageId), - SqlHelper.CreateParameter("@key", key)); + ApplicationContext.Current.DatabaseContext.Database.Update( + "Update cmsLanguageText set [value] = @value where LanguageId = @languageId And UniqueId = @key", + new { value = value, languageId = languageId, key = key }); } /// @@ -146,11 +149,13 @@ namespace umbraco.cms.businesslogic.language public static void addText(int languageId, Guid key, string value) { if (hasText(key, languageId)) throw new ArgumentException("Key being add'ed already exists"); - - SqlHelper.ExecuteNonQuery("Insert Into cmsLanguageText (languageId,UniqueId,[value]) values (@languageId, @key, @value)", - SqlHelper.CreateParameter("@languageId", languageId), - SqlHelper.CreateParameter("@key", key), - SqlHelper.CreateParameter("@value", value)); + + ApplicationContext.Current.DatabaseContext.Database.Insert(new LanguageTextDto + { + LanguageId = languageId, + Value = value, + UniqueId = key + }); } /// @@ -160,8 +165,7 @@ namespace umbraco.cms.businesslogic.language public static void removeText(Guid key) { // remove from database - SqlHelper.ExecuteNonQuery("Delete from cmsLanguageText where UniqueId = @key", - SqlHelper.CreateParameter("@key", key)); + ApplicationContext.Current.DatabaseContext.Database.Delete(key); } /// @@ -172,9 +176,7 @@ namespace umbraco.cms.businesslogic.language public static void RemoveByLanguage(int languageId) { // remove from database - SqlHelper.ExecuteNonQuery("Delete from cmsLanguageText where languageId = @languageId", - SqlHelper.CreateParameter("@languageId", languageId)); - + ApplicationContext.Current.DatabaseContext.Database.Delete("where languageId = @languageId", new { languageId = languageId }); } } } \ No newline at end of file From 9347a2edbbba0a7064e34441716438fa644f6e5a Mon Sep 17 00:00:00 2001 From: Robert Stocks Date: Thu, 7 Nov 2013 10:40:23 +0000 Subject: [PATCH 07/20] Refactoring umbraco.cms.businesslogic.language.Item class - Fix Update and Delete calls --- src/umbraco.cms/businesslogic/language/Item.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/umbraco.cms/businesslogic/language/Item.cs b/src/umbraco.cms/businesslogic/language/Item.cs index 9f9e6658f2..6d59b45ffa 100644 --- a/src/umbraco.cms/businesslogic/language/Item.cs +++ b/src/umbraco.cms/businesslogic/language/Item.cs @@ -134,8 +134,8 @@ namespace umbraco.cms.businesslogic.language { if (!hasText(key, languageId)) throw new ArgumentException("Key does not exist"); - ApplicationContext.Current.DatabaseContext.Database.Update( - "Update cmsLanguageText set [value] = @value where LanguageId = @languageId And UniqueId = @key", + ApplicationContext.Current.DatabaseContext.Database.Update( + "set [value] = @value where LanguageId = @languageId And UniqueId = @key", new { value = value, languageId = languageId, key = key }); } @@ -165,7 +165,7 @@ namespace umbraco.cms.businesslogic.language public static void removeText(Guid key) { // remove from database - ApplicationContext.Current.DatabaseContext.Database.Delete(key); + ApplicationContext.Current.DatabaseContext.Database.Delete("where UniqueId = @UniqueId", new { UniqueId = key }); } /// From f91ff5dc31760f731c8f3d065302322b2f12650b Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Thu, 7 Nov 2013 11:48:25 +0100 Subject: [PATCH 08/20] Special commit for a special Lars-Erik --- src/umbraco.cms/businesslogic/CMSNode.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/umbraco.cms/businesslogic/CMSNode.cs b/src/umbraco.cms/businesslogic/CMSNode.cs index 278ec9467f..69fe7a1192 100644 --- a/src/umbraco.cms/businesslogic/CMSNode.cs +++ b/src/umbraco.cms/businesslogic/CMSNode.cs @@ -6,6 +6,7 @@ using System.Xml; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.EntityBase; +using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Caching; using umbraco.cms.businesslogic.web; using umbraco.DataLayer; @@ -342,10 +343,16 @@ namespace umbraco.cms.businesslogic /// Gets the SQL helper. /// /// The SQL helper. + [Obsolete("Obsolete, For querying the database use the new UmbracoDatabase object ApplicationContext.Current.DatabaseContext.Database", false)] protected static ISqlHelper SqlHelper { get { return Application.SqlHelper; } } + + internal static UmbracoDatabase Database + { + get { return ApplicationContext.Current.DatabaseContext.Database; } + } #endregion #region Constructors From 1e319d667b3b17b288d2ea8807285f984f0a78cf Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Thu, 7 Nov 2013 11:59:59 +0100 Subject: [PATCH 09/20] Updating the remaining methods in the Notification class so it no longer uses the legacy SqlHelper. --- .../businesslogic/workflow/Notification.cs | 64 +++++++++---------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/src/umbraco.cms/businesslogic/workflow/Notification.cs b/src/umbraco.cms/businesslogic/workflow/Notification.cs index c47a7bb6bd..68bdd7bc25 100644 --- a/src/umbraco.cms/businesslogic/workflow/Notification.cs +++ b/src/umbraco.cms/businesslogic/workflow/Notification.cs @@ -38,6 +38,7 @@ namespace umbraco.cms.businesslogic.workflow /// Gets the SQL helper. /// /// The SQL helper. + [Obsolete("Obsolete, For querying the database use the new UmbracoDatabase object ApplicationContext.Current.DatabaseContext.Database", false)] protected static ISqlHelper SqlHelper { get { return Application.SqlHelper; } @@ -236,21 +237,17 @@ namespace umbraco.cms.businesslogic.workflow public static IEnumerable GetNodeNotifications(CMSNode node) { var items = new List(); - using ( - IRecordsReader dr = - SqlHelper.ExecuteReader( - "select * from umbracoUser2NodeNotify where nodeId = @nodeId order by nodeId", - SqlHelper.CreateParameter("@nodeId", node.Id))) + var dtos = ApplicationContext.Current.DatabaseContext.Database.Fetch( + "WHERE userId = @UserId ORDER BY nodeId", new { nodeId = node.Id }); + + foreach (var dto in dtos) { - while (dr.Read()) + items.Add(new Notification { - items.Add(new Notification - { - NodeId = dr.GetInt("nodeId"), - ActionId = Convert.ToChar(dr.GetString("action")), - UserId = dr.GetInt("userId") - }); - } + NodeId = dto.NodeId, + ActionId = Convert.ToChar(dto.Action), + UserId = dto.UserId + }); } return items; } @@ -258,12 +255,12 @@ namespace umbraco.cms.businesslogic.workflow /// /// Deletes notifications by node /// - /// + /// public static void DeleteNotifications(CMSNode node) { // delete all settings on the node for this node id - SqlHelper.ExecuteNonQuery("delete from umbracoUser2NodeNotify where nodeId = @nodeId", - SqlHelper.CreateParameter("@nodeId", node.Id)); + ApplicationContext.Current.DatabaseContext.Database.Delete("WHERE nodeId = @nodeId", + new {nodeId = node.Id}); } /// @@ -273,8 +270,8 @@ namespace umbraco.cms.businesslogic.workflow public static void DeleteNotifications(User user) { // delete all settings on the node for this node id - SqlHelper.ExecuteNonQuery("delete from umbracoUser2NodeNotify where userId = @userId", - SqlHelper.CreateParameter("@userId", user.Id)); + ApplicationContext.Current.DatabaseContext.Database.Delete("WHERE userId = @userId", + new { userId = user.Id }); } /// @@ -285,9 +282,8 @@ namespace umbraco.cms.businesslogic.workflow public static void DeleteNotifications(User user, CMSNode node) { // delete all settings on the node for this user - SqlHelper.ExecuteNonQuery("delete from umbracoUser2NodeNotify where userId = @userId and nodeId = @nodeId", - SqlHelper.CreateParameter("@userId", user.Id), - SqlHelper.CreateParameter("@nodeId", node.Id)); + ApplicationContext.Current.DatabaseContext.Database.Delete( + "WHERE userId = @userId AND nodeId = @nodeId", new {userId = user.Id, nodeId = node.Id}); } /// @@ -299,21 +295,19 @@ namespace umbraco.cms.businesslogic.workflow [MethodImpl(MethodImplOptions.Synchronized)] public static void MakeNew(User User, CMSNode Node, char ActionLetter) { - var parameters = new[] - { - SqlHelper.CreateParameter("@userId", User.Id), - SqlHelper.CreateParameter("@nodeId", Node.Id), - SqlHelper.CreateParameter("@action", ActionLetter.ToString()) - }; + bool exists = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar( + "SELECT COUNT(userId) FROM umbracoUser2nodeNotify WHERE userId = @userId AND nodeId = @nodeId AND action = @action", + new { userId = User.Id, nodeId = Node.Id, action = ActionLetter.ToString()}) > 0; - // Method is synchronized so exists remains consistent (avoiding race condition) - bool exists = SqlHelper.ExecuteScalar( - "SELECT COUNT(userId) FROM umbracoUser2nodeNotify WHERE userId = @userId AND nodeId = @nodeId AND action = @action", - parameters) > 0; - if (!exists) - SqlHelper.ExecuteNonQuery( - "INSERT INTO umbracoUser2nodeNotify (userId, nodeId, action) VALUES (@userId, @nodeId, @action)", - parameters); + if (exists == false) + { + ApplicationContext.Current.DatabaseContext.Database.Insert(new User2NodeNotifyDto + { + Action = ActionLetter.ToString(), + NodeId = Node.Id, + UserId = User.Id + }); + } } /// From a567cf2a873ee7718a689ee3375078b2defc5ad3 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Thu, 7 Nov 2013 12:00:45 +0100 Subject: [PATCH 10/20] Minor update to the DefaultData so the used PetaPoco db object is consistent --- src/umbraco.cms/businesslogic/datatype/DefaultData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs index 471fcc9479..16be25827c 100644 --- a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs +++ b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs @@ -32,7 +32,7 @@ namespace umbraco.cms.businesslogic.datatype //TODO Refactor this class to use the Database object instead of the SqlHelper //NOTE DatabaseContext.Current.Database should eventually be replaced with that from the Repository-Resolver refactor branch. - internal static Database Database + internal static UmbracoDatabase Database { get { return ApplicationContext.Current.DatabaseContext.Database; } } From 7c97fddec5f4e8198122145190a612f48a26cc7e Mon Sep 17 00:00:00 2001 From: mkariti Date: Thu, 7 Nov 2013 13:08:56 +0200 Subject: [PATCH 11/20] fix U4-1477 --- .../umbraco.presentation/umbraco/create/member.ascx.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/member.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/member.ascx.cs index a8b1661266..72ff6239fc 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/member.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/member.ascx.cs @@ -41,7 +41,7 @@ namespace umbraco.cms.presentation.create.controls string[] pwRules = { Membership.MinRequiredPasswordLength.ToString(), Membership.MinRequiredNonAlphanumericCharacters.ToString() }; PasswordRules.Text = PasswordRules.Text = ui.Text( - "errorHandling", "errorInPasswordFormat", pwRules, BasePages.UmbracoEnsuredPage.CurrentUser); + "errorHandling", "", pwRules, BasePages.UmbracoEnsuredPage.CurrentUser); if (!IsPostBack) { From 9269a988069a020d2dd90aa7bf148d1c9227f37e Mon Sep 17 00:00:00 2001 From: Sandro Ciervo Date: Thu, 7 Nov 2013 12:15:03 +0100 Subject: [PATCH 12/20] Refactored Umbraco.Web.UI.Controls.InsertMacroSplitButton - CreateChildControls() - DoesMacroHaveParameters (Int32) --- .../UI/Controls/InsertMacroSplitButton.cs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Web/UI/Controls/InsertMacroSplitButton.cs b/src/Umbraco.Web/UI/Controls/InsertMacroSplitButton.cs index eaadd345e7..50968413ae 100644 --- a/src/Umbraco.Web/UI/Controls/InsertMacroSplitButton.cs +++ b/src/Umbraco.Web/UI/Controls/InsertMacroSplitButton.cs @@ -71,21 +71,19 @@ namespace Umbraco.Web.UI.Controls var divMacroItemContainer = new TagBuilder("div"); divMacroItemContainer.Attributes.Add("style", "width: 285px;display:none;"); divMacroItemContainer.Attributes.Add("class", "sbMenu"); - using (var macroReader = SqlHelper.ExecuteReader("select id, macroAlias, macroName from cmsMacro order by macroName")) + var macros = ApplicationContext.DatabaseContext.Database.Query("select id, macroAlias, macroName from cmsMacro order by macroName"); + foreach (var macro in macros) { - while (macroReader.Read()) - { - var divMacro = new TagBuilder("div"); - divMacro.AddCssClass("macro-item"); - divMacro.Attributes.Add("rel", macroReader.GetString("macroAlias")); - divMacro.Attributes.Add("data-has-params", DoesMacroHaveParameters(macroReader.GetInt("id")).ToString().ToLower()); - divMacro.SetInnerText(macroReader.GetString("macroName")); - divMacroItemContainer.InnerHtml += divMacro.ToString(); - } + var divMacro = new TagBuilder("div"); + divMacro.AddCssClass("macro-item"); + divMacro.Attributes.Add("rel", macro.Alias); + divMacro.Attributes.Add("data-has-params", DoesMacroHaveParameters(macro.Id).ToString().ToLower()); + divMacro.SetInnerText(macro.Name); + divMacroItemContainer.InnerHtml += divMacro.ToString(); } /*create the button itself, similar to this: - +