Removes database support from legacy stylesheet apis

This commit is contained in:
Shannon
2015-01-15 15:11:52 +11:00
parent 23ea9e71fd
commit 3fdf13a8b1
2 changed files with 13 additions and 65 deletions

View File

@@ -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
/// </summary>
protected override void setupNode()
{
var found = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar<string>(
"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<StyleSheet>();
}
internal static void ThrowNotSupported<T>()
{
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<string>(
"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<StyleSheet>();
return null;
}
[Obsolete("Stylesheet cache is automatically invalidated by Umbraco when a stylesheet is saved or deleted")]

View File

@@ -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
/// </summary>
protected override void setupNode()
{
var foundProp = ApplicationContext.Current.DatabaseContext.Database.SingleOrDefault<dynamic>(
"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<string>(
"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<StylesheetProperty>();
}
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<dynamic>(
"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<string>(
"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<StylesheetProperty>();
return null;
}
// EVENTS