Attempting to update the legacy macro business logic code to support the db structure changes.
This commit is contained in:
@@ -309,7 +309,7 @@ namespace umbraco.cms.businesslogic.macro
|
||||
{
|
||||
|
||||
Macro m = null;
|
||||
string alias = xmlHelper.GetNodeValue(n.SelectSingleNode("alias"));
|
||||
string alias = XmlHelper.GetNodeValue(n.SelectSingleNode("alias"));
|
||||
try
|
||||
{
|
||||
//check to see if the macro alreay exists in the system
|
||||
@@ -319,27 +319,27 @@ namespace umbraco.cms.businesslogic.macro
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
m = MakeNew(xmlHelper.GetNodeValue(n.SelectSingleNode("name")));
|
||||
m = MakeNew(XmlHelper.GetNodeValue(n.SelectSingleNode("name")));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m.Alias = alias;
|
||||
m.Assembly = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptAssembly"));
|
||||
m.Type = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptType"));
|
||||
m.Xslt = xmlHelper.GetNodeValue(n.SelectSingleNode("xslt"));
|
||||
m.RefreshRate = int.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("refreshRate")));
|
||||
m.Assembly = XmlHelper.GetNodeValue(n.SelectSingleNode("scriptAssembly"));
|
||||
m.Type = XmlHelper.GetNodeValue(n.SelectSingleNode("scriptType"));
|
||||
m.Xslt = XmlHelper.GetNodeValue(n.SelectSingleNode("xslt"));
|
||||
m.RefreshRate = int.Parse(XmlHelper.GetNodeValue(n.SelectSingleNode("refreshRate")));
|
||||
|
||||
// we need to validate if the usercontrol is missing the tilde prefix requirement introduced in v6
|
||||
if (String.IsNullOrEmpty(m.Assembly) && !String.IsNullOrEmpty(m.Type) && !m.Type.StartsWith("~"))
|
||||
m.Type = "~/" + m.Type;
|
||||
|
||||
if (n.SelectSingleNode("scriptingFile") != null)
|
||||
m.ScriptingFile = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptingFile"));
|
||||
m.ScriptingFile = XmlHelper.GetNodeValue(n.SelectSingleNode("scriptingFile"));
|
||||
|
||||
try
|
||||
{
|
||||
m.UseInEditor = bool.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("useInEditor")));
|
||||
m.UseInEditor = bool.Parse(XmlHelper.GetNodeValue(n.SelectSingleNode("useInEditor")));
|
||||
}
|
||||
catch (Exception macroExp)
|
||||
{
|
||||
@@ -355,9 +355,8 @@ namespace umbraco.cms.businesslogic.macro
|
||||
var property = m.Properties.SingleOrDefault(p => p.Alias == propertyAlias);
|
||||
if (property != null)
|
||||
{
|
||||
property.Public = bool.Parse(mp.Attributes.GetNamedItem("show").Value);
|
||||
property.Name = mp.Attributes.GetNamedItem("name").Value;
|
||||
property.Type = new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value);
|
||||
property.ParameterEditorAlias = mp.Attributes.GetNamedItem("propertyType").Value;
|
||||
|
||||
property.Save();
|
||||
}
|
||||
@@ -365,10 +364,9 @@ namespace umbraco.cms.businesslogic.macro
|
||||
{
|
||||
MacroProperty.MakeNew(
|
||||
m,
|
||||
bool.Parse(mp.Attributes.GetNamedItem("show").Value),
|
||||
propertyAlias,
|
||||
mp.Attributes.GetNamedItem("name").Value,
|
||||
new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value)
|
||||
mp.Attributes.GetNamedItem("propertyType").Value
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -427,14 +425,14 @@ namespace umbraco.cms.businesslogic.macro
|
||||
XmlNode doc = xd.CreateElement("macro");
|
||||
|
||||
// info section
|
||||
doc.AppendChild(xmlHelper.addTextNode(xd, "name", this.Name));
|
||||
doc.AppendChild(xmlHelper.addTextNode(xd, "alias", this.Alias));
|
||||
doc.AppendChild(xmlHelper.addTextNode(xd, "scriptType", this.Type));
|
||||
doc.AppendChild(xmlHelper.addTextNode(xd, "scriptAssembly", this.Assembly));
|
||||
doc.AppendChild(xmlHelper.addTextNode(xd, "xslt", this.Xslt));
|
||||
doc.AppendChild(xmlHelper.addTextNode(xd, "useInEditor", this.UseInEditor.ToString()));
|
||||
doc.AppendChild(xmlHelper.addTextNode(xd, "refreshRate", this.RefreshRate.ToString()));
|
||||
doc.AppendChild(xmlHelper.addTextNode(xd, "scriptingFile", this.ScriptingFile));
|
||||
doc.AppendChild(XmlHelper.AddTextNode(xd, "name", this.Name));
|
||||
doc.AppendChild(XmlHelper.AddTextNode(xd, "alias", this.Alias));
|
||||
doc.AppendChild(XmlHelper.AddTextNode(xd, "scriptType", this.Type));
|
||||
doc.AppendChild(XmlHelper.AddTextNode(xd, "scriptAssembly", this.Assembly));
|
||||
doc.AppendChild(XmlHelper.AddTextNode(xd, "xslt", this.Xslt));
|
||||
doc.AppendChild(XmlHelper.AddTextNode(xd, "useInEditor", this.UseInEditor.ToString()));
|
||||
doc.AppendChild(XmlHelper.AddTextNode(xd, "refreshRate", this.RefreshRate.ToString()));
|
||||
doc.AppendChild(XmlHelper.AddTextNode(xd, "scriptingFile", this.ScriptingFile));
|
||||
|
||||
// properties
|
||||
XmlNode props = xd.CreateElement("properties");
|
||||
|
||||
@@ -2,7 +2,7 @@ using System;
|
||||
using System.Data;
|
||||
using System.Xml;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
using Umbraco.Core;
|
||||
using umbraco.DataLayer;
|
||||
using umbraco.BusinessLogic;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,15 +20,6 @@ namespace umbraco.cms.businesslogic.macro
|
||||
/// </summary>
|
||||
public class MacroProperty
|
||||
{
|
||||
|
||||
int _id;
|
||||
int _sortOrder;
|
||||
bool _public;
|
||||
string _alias;
|
||||
string _name;
|
||||
cms.businesslogic.macro.Macro m_macro;
|
||||
cms.businesslogic.macro.MacroPropertyType _type;
|
||||
|
||||
protected static ISqlHelper SqlHelper
|
||||
{
|
||||
get { return Application.SqlHelper; }
|
||||
@@ -47,92 +38,66 @@ namespace umbraco.cms.businesslogic.macro
|
||||
/// <param name="Id">Id</param>
|
||||
public MacroProperty(int Id)
|
||||
{
|
||||
_id = Id;
|
||||
setup();
|
||||
this.Id = Id;
|
||||
Setup();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The sortorder
|
||||
/// </summary>
|
||||
public int SortOrder
|
||||
{
|
||||
get { return _sortOrder; }
|
||||
set { _sortOrder = value; }
|
||||
}
|
||||
public int SortOrder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If set to true, the user will be presented with an editor to input data.
|
||||
///
|
||||
/// If not, the field can be manipulated by a default value given by the MacroPropertyType, this is s
|
||||
/// This is not used for anything
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public bool Public
|
||||
{
|
||||
get { return _public; }
|
||||
set { _public = value; }
|
||||
}
|
||||
[Obsolete("This is not used for anything and will be removed in future versions")]
|
||||
public bool Public { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The alias if of the macroproperty, this is used in the special macro element
|
||||
/// <?UMBRACO_MACRO macroAlias="value"></?UMBRACO_MACRO>
|
||||
///
|
||||
/// The macro property alias
|
||||
/// </summary>
|
||||
public string Alias
|
||||
{
|
||||
get { return _alias; }
|
||||
set { _alias = value; }
|
||||
}
|
||||
public string Alias { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The userfriendly name
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the id.
|
||||
/// </summary>
|
||||
/// <value>The id.</value>
|
||||
public int Id
|
||||
{
|
||||
get { return _id; }
|
||||
}
|
||||
public int Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the macro.
|
||||
/// </summary>
|
||||
/// <value>The macro.</value>
|
||||
public Macro Macro
|
||||
{
|
||||
get { return m_macro; }
|
||||
set { m_macro = value; }
|
||||
}
|
||||
public Macro Macro { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The basetype which defines which component is used in the UI for editing content
|
||||
/// </summary>
|
||||
public MacroPropertyType Type
|
||||
{
|
||||
get { return _type; }
|
||||
set { _type = value; }
|
||||
}
|
||||
[Obsolete("This no longer does anything and will be removed in future versions")]
|
||||
public MacroPropertyType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The macro parameter editor alias used to render the editor
|
||||
/// </summary>
|
||||
public string ParameterEditorAlias { get; set; }
|
||||
|
||||
private void setup()
|
||||
private void Setup()
|
||||
{
|
||||
using (IRecordsReader dr = SqlHelper.ExecuteReader("select macro, macroPropertyHidden, macroPropertyType, macroPropertySortOrder, macroPropertyAlias, macroPropertyName from cmsMacroProperty where id = @id", SqlHelper.CreateParameter("@id", _id)))
|
||||
using (var dr = SqlHelper.ExecuteReader("select macro, macroPropertyHidden, editorAlias, macroPropertySortOrder, macroPropertyAlias, macroPropertyName from cmsMacroProperty where id = @id", SqlHelper.CreateParameter("@id", Id)))
|
||||
{
|
||||
if (dr.Read())
|
||||
{
|
||||
m_macro = new Macro(dr.GetInt("macro"));
|
||||
_public = dr.GetBoolean("macroPropertyHidden");
|
||||
_sortOrder = (int)dr.GetByte("macroPropertySortOrder");
|
||||
_alias = dr.GetString("macroPropertyAlias");
|
||||
_name = dr.GetString("macroPropertyName");
|
||||
_type = new MacroPropertyType(dr.GetShort("macroPropertyType"));
|
||||
Macro = new Macro(dr.GetInt("macro"));
|
||||
SortOrder = (int)dr.GetByte("macroPropertySortOrder");
|
||||
Alias = dr.GetString("macroPropertyAlias");
|
||||
Name = dr.GetString("macroPropertyName");
|
||||
Type = null;
|
||||
ParameterEditorAlias = dr.GetString("editorAlias");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -146,28 +111,29 @@ namespace umbraco.cms.businesslogic.macro
|
||||
/// </summary>
|
||||
public void Delete()
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery("delete from cmsMacroProperty where id = @id", SqlHelper.CreateParameter("@id", this._id));
|
||||
SqlHelper.ExecuteNonQuery("delete from cmsMacroProperty where id = @id", SqlHelper.CreateParameter("@id", this.Id));
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (_id == 0)
|
||||
if (Id == 0)
|
||||
{
|
||||
MacroProperty mp =
|
||||
MakeNew(m_macro, Public, Alias, Name, Type);
|
||||
_id = mp.Id;
|
||||
MakeNew(Macro, Public, Alias, Name, Type);
|
||||
Id = mp.Id;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
SqlHelper.ExecuteNonQuery("UPDATE cmsMacroProperty set macro = @macro, macroPropertyHidden = @show, macropropertyAlias = @alias, macroPropertyName = @name, macroPropertyType = @type, macroPropertySortOrder = @so WHERE id = @id",
|
||||
SqlHelper.CreateParameter("@id", Id),
|
||||
SqlHelper.CreateParameter("@macro", Macro.Id),
|
||||
SqlHelper.CreateParameter("@show", Public),
|
||||
SqlHelper.CreateParameter("@alias", Alias),
|
||||
SqlHelper.CreateParameter("@name", Name),
|
||||
SqlHelper.CreateParameter("@type", Type.Id),
|
||||
SqlHelper.CreateParameter("@so", SortOrder));
|
||||
SqlHelper.ExecuteNonQuery("UPDATE cmsMacroProperty set macro = @macro, " +
|
||||
"macropropertyAlias = @alias, macroPropertyName = @name, " +
|
||||
"editorAlias = @editorAlias, macroPropertySortOrder = @so WHERE id = @id",
|
||||
SqlHelper.CreateParameter("@id", Id),
|
||||
SqlHelper.CreateParameter("@macro", Macro.Id),
|
||||
SqlHelper.CreateParameter("@alias", Alias),
|
||||
SqlHelper.CreateParameter("@name", Name),
|
||||
SqlHelper.CreateParameter("@editorAlias", ParameterEditorAlias),
|
||||
SqlHelper.CreateParameter("@so", SortOrder));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,10 +146,9 @@ namespace umbraco.cms.businesslogic.macro
|
||||
{
|
||||
XmlElement doc = xd.CreateElement("property");
|
||||
|
||||
doc.Attributes.Append(xmlHelper.addAttribute(xd, "name", this.Name));
|
||||
doc.Attributes.Append(xmlHelper.addAttribute(xd, "alias", this.Alias));
|
||||
doc.Attributes.Append(xmlHelper.addAttribute(xd, "show", this.Public.ToString()));
|
||||
doc.Attributes.Append(xmlHelper.addAttribute(xd, "propertyType", this.Type.Alias));
|
||||
doc.Attributes.Append(XmlHelper.AddAttribute(xd, "name", this.Name));
|
||||
doc.Attributes.Append(XmlHelper.AddAttribute(xd, "alias", this.Alias));
|
||||
doc.Attributes.Append(XmlHelper.AddAttribute(xd, "propertyType", this.ParameterEditorAlias));
|
||||
|
||||
return doc;
|
||||
}
|
||||
@@ -193,12 +158,12 @@ namespace umbraco.cms.businesslogic.macro
|
||||
/// <summary>
|
||||
/// Retieve all MacroProperties of a macro
|
||||
/// </summary>
|
||||
/// <param name="MacroId">Macro identifier</param>
|
||||
/// <param name="macroId">Macro identifier</param>
|
||||
/// <returns>All MacroProperties of a macro</returns>
|
||||
public static MacroProperty[] GetProperties(int MacroId)
|
||||
public static MacroProperty[] GetProperties(int macroId)
|
||||
{
|
||||
var props = new List<MacroProperty>();
|
||||
using (IRecordsReader dr = SqlHelper.ExecuteReader("select id from cmsMacroProperty where macro = @macroId order by macroPropertySortOrder, id ASC", SqlHelper.CreateParameter("@macroId", MacroId)))
|
||||
using (IRecordsReader dr = SqlHelper.ExecuteReader("select id from cmsMacroProperty where macro = @macroId order by macroPropertySortOrder, id ASC", SqlHelper.CreateParameter("@macroId", macroId)))
|
||||
{
|
||||
while (dr.Read())
|
||||
{
|
||||
@@ -208,25 +173,31 @@ namespace umbraco.cms.businesslogic.macro
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
[Obsolete("This method is no longer supported because MacroPropertyType no longer has a function")]
|
||||
public static MacroProperty MakeNew(Macro macro, bool show, string alias, string name, MacroPropertyType propertyType)
|
||||
{
|
||||
return MakeNew(macro, alias, name, propertyType.Alias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new MacroProperty on a macro
|
||||
/// </summary>
|
||||
/// <param name="M">The macro</param>
|
||||
/// <param name="show">Will the editor be able to input data</param>
|
||||
/// <param name="macro">The macro</param>
|
||||
/// <param name="alias">The alias of the property</param>
|
||||
/// <param name="name">Userfriendly MacroProperty name</param>
|
||||
/// <param name="propertyType">The MacroPropertyType of the property</param>
|
||||
/// <param name="editorAlias">The Alias of the parameter editor</param>
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
public static MacroProperty MakeNew(Macro M, bool show, string alias, string name, MacroPropertyType propertyType)
|
||||
public static MacroProperty MakeNew(Macro macro, string alias, string name, string editorAlias)
|
||||
{
|
||||
int macroPropertyId = 0;
|
||||
// The method is synchronized
|
||||
SqlHelper.ExecuteNonQuery("INSERT INTO cmsMacroProperty (macro, macroPropertyHidden, macropropertyAlias, macroPropertyName, macroPropertyType) VALUES (@macro, @show, @alias, @name, @type)",
|
||||
SqlHelper.CreateParameter("@macro", M.Id),
|
||||
SqlHelper.CreateParameter("@show", show),
|
||||
SqlHelper.ExecuteNonQuery("INSERT INTO cmsMacroProperty (macro, macropropertyAlias, macroPropertyName, editorAlias) VALUES (@macro, @alias, @name, @editorAlias)",
|
||||
SqlHelper.CreateParameter("@macro", macro.Id),
|
||||
SqlHelper.CreateParameter("@alias", alias),
|
||||
SqlHelper.CreateParameter("@name", name),
|
||||
SqlHelper.CreateParameter("@type", propertyType.Id));
|
||||
SqlHelper.CreateParameter("@editorAlias", editorAlias));
|
||||
macroPropertyId = SqlHelper.ExecuteScalar<int>("SELECT MAX(id) FROM cmsMacroProperty");
|
||||
return new MacroProperty(macroPropertyId);
|
||||
}
|
||||
|
||||
@@ -10,15 +10,9 @@ namespace umbraco.cms.businesslogic.macro
|
||||
/// The MacroPropertyType class contains information on the assembly and class of the
|
||||
/// IMacroGuiRendering component and basedatatype
|
||||
/// </summary>
|
||||
[Obsolete("This class is no longer used, the cmsMacroPropertyType has been removed, all methods will return empty collections and not perform any functions")]
|
||||
public class MacroPropertyType
|
||||
{
|
||||
int _id;
|
||||
string _alias;
|
||||
string _assembly;
|
||||
string _type;
|
||||
string _baseType;
|
||||
private static List<MacroPropertyType> m_allPropertyTypes = new List<MacroPropertyType>();
|
||||
|
||||
protected static ISqlHelper SqlHelper
|
||||
{
|
||||
get { return Application.SqlHelper; }
|
||||
@@ -26,61 +20,41 @@ namespace umbraco.cms.businesslogic.macro
|
||||
|
||||
public static List<MacroPropertyType> GetAll
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_allPropertyTypes.Count == 0)
|
||||
{
|
||||
using (IRecordsReader dr = SqlHelper.ExecuteReader("select id from cmsMacroPropertyType order by macroPropertyTypeAlias"))
|
||||
{
|
||||
while (dr.Read())
|
||||
{
|
||||
m_allPropertyTypes.Add(new MacroPropertyType(dr.GetShort("id")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m_allPropertyTypes;
|
||||
}
|
||||
get { return new List<MacroPropertyType>(); }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Identifier
|
||||
/// </summary>
|
||||
public int Id
|
||||
{
|
||||
get { return _id; }
|
||||
}
|
||||
public int Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The alias of the MacroPropertyType
|
||||
/// </summary>
|
||||
public string Alias { get { return _alias; } }
|
||||
public string Alias { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The assembly (without the .dll extension) used to retrieve the component at runtime
|
||||
/// </summary>
|
||||
public string Assembly { get { return _assembly; } }
|
||||
public string Assembly { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The MacroPropertyType
|
||||
/// </summary>
|
||||
public string Type { get { return _type; } }
|
||||
public string Type { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The IMacroGuiRendering component (namespace.namespace.Classname)
|
||||
/// </summary>
|
||||
public string BaseType { get { return _baseType; } }
|
||||
|
||||
|
||||
public string BaseType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="Id">Identifier</param>
|
||||
public MacroPropertyType(int Id)
|
||||
{
|
||||
_id = Id;
|
||||
setup();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -89,28 +63,8 @@ namespace umbraco.cms.businesslogic.macro
|
||||
/// <param name="Alias">The alias of the MacroPropertyType</param>
|
||||
public MacroPropertyType(string Alias)
|
||||
{
|
||||
_id = SqlHelper.ExecuteScalar<int>("select id from cmsMacroPropertyType where macroPropertyTypeAlias = @alias", SqlHelper.CreateParameter("@alias", Alias));
|
||||
setup();
|
||||
|
||||
}
|
||||
|
||||
private void setup()
|
||||
{
|
||||
using (IRecordsReader dr = SqlHelper.ExecuteReader("select macroPropertyTypeAlias, macroPropertyTypeRenderAssembly, macroPropertyTypeRenderType, macroPropertyTypeBaseType from cmsMacroPropertyType where id = @id", SqlHelper.CreateParameter("@id", _id)))
|
||||
{
|
||||
if (dr.Read())
|
||||
{
|
||||
_alias = dr.GetString("macroPropertyTypeAlias");
|
||||
_assembly = dr.GetString("macroPropertyTypeRenderAssembly");
|
||||
_type = dr.GetString("macroPropertyTypeRenderType");
|
||||
_baseType = dr.GetString("macroPropertyTypeBaseType");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("No macro property type found with the id specified");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user