From 3fdf13a8b15ffded6f2ca69afa0a1efe3be8896f Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 15 Jan 2015 15:11:52 +1100 Subject: [PATCH] Removes database support from legacy stylesheet apis --- .../businesslogic/web/StyleSheet.cs | 37 +++++------------ .../businesslogic/web/StylesheetProperty.cs | 41 ++----------------- 2 files changed, 13 insertions(+), 65 deletions(-) diff --git a/src/umbraco.cms/businesslogic/web/StyleSheet.cs b/src/umbraco.cms/businesslogic/web/StyleSheet.cs index 9146fa5a54..1444307d85 100644 --- a/src/umbraco.cms/businesslogic/web/StyleSheet.cs +++ b/src/umbraco.cms/businesslogic/web/StyleSheet.cs @@ -23,11 +23,8 @@ namespace umbraco.cms.businesslogic.web { internal Stylesheet StylesheetItem; - //private string _filename = ""; - //private string _content = ""; - //private StylesheetProperty[] _properties; public static Guid ModuleObjectType = new Guid(Constants.ObjectTypes.Stylesheet); - + public string Filename { get @@ -38,12 +35,8 @@ namespace umbraco.cms.businesslogic.web } set { - //NOTE: This has zero affect - - ////move old file - //_filename = value; - //SqlHelper.ExecuteNonQuery(string.Format("update cmsStylesheet set filename = '{0}' where nodeId = {1}", _filename, Id)); - //InvalidateCache(); + //setting the file name changing it's path + StylesheetItem.Path = StylesheetItem.Path.TrimEnd(StylesheetItem.Name) + value.EnsureEndsWith(".css"); } } @@ -58,8 +51,6 @@ namespace umbraco.cms.businesslogic.web get { return StylesheetItem.Properties.Select(x => new StylesheetProperty(StylesheetItem, x)).ToArray(); } } - //static bool isInitialized = false; - internal StyleSheet(Stylesheet stylesheet) : base(stylesheet) { @@ -147,14 +138,13 @@ namespace umbraco.cms.businesslogic.web /// protected override void setupNode() { - var found = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar( - "SELECT TOP 1 filename FROM cmsStylesheet WHERE nodeid=" + Id); - if (found.IsNullOrWhiteSpace()) throw new ArgumentException(string.Format("No stylesheet exists with id '{0}'", Id)); - - StylesheetItem = ApplicationContext.Current.Services.FileService.GetStylesheetByName(found.EnsureEndsWith(".css")); - if (StylesheetItem == null) throw new ArgumentException(string.Format("No stylesheet exists with name '{0}.css'", found)); + ThrowNotSupported(); } + internal static void ThrowNotSupported() + { + throw new NotSupportedException("The legacy " + typeof(T) + " API is no longer functional for retrieving stylesheets based on an integer ID. Stylesheets are no longer persisted in database tables. Use the new Umbraco.Core.Services.IFileSystem APIs instead of working with Umbraco stylesheets."); + } public static StyleSheet MakeNew(BusinessLogic.User user, string Text, string FileName, string Content) { @@ -245,15 +235,8 @@ namespace umbraco.cms.businesslogic.web public static StyleSheet GetStyleSheet(int id, bool setupStyleProperties, bool loadContentFromFile) { - var found = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar( - "SELECT TOP 1 filename FROM cmsStylesheet WHERE nodeid=" + id); - if (found.IsNullOrWhiteSpace()) return null; - - var s = ApplicationContext.Current.Services.FileService.GetStylesheetByName(found); - if (s == null) return null; - - return new StyleSheet(s); - + ThrowNotSupported(); + return null; } [Obsolete("Stylesheet cache is automatically invalidated by Umbraco when a stylesheet is saved or deleted")] diff --git a/src/umbraco.cms/businesslogic/web/StylesheetProperty.cs b/src/umbraco.cms/businesslogic/web/StylesheetProperty.cs index 5541dfdaa6..e3d68ccc62 100644 --- a/src/umbraco.cms/businesslogic/web/StylesheetProperty.cs +++ b/src/umbraco.cms/businesslogic/web/StylesheetProperty.cs @@ -15,8 +15,6 @@ namespace umbraco.cms.businesslogic.web internal Umbraco.Core.Models.Stylesheet StylesheetItem; internal Umbraco.Core.Models.StylesheetProperty StylesheetProp; - private static readonly Guid ModuleObjectType = new Guid(Constants.ObjectTypes.StylesheetProperty); - internal StylesheetProperty(Umbraco.Core.Models.Stylesheet sheet, Umbraco.Core.Models.StylesheetProperty prop) : base(int.MaxValue, true) { @@ -37,21 +35,7 @@ namespace umbraco.cms.businesslogic.web /// protected override void setupNode() { - var foundProp = ApplicationContext.Current.DatabaseContext.Database.SingleOrDefault( - "SELECT parentID FROM cmsStylesheetProperty INNER JOIN umbracoNode ON cmsStylesheetProperty.nodeId = umbracoNode.id WHERE nodeId = @id", new {id = Id}); - - if (foundProp == null) throw new ArgumentException(string.Format("No stylesheet property exists with an id '{0}'", Id)); - - var found = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar( - "SELECT filename FROM cmsStylesheet WHERE nodeId = @id", new { id = foundProp.parentID }); - - if (found == null) throw new ArgumentException(string.Format("No stylesheet exists with a property with id '{0}'", Id)); - - StylesheetItem = ApplicationContext.Current.Services.FileService.GetStylesheetByName(found.EnsureEndsWith(".css")); - if (StylesheetItem == null) throw new ArgumentException(string.Format("No stylesheet exists with name '{0}.css'", found)); - - StylesheetProp = StylesheetItem.Properties.FirstOrDefault(x => x.Alias == foundProp.stylesheetPropertyAlias); - if (StylesheetProp == null) throw new ArgumentException(string.Format("No stylesheet property exists with alias {0}", foundProp.stylesheetPropertyAlias)); + web.StyleSheet.ThrowNotSupported(); } public StyleSheet StyleSheet() @@ -107,10 +91,6 @@ namespace umbraco.cms.businesslogic.web sheet.StylesheetItem.AddProperty(prop); ApplicationContext.Current.Services.FileService.SaveStylesheet(sheet.StylesheetItem); - //NOTE: Only for backward compatibility do we create data in the db! - var newNode = CMSNode.MakeNew(sheet.Id, ModuleObjectType, user.Id, 2, Text, Guid.NewGuid()); - SqlHelper.ExecuteNonQuery(String.Format("Insert into cmsStylesheetProperty (nodeId,stylesheetPropertyAlias,stylesheetPropertyValue) values ('{0}','{1}','')", newNode.Id, Text)); - var ssp = new StylesheetProperty(sheet.StylesheetItem, prop); var e = new NewEventArgs(); ssp.OnNew(e); @@ -153,23 +133,8 @@ namespace umbraco.cms.businesslogic.web public static StylesheetProperty GetStyleSheetProperty(int id) { - var foundProp = ApplicationContext.Current.DatabaseContext.Database.SingleOrDefault( - "SELECT parentID FROM cmsStylesheetProperty INNER JOIN umbracoNode ON cmsStylesheetProperty.nodeId = umbracoNode.id WHERE nodeId = @id", new { id = id }); - - if (foundProp == null) return null; - - var found = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar( - "SELECT filename FROM cmsStylesheet WHERE nodeId = @id", new { id = foundProp.parentID }); - - if (found == null) return null; - - var stylesheetItem = ApplicationContext.Current.Services.FileService.GetStylesheetByName(found.EnsureEndsWith(".css")); - if (stylesheetItem == null) return null; - - var stylesheetProp = stylesheetItem.Properties.FirstOrDefault(x => x.Alias == foundProp.stylesheetPropertyAlias); - if (stylesheetProp == null) return null; - - return new StylesheetProperty(stylesheetItem, stylesheetProp); + web.StyleSheet.ThrowNotSupported(); + return null; } // EVENTS