diff --git a/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs b/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs index f249ca4577..7ae81aaa16 100644 --- a/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs +++ b/src/Umbraco.Core/Persistence/PetaPocoExtensions.cs @@ -304,22 +304,40 @@ namespace Umbraco.Core.Persistence return SqlSyntaxContext.SqlSyntaxProvider.DoesTableExist(db, tableName); } + /// + /// Creates the Umbraco db schema in the Database of the current Database. + /// Safe method that is only able to create the schema in non-configured + /// umbraco instances. + /// + /// Current PetaPoco object public static void CreateDatabaseSchema(this Database db) { CreateDatabaseSchema(db, true); } + /// + /// Creates the Umbraco db schema in the Database of the current Database + /// with the option to guard the db from having the schema created + /// multiple times. + /// + /// + /// + public static void CreateDatabaseSchema(this Database db, bool guardConfiguration) + { + if (guardConfiguration && ApplicationContext.Current.IsConfigured) + throw new Exception("Umbraco is already configured!"); + + CreateDatabaseSchemaDo(db); + } + internal static void UninstallDatabaseSchema(this Database db) { var creation = new DatabaseSchemaCreation(db); creation.UninstallDatabaseSchema(); } - internal static void CreateDatabaseSchema(this Database db, bool guardConfiguration) + internal static void CreateDatabaseSchemaDo(this Database db) { - if (guardConfiguration && ApplicationContext.Current.IsConfigured) - throw new Exception("Umbraco is already configured!"); - NewTable += PetaPocoExtensions_NewTable; LogHelper.Info("Initializing database schema creation"); diff --git a/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs b/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs index 9acfff4e8b..893fce373c 100644 --- a/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using Umbraco.Core.IO; using Umbraco.Core.Models; +using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence.UnitOfWork; namespace Umbraco.Core.Persistence.Repositories @@ -14,14 +15,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)) { } @@ -29,7 +32,7 @@ namespace Umbraco.Core.Persistence.Repositories public override Stylesheet Get(string id) { - if (!FileSystem.FileExists(id)) + if (FileSystem.FileExists(id) == false) { throw new Exception(string.Format("The file {0} was not found", id)); } @@ -53,7 +56,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 +65,22 @@ 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 int GetStylesheetId(string path) + { + var sql = new Sql() + .Select("*") + .From() + .Where("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; } public override IEnumerable GetAll(params string[] ids) diff --git a/src/Umbraco.Core/Persistence/RepositoryFactory.cs b/src/Umbraco.Core/Persistence/RepositoryFactory.cs index f502e28d32..7e0b506424 100644 --- a/src/Umbraco.Core/Persistence/RepositoryFactory.cs +++ b/src/Umbraco.Core/Persistence/RepositoryFactory.cs @@ -116,9 +116,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); diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs index 0b37761329..d91bc0e309 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -4,20 +4,22 @@ using System.Text; using NUnit.Framework; using Umbraco.Core.IO; using Umbraco.Core.Models; -using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.UnitOfWork; +using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Persistence.Repositories { [TestFixture] - public class StylesheetRepositoryTest + public class StylesheetRepositoryTest : BaseDatabaseFactoryTest { private IFileSystem _fileSystem; [SetUp] - public void Initialize() + public override void Initialize() { + base.Initialize(); + _fileSystem = new PhysicalFileSystem(SystemDirectories.Css); var stream = CreateStream("body {background:#EE7600; color:#FFF;}"); _fileSystem.AddFile("styles.css", stream); @@ -29,9 +31,10 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); + var dbUnitOfWork = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); // Act - var repository = new StylesheetRepository(unitOfWork, _fileSystem); + var repository = new StylesheetRepository(unitOfWork, dbUnitOfWork, _fileSystem); // Assert @@ -44,7 +47,9 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); - var repository = new StylesheetRepository(unitOfWork, _fileSystem); + var dbUnitOfWork = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); + + var repository = new StylesheetRepository(unitOfWork, dbUnitOfWork, _fileSystem); // Act var stylesheet = new Stylesheet("test-add.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" }; @@ -61,12 +66,14 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); - var repository = new StylesheetRepository(unitOfWork, _fileSystem); + var dbUnitOfWork = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); + var repository = new StylesheetRepository(unitOfWork, dbUnitOfWork, _fileSystem); // Act var stylesheet = new Stylesheet("test-update.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" }; repository.AddOrUpdate(stylesheet); unitOfWork.Commit(); + dbUnitOfWork.Commit(); var stylesheetUpdate = repository.Get("test-update.css"); stylesheetUpdate.Content = "body { color:#000; }"; @@ -87,7 +94,8 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); - var repository = new StylesheetRepository(unitOfWork, _fileSystem); + var dbUnitOfWork = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); + var repository = new StylesheetRepository(unitOfWork, dbUnitOfWork, _fileSystem); // Act var stylesheet = new Stylesheet("test-delete.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" }; @@ -107,7 +115,8 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); - var repository = new StylesheetRepository(unitOfWork, _fileSystem); + var dbUnitOfWork = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); + var repository = new StylesheetRepository(unitOfWork, dbUnitOfWork, _fileSystem); // Act var stylesheet = repository.Get("styles.css"); @@ -125,11 +134,13 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); - var repository = new StylesheetRepository(unitOfWork, _fileSystem); + var dbUnitOfWork = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); + var repository = new StylesheetRepository(unitOfWork, dbUnitOfWork, _fileSystem); var stylesheet = new Stylesheet("styles-v2.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" }; repository.AddOrUpdate(stylesheet); unitOfWork.Commit(); + dbUnitOfWork.Commit(); // Act var stylesheets = repository.GetAll(); @@ -147,11 +158,13 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); - var repository = new StylesheetRepository(unitOfWork, _fileSystem); + var dbUnitOfWork = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); + var repository = new StylesheetRepository(unitOfWork, dbUnitOfWork, _fileSystem); var stylesheet = new Stylesheet("styles-v2.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" }; repository.AddOrUpdate(stylesheet); unitOfWork.Commit(); + dbUnitOfWork.Commit(); // Act var stylesheets = repository.GetAll("styles-v2.css", "styles.css"); @@ -169,7 +182,8 @@ namespace Umbraco.Tests.Persistence.Repositories // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); - var repository = new StylesheetRepository(unitOfWork, _fileSystem); + var dbUnitOfWork = PetaPocoUnitOfWorkProvider.CreateUnitOfWork(); + var repository = new StylesheetRepository(unitOfWork, dbUnitOfWork, _fileSystem); // Act var exists = repository.Exists("styles.css"); diff --git a/src/Umbraco.Tests/Persistence/RepositoryResolverTests.cs b/src/Umbraco.Tests/Persistence/RepositoryResolverTests.cs index b7ccc58eaf..bd4d366c4e 100644 --- a/src/Umbraco.Tests/Persistence/RepositoryResolverTests.cs +++ b/src/Umbraco.Tests/Persistence/RepositoryResolverTests.cs @@ -43,7 +43,7 @@ namespace Umbraco.Tests.Persistence [TestCase(typeof(IRelationRepository))] [TestCase(typeof(IRelationTypeRepository))] [TestCase(typeof(IScriptRepository))] - [TestCase(typeof(IStylesheetRepository))] + //[TestCase(typeof(IStylesheetRepository))] [TestCase(typeof(ITemplateRepository))] public void ResolveRepository(Type repoType) { diff --git a/src/Umbraco.Web.UI/config/splashes/noNodes.aspx b/src/Umbraco.Web.UI/config/splashes/noNodes.aspx index be53c864fa..b66780d87f 100644 --- a/src/Umbraco.Web.UI/config/splashes/noNodes.aspx +++ b/src/Umbraco.Web.UI/config/splashes/noNodes.aspx @@ -27,7 +27,7 @@ diff --git a/src/Umbraco.Web.UI/umbraco/config/lang/it.xml b/src/Umbraco.Web.UI/umbraco/config/lang/it.xml index 10a670378a..d925460d57 100644 --- a/src/Umbraco.Web.UI/umbraco/config/lang/it.xml +++ b/src/Umbraco.Web.UI/umbraco/config/lang/it.xml @@ -108,7 +108,7 @@ Statistiche Titolo (opzionale) Tipo - Non pubblicato + Non pubblicare Ultima modifica Rimuovi il file Link al documento 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: - +
Insert Macro(string.Format("select 1 from cmsMacroProperty where macro = {0}", macroId)) == 1; + return ApplicationContext.DatabaseContext.Database.ExecuteScalar(string.Format("select 1 from cmsMacroProperty where macro = {0}", macroId)) == 1; } } } 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 43ad833484..9286a953f7 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/member.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/member.ascx.cs @@ -43,7 +43,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) { diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs index 32d6924932..01453e3a34 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs @@ -59,7 +59,7 @@ namespace umbraco.cms.presentation.create.controls new User(Security.CurrentUser), Request.GetItemAsString("nodeType"), nodeId, - rename.Text); + rename.Text.Trim()); BasePage.Current.ClientTools .ChangeContentFrameUrl(returnUrl) diff --git a/src/umbraco.cms/businesslogic/CMSNode.cs b/src/umbraco.cms/businesslogic/CMSNode.cs index b337f6b97c..bd997bab54 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; @@ -343,10 +344,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 diff --git a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs index d192385d8b..18234dc0d1 100644 --- a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs +++ b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs @@ -33,7 +33,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; } } diff --git a/src/umbraco.cms/businesslogic/language/Item.cs b/src/umbraco.cms/businesslogic/language/Item.cs index 30ce7089f7..6d59b45ffa 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( + "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("where UniqueId = @UniqueId", new { UniqueId = 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 diff --git a/src/umbraco.cms/businesslogic/language/Language.cs b/src/umbraco.cms/businesslogic/language/Language.cs index 0618b9d7d4..61cd99e2f2 100644 --- a/src/umbraco.cms/businesslogic/language/Language.cs +++ b/src/umbraco.cms/businesslogic/language/Language.cs @@ -6,6 +6,8 @@ using System.Xml; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Logging; +using Umbraco.Core.Models.Rdbms; + using umbraco.DataLayer; using umbraco.BusinessLogic; using System.Linq; @@ -37,13 +39,13 @@ 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; } } - protected internal const string m_SQLOptimizedGetAll = @"select * from umbracoLanguage"; - + #endregion #region Constructors @@ -86,24 +88,11 @@ namespace umbraco.cms.businesslogic.language if (culture != null) { //insert it - SqlHelper.ExecuteNonQuery( - "insert into umbracoLanguage (languageISOCode) values (@CultureCode)", - SqlHelper.CreateParameter("@CultureCode", cultureCode)); - - //get it's id - var newId = SqlHelper.ExecuteScalar("SELECT MAX(id) FROM umbracoLanguage WHERE languageISOCode=@cultureCode", SqlHelper.CreateParameter("@cultureCode", cultureCode)); - - //load it and raise events - using (var dr = SqlHelper.ExecuteReader(string.Format("{0} where id = {1}", m_SQLOptimizedGetAll, newId))) - { - while (dr.Read()) - { - - var ct = new Language(); - ct.PopulateFromReader(dr); - ct.OnNew(new NewEventArgs()); - } - } + var newId = ApplicationContext.Current.DatabaseContext.Database.Insert(new LanguageDto { IsoCode = cultureCode }); + var ct = new Language { _id = Convert.ToInt32(newId), _cultureAlias = cultureCode }; + ct.UpdateNames(); + ct.OnNew(new NewEventArgs()); + } } } @@ -135,20 +124,19 @@ namespace umbraco.cms.businesslogic.language () => { var languages = new List(); - using (var dr = SqlHelper.ExecuteReader(m_SQLOptimizedGetAll)) + var dtos = ApplicationContext.Current.DatabaseContext.Database.Fetch(""); + foreach (var dto in dtos) { - while (dr.Read()) - { - //create the ContentType object without setting up - var ct = new Language(); - ct.PopulateFromReader(dr); - languages.Add(ct); - } + var ct = new Language {_id = dto.Id, _cultureAlias = dto.IsoCode}; + ct.UpdateNames(); + languages.Add(ct); } return languages; }); } + + /// /// Gets the language by its culture code, if no language is found, null is returned /// @@ -209,9 +197,11 @@ namespace umbraco.cms.businesslogic.language set { _cultureAlias = value; - SqlHelper.ExecuteNonQuery( - "update umbracoLanguage set languageISOCode = @cultureAlias where id = @id", SqlHelper.CreateParameter("@id", id), - SqlHelper.CreateParameter("@cultureAlias", _cultureAlias)); + ApplicationContext.Current.DatabaseContext.Database.Update( + "set languageISOCode = @cultureAlias where id = @id", + new { cultureAlias = _cultureAlias,id=id} + ); + UpdateNames(); } } @@ -277,10 +267,9 @@ namespace umbraco.cms.businesslogic.language { lock (Locker) { - if (SqlHelper.ExecuteScalar("SELECT count(id) FROM umbracoDomains where domainDefaultLanguage = @id", - SqlHelper.CreateParameter("@id", id)) == 0) - { + if (ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar("SELECT count(id) FROM umbracoDomains where domainDefaultLanguage = @id", new { id = id }) == 0) + { var e = new DeleteEventArgs(); FireBeforeDelete(e); @@ -289,9 +278,8 @@ namespace umbraco.cms.businesslogic.language //remove the dictionary entries first Item.RemoveByLanguage(id); - SqlHelper.ExecuteNonQuery("delete from umbracoLanguage where id = @id", - SqlHelper.CreateParameter("@id", id)); - + ApplicationContext.Current.DatabaseContext.Database.Delete("where id = @id", + new {id = id}); FireAfterDelete(e); } } @@ -328,7 +316,8 @@ namespace umbraco.cms.businesslogic.language _cultureAlias = dr.GetString("languageISOCode"); UpdateNames(); - } + } + #endregion #region Private methods diff --git a/src/umbraco.cms/businesslogic/workflow/Notification.cs b/src/umbraco.cms/businesslogic/workflow/Notification.cs index 9387ad4444..b6b3388a74 100644 --- a/src/umbraco.cms/businesslogic/workflow/Notification.cs +++ b/src/umbraco.cms/businesslogic/workflow/Notification.cs @@ -5,10 +5,12 @@ using System.Runtime.CompilerServices; using System.Text; using System.Web; using Umbraco.Core.Configuration; +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; @@ -37,6 +39,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; } @@ -211,22 +214,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; } @@ -238,21 +238,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; } @@ -260,12 +256,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}); } /// @@ -275,8 +271,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 }); } /// @@ -287,9 +283,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}); } /// @@ -301,21 +296,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 + }); + } } /// diff --git a/src/umbraco.presentation.targets b/src/umbraco.presentation.targets index 79eb7c494d..d3d5c924c0 100644 --- a/src/umbraco.presentation.targets +++ b/src/umbraco.presentation.targets @@ -47,6 +47,10 @@ $(MSBuildExtensionsPath)\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.Tasks.dll + + + $(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll +