Implements 21002

[TFS Changeset #81524]
This commit is contained in:
hartvig
2010-12-06 09:43:56 +00:00
parent 6b81546606
commit 724dc74e8b
4 changed files with 405 additions and 349 deletions

View File

@@ -35,7 +35,7 @@ namespace umbraco.cms.businesslogic
///
/// </summary>
/// <param name="id"></param>
public ContentType(int id) : base(id) { }
public ContentType(int id) : base(id) { }
/// <summary>
/// Initializes a new instance of the <see cref="ContentType"/> class.
@@ -98,7 +98,7 @@ namespace umbraco.cms.businesslogic
FROM umbracoNode INNER JOIN cmsContentType ON umbracoNode.id = cmsContentType.nodeId
WHERE nodeObjectType = @nodeObjectType";
private static readonly object m_Locker = new object();
private static readonly object m_Locker = new object();
#endregion
@@ -117,7 +117,7 @@ namespace umbraco.cms.businesslogic
delegate
{
return new ContentType(id);
});
});
}
/// <summary>
@@ -206,7 +206,7 @@ namespace umbraco.cms.businesslogic
private static readonly object propertyTypesCacheSyncLock = new object();
#endregion
#region Public Properties
/// <summary>
@@ -351,7 +351,7 @@ namespace umbraco.cms.businesslogic
set
{
_alias = helpers.Casing.SafeAliasWithForcingCheck(value);
// validate if alias is empty
if (String.IsNullOrEmpty(_alias))
{
@@ -488,7 +488,7 @@ namespace umbraco.cms.businesslogic
/// </summary>
/// <returns>The list of all ContentTypes</returns>
public ContentType[] GetAll()
{
{
var contentTypes = new List<ContentType>();
using (IRecordsReader dr =
@@ -508,7 +508,7 @@ namespace umbraco.cms.businesslogic
}
return contentTypes.ToArray();
}
/// <summary>
@@ -517,7 +517,7 @@ namespace umbraco.cms.businesslogic
/// <param name="dt">The DataTypeDefinition of the PropertyType</param>
/// <param name="Alias">The Alias of the PropertyType</param>
/// <param name="Name">The userfriendly name</param>
public void AddPropertyType(DataTypeDefinition dt, string Alias, string Name)
public PropertyType AddPropertyType(DataTypeDefinition dt, string Alias, string Name)
{
PropertyType pt = PropertyType.MakeNew(dt, this, Name, Alias);
@@ -532,6 +532,8 @@ namespace umbraco.cms.businesslogic
// Remove from cache
FlushFromCache(Id);
return pt;
}
/// <summary>
@@ -541,13 +543,11 @@ namespace umbraco.cms.businesslogic
/// <param name="pt">The PropertyType</param>
/// <param name="TabId">The Id of the Tab</param>
public void SetTabOnPropertyType(PropertyType pt, int TabId)
{
{
// This is essentially just a wrapper for the property
pt.TabId = TabId;
//flush the content type cache, the the tab cache (why so much cache?! argh!)
FlushFromCache(Id);
foreach (TabI t in getVirtualTabs.ToList())
FlushTabCache(t.Id, pt.ContentTypeId);
pt.FlushCacheBasedOnTab();
}
/// <summary>
@@ -555,7 +555,7 @@ namespace umbraco.cms.businesslogic
/// </summary>
/// <param name="pt">The PropertyType which should be freed from its tab</param>
public void removePropertyTypeFromTab(PropertyType pt)
{
{
pt.TabId = 0; //this will set to null in the database.
// Remove from cache
FlushFromCache(Id);
@@ -734,12 +734,12 @@ namespace umbraco.cms.businesslogic
{
if (dr.Read())
{
PopulateContentTypeNodeFromReader(dr);
PopulateContentTypeNodeFromReader(dr);
}
else
{
throw new ArgumentException("No Contenttype with id: " + Id);
}
}
}
}
@@ -756,18 +756,20 @@ namespace umbraco.cms.businesslogic
/// Flushes the cache.
/// </summary>
/// <param name="Id">The id.</param>
public void FlushFromCache(int Id)
public static void FlushFromCache(int id)
{
Cache.ClearCacheItem(string.Format("UmbracoContentType{0}", Id.ToString()));
Cache.ClearCacheItem(GetPropertiesCacheKey());
ContentType ct = new ContentType(id);
Cache.ClearCacheItem(string.Format("UmbracoContentType{0}", id));
Cache.ClearCacheItem(ct.GetPropertiesCacheKey());
ct.ClearVirtualTabs();
ClearVirtualTabs();
// clear anything that uses this as master content type
if (this.nodeObjectType == DocumentType._objectType)
if (ct.nodeObjectType == DocumentType._objectType)
{
List<DocumentType> cacheToFlush = DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentType == Id);
foreach(DocumentType dt in cacheToFlush)
List<DocumentType> cacheToFlush = DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentType == id);
foreach (DocumentType dt in cacheToFlush)
FlushFromCache(dt.Id);
}
@@ -779,7 +781,7 @@ namespace umbraco.cms.businesslogic
Cache.ClearCacheByKeySearch("ContentType_PropertyTypes_Content");
ClearVirtualTabs();
}
}
#endregion
@@ -799,6 +801,9 @@ namespace umbraco.cms.businesslogic
/// </summary>
private void ClearVirtualTabs()
{
foreach (TabI t in getVirtualTabs)
Tab.FlushCache(t.Id, t.ContentType);
m_VirtualTabs = null;
}
@@ -862,7 +867,7 @@ namespace umbraco.cms.businesslogic
SqlHelper.ExecuteNonQuery(
"insert into cmsPropertyData (contentNodeId, versionId, propertyTypeId) select contentId, versionId, " + pt.Id + " from cmsContent inner join cmsContentVersion on cmsContent.nodeId = cmsContentVersion.contentId where contentType = @contentTypeId",
SqlHelper.CreateParameter("@contentTypeId", contentTypeId));
}
}
#endregion
@@ -912,7 +917,7 @@ namespace umbraco.cms.businesslogic
/// Method for moving the tab down
/// </summary>
void MoveDown();
}
}
#endregion
#region Protected Tab Class
@@ -920,7 +925,7 @@ namespace umbraco.cms.businesslogic
/// A tab is merely a way to organize data on a ContentType to make it more
/// human friendly
/// </summary>
protected class Tab : TabI
public class Tab : TabI
{
private ContentType _contenttype;
private static object propertyTypesCacheSyncLock = new object();
@@ -967,13 +972,33 @@ namespace umbraco.cms.businesslogic
});
}
public static Tab GetTab(int id)
{
Tab tab = null;
using (IRecordsReader dr = SqlHelper.ExecuteReader(
string.Format(
"Select Id, text, contenttypeNodeId, sortOrder from cmsTab where Id = {0} order by sortOrder",
id)))
{
if (dr.Read())
{
tab = new Tab(id, dr.GetString("text"), dr.GetInt("sortOrder"), new ContentType(dr.GetInt("contenttypeNodeId")),
true);
}
dr.Close();
}
return tab;
}
/// <summary>
/// Flushes the cache.
/// </summary>
/// <param name="Id">The id.</param>
public static void FlushCache(int Id, int ContentTypeId)
/// <param name="id">The id.</param>
/// <param name="contentTypeId"></param>
public static void FlushCache(int id, int contentTypeId)
{
Cache.ClearCacheItem(generateCacheKey(Id, ContentTypeId));
Cache.ClearCacheItem(generateCacheKey(id, contentTypeId));
}
private static string generateCacheKey(int tabId, int contentTypeId)
@@ -1169,9 +1194,9 @@ namespace umbraco.cms.businesslogic
}
}
}
}
}
#endregion
///// <summary>
///// Analyzes the content types.
@@ -1209,6 +1234,6 @@ namespace umbraco.cms.businesslogic
// return (bool) _optimizedContentTypes[UniqueId];
//}
}
}

View File

@@ -1,93 +1,93 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Web.UI;
using System.Linq;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.cache;
using umbraco.cms.businesslogic.datatype;
using umbraco.cms.businesslogic.language;
using umbraco.interfaces;
using umbraco.DataLayer;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.property;
using umbraco.cms.businesslogic.web;
using umbraco.cms.helpers;
using umbraco.DataLayer;
using umbraco.interfaces;
namespace umbraco.cms.businesslogic.propertytype
{
/// <summary>
/// Summary description for propertytype.
/// </summary>
public class PropertyType
{
#region Declarations
/// <summary>
/// Summary description for propertytype.
/// </summary>
public class PropertyType
{
#region Declarations
private string _alias;
private string _name;
private int _id;
private int _DataTypeId;
private int _contenttypeid;
private int _sortOrder;
private bool _mandatory = false;
private string _validationRegExp = "";
private string _description = "";
private int _tabId = 0;
private static string _connstring = GlobalSettings.DbDSN;
private static string _connstring = GlobalSettings.DbDSN;
private static object propertyTypeCacheSyncLock = new object();
private static readonly string UmbracoPropertyTypeCacheKey = "UmbracoPropertyTypeCache";
private static readonly object propertyTypeCacheSyncLock = new object();
private static readonly string UmbracoPropertyTypeCacheKey = "UmbracoPropertyTypeCache";
private readonly int _contenttypeid;
private readonly int _id;
private int _DataTypeId;
private string _alias;
private string _description = "";
private bool _mandatory;
private string _name;
private int _sortOrder;
private int _tabId;
private string _validationRegExp = "";
#endregion
#endregion
protected static ISqlHelper SqlHelper
{
get { return Application.SqlHelper; }
}
#region Constructors
#region Constructors
public PropertyType(int id)
{
using (IRecordsReader dr = SqlHelper.ExecuteReader(
"Select mandatory, DataTypeId, tabId, ContentTypeId, sortOrder, alias, name, validationRegExp, description from cmsPropertyType where id=@id",
SqlHelper.CreateParameter("@id", id)))
{
if(!dr.Read())
throw new ArgumentException("Propertytype with id: " + id + " doesnt exist!");
_mandatory = dr.GetBoolean("mandatory");
_id = id;
if(!dr.IsNull("tabId"))
_tabId = dr.GetInt("tabId");
_sortOrder = dr.GetInt("sortOrder");
_alias = dr.GetString("alias");
_name = dr.GetString("Name");
_validationRegExp = dr.GetString("validationRegExp");
_DataTypeId = dr.GetInt("DataTypeId");
_contenttypeid = dr.GetInt("contentTypeId");
_description = dr.GetString("description");
}
}
public PropertyType(int id)
{
using (IRecordsReader dr = SqlHelper.ExecuteReader(
"Select mandatory, DataTypeId, tabId, ContentTypeId, sortOrder, alias, name, validationRegExp, description from cmsPropertyType where id=@id",
SqlHelper.CreateParameter("@id", id)))
{
if (!dr.Read())
throw new ArgumentException("Propertytype with id: " + id + " doesnt exist!");
_mandatory = dr.GetBoolean("mandatory");
_id = id;
if (!dr.IsNull("tabId"))
_tabId = dr.GetInt("tabId");
_sortOrder = dr.GetInt("sortOrder");
_alias = dr.GetString("alias");
_name = dr.GetString("Name");
_validationRegExp = dr.GetString("validationRegExp");
_DataTypeId = dr.GetInt("DataTypeId");
_contenttypeid = dr.GetInt("contentTypeId");
_description = dr.GetString("description");
}
}
#endregion
#endregion
#region Properties
#region Properties
public DataTypeDefinition DataTypeDefinition
{
get { return DataTypeDefinition.GetDataTypeDefinition(_DataTypeId); }
set
{
_DataTypeId = value.Id;
this.InvalidateCache();
SqlHelper.ExecuteNonQuery(
"Update cmsPropertyType set DataTypeId = " + value.Id + " where id=" + this.Id);
}
}
public DataTypeDefinition DataTypeDefinition
{
get { return DataTypeDefinition.GetDataTypeDefinition(_DataTypeId); }
set
{
_DataTypeId = value.Id;
InvalidateCache();
SqlHelper.ExecuteNonQuery(
"Update cmsPropertyType set DataTypeId = " + value.Id + " where id=" + Id);
}
}
public int Id
{
get { return _id; }
}
public int Id
{
get { return _id; }
}
/// <summary>
/// Setting the tab id is not meant to be used directly in code. Use the ContentType SetTabOnPropertyType method instead
@@ -96,158 +96,171 @@ namespace umbraco.cms.businesslogic.propertytype
/// <remarks>
/// Setting the tab id to a negative value will actually set the value to NULL in the database
/// </remarks>
public int TabId
{
get { return _tabId; }
set
{
_tabId = value;
this.InvalidateCache();
public int TabId
{
get { return _tabId; }
set
{
_tabId = value;
InvalidateCache();
object tabId = value;
if (value < 1)
{
tabId = DBNull.Value;
}
SqlHelper.ExecuteNonQuery( "Update cmsPropertyType set tabId = @tabId where id = @id",
SqlHelper.CreateParameter("@tabId", tabId),
SqlHelper.CreateParameter("@id", this.Id));
}
}
SqlHelper.ExecuteNonQuery("Update cmsPropertyType set tabId = @tabId where id = @id",
SqlHelper.CreateParameter("@tabId", tabId),
SqlHelper.CreateParameter("@id", Id));
}
}
public bool Mandatory
{
get { return _mandatory; }
set
{
_mandatory = value;
this.InvalidateCache();
SqlHelper.ExecuteNonQuery(
"Update cmsPropertyType set mandatory = @mandatory where id = @id", SqlHelper.CreateParameter("@mandatory", value),
SqlHelper.CreateParameter("@id", this.Id));
}
}
public bool Mandatory
{
get { return _mandatory; }
set
{
_mandatory = value;
InvalidateCache();
SqlHelper.ExecuteNonQuery(
"Update cmsPropertyType set mandatory = @mandatory where id = @id",
SqlHelper.CreateParameter("@mandatory", value),
SqlHelper.CreateParameter("@id", Id));
}
}
public string ValidationRegExp
{
get { return _validationRegExp; }
set
{
_validationRegExp = value;
this.InvalidateCache();
SqlHelper.ExecuteNonQuery(
"Update cmsPropertyType set validationRegExp = @validationRegExp where id = @id",
SqlHelper.CreateParameter("@validationRegExp", value), SqlHelper.CreateParameter("@id", this.Id));
}
}
public string ValidationRegExp
{
get { return _validationRegExp; }
set
{
_validationRegExp = value;
InvalidateCache();
SqlHelper.ExecuteNonQuery(
"Update cmsPropertyType set validationRegExp = @validationRegExp where id = @id",
SqlHelper.CreateParameter("@validationRegExp", value), SqlHelper.CreateParameter("@id", Id));
}
}
public string Description
{
get {
if (_description != null) {
public string Description
{
get
{
if (_description != null)
{
if (!_description.StartsWith("#"))
return _description;
else {
else
{
Language lang = Language.GetByCultureCode(Thread.CurrentThread.CurrentCulture.Name);
if (lang != null) {
if (Dictionary.DictionaryItem.hasKey(_description.Substring(1, _description.Length - 1))) {
Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(_description.Substring(1, _description.Length - 1));
if (lang != null)
{
if (Dictionary.DictionaryItem.hasKey(_description.Substring(1, _description.Length - 1)))
{
var di =
new Dictionary.DictionaryItem(_description.Substring(1, _description.Length - 1));
return di.Value(lang.id);
}
}
}
return "[" + _description + "]";
} else
}
else
return _description;
}
set
{
_description = value;
this.InvalidateCache();
SqlHelper.ExecuteNonQuery(
"Update cmsPropertyType set description = @description where id = @id", SqlHelper.CreateParameter("@description", value),
SqlHelper.CreateParameter("@id", this.Id));
}
}
public int SortOrder
{
get { return _sortOrder; }
set
{
_sortOrder = value;
this.InvalidateCache();
SqlHelper.ExecuteNonQuery(
"Update cmsPropertyType set sortOrder = @sortOrder where id = @id", SqlHelper.CreateParameter("@sortOrder", value),
SqlHelper.CreateParameter("@id", this.Id));
}
}
public string Alias
{
get { return _alias; }
set
{
_alias = value;
this.InvalidateCache();
SqlHelper.ExecuteNonQuery("Update cmsPropertyType set alias = @alias where id= @id",
SqlHelper.CreateParameter("@alias", helpers.Casing.SafeAliasWithForcingCheck(_alias)),
set
{
_description = value;
InvalidateCache();
SqlHelper.ExecuteNonQuery(
"Update cmsPropertyType set description = @description where id = @id",
SqlHelper.CreateParameter("@description", value),
SqlHelper.CreateParameter("@id", Id));
}
}
}
}
public int SortOrder
{
get { return _sortOrder; }
set
{
_sortOrder = value;
InvalidateCache();
SqlHelper.ExecuteNonQuery(
"Update cmsPropertyType set sortOrder = @sortOrder where id = @id",
SqlHelper.CreateParameter("@sortOrder", value),
SqlHelper.CreateParameter("@id", Id));
}
}
public string Alias
{
get { return _alias; }
set
{
_alias = value;
InvalidateCache();
SqlHelper.ExecuteNonQuery("Update cmsPropertyType set alias = @alias where id= @id",
SqlHelper.CreateParameter("@alias", Casing.SafeAliasWithForcingCheck(_alias)),
SqlHelper.CreateParameter("@id", Id));
}
}
public int ContentTypeId
{
get { return _contenttypeid; }
}
public string Name
{
get
{
if(!_name.StartsWith("#"))
return _name;
else
{
Language lang = Language.GetByCultureCode(Thread.CurrentThread.CurrentCulture.Name);
if(lang != null)
{
if(Dictionary.DictionaryItem.hasKey(_name.Substring(1, _name.Length - 1)))
{
Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(_name.Substring(1, _name.Length - 1));
return di.Value(lang.id);
}
}
public string Name
{
get
{
if (!_name.StartsWith("#"))
return _name;
else
{
Language lang = Language.GetByCultureCode(Thread.CurrentThread.CurrentCulture.Name);
if (lang != null)
{
if (Dictionary.DictionaryItem.hasKey(_name.Substring(1, _name.Length - 1)))
{
var di = new Dictionary.DictionaryItem(_name.Substring(1, _name.Length - 1));
return di.Value(lang.id);
}
}
return "[" + _name + "]";
}
}
set
{
_name = value;
InvalidateCache();
SqlHelper.ExecuteNonQuery(
"UPDATE cmsPropertyType SET name=@name WHERE id=@id",
return "[" + _name + "]";
}
}
set
{
_name = value;
InvalidateCache();
SqlHelper.ExecuteNonQuery(
"UPDATE cmsPropertyType SET name=@name WHERE id=@id",
SqlHelper.CreateParameter("@name", _name),
SqlHelper.CreateParameter("@id", Id));
}
}
}
}
#endregion
#endregion
#region Methods
#region Methods
public string GetRawName()
{
return _name;
}
public string GetRawDescription() {
public string GetRawName()
{
return _name;
}
public string GetRawDescription()
{
return _description;
}
[MethodImpl(MethodImplOptions.Synchronized)]
public static PropertyType MakeNew(DataTypeDefinition dt, ContentType ct, string name, string alias)
{
public static PropertyType MakeNew(DataTypeDefinition dt, ContentType ct, string name, string alias)
{
//make sure that the alias starts with a letter
if (string.IsNullOrEmpty(alias))
throw new ArgumentNullException("alias");
@@ -256,42 +269,45 @@ namespace umbraco.cms.businesslogic.propertytype
if (!Char.IsLetter(alias[0]))
throw new ArgumentException("alias must start with a letter", "alias");
PropertyType pt;
try
{
PropertyType pt;
try
{
// The method is synchronized, but we'll still look it up with an additional parameter (alias)
SqlHelper.ExecuteNonQuery("INSERT INTO cmsPropertyType (DataTypeId, ContentTypeId, alias, name) VALUES (@DataTypeId, @ContentTypeId, @alias, @name)",
SqlHelper.ExecuteNonQuery(
"INSERT INTO cmsPropertyType (DataTypeId, ContentTypeId, alias, name) VALUES (@DataTypeId, @ContentTypeId, @alias, @name)",
SqlHelper.CreateParameter("@DataTypeId", dt.Id),
SqlHelper.CreateParameter("@ContentTypeId", ct.Id),
SqlHelper.CreateParameter("@alias", alias),
SqlHelper.CreateParameter("@name", name));
pt = new PropertyType(SqlHelper.ExecuteScalar<int>("SELECT MAX(id) FROM cmsPropertyType WHERE alias=@alias",
SqlHelper.CreateParameter("@alias", alias)));
}
finally
{
// Clear cached items
Cache.ClearCacheByKeySearch(UmbracoPropertyTypeCacheKey);
}
pt =
new PropertyType(
SqlHelper.ExecuteScalar<int>("SELECT MAX(id) FROM cmsPropertyType WHERE alias=@alias",
SqlHelper.CreateParameter("@alias", alias)));
}
finally
{
// Clear cached items
Cache.ClearCacheByKeySearch(UmbracoPropertyTypeCacheKey);
}
return pt;
}
return pt;
}
public static PropertyType[] GetAll()
{
List<PropertyType> result = new List<PropertyType>();
using (IRecordsReader dr =
SqlHelper.ExecuteReader("select id, Name from cmsPropertyType order by Name"))
{
while(dr.Read())
{
PropertyType pt = GetPropertyType(dr.GetInt("id"));
if(pt != null)
result.Add(pt);
}
}
public static PropertyType[] GetAll()
{
var result = new List<PropertyType>();
using (IRecordsReader dr =
SqlHelper.ExecuteReader("select id, Name from cmsPropertyType order by Name"))
{
while (dr.Read())
{
PropertyType pt = GetPropertyType(dr.GetInt("id"));
if (pt != null)
result.Add(pt);
}
}
return result.ToArray();
}
}
/// <summary>
/// Returns all property types based on the data type definition
@@ -300,7 +316,7 @@ namespace umbraco.cms.businesslogic.propertytype
/// <returns></returns>
public static IEnumerable<PropertyType> GetByDataTypeDefinition(int dataTypeDefId)
{
List<PropertyType> result = new List<PropertyType>();
var result = new List<PropertyType>();
using (IRecordsReader dr =
SqlHelper.ExecuteReader(
"select id, Name from cmsPropertyType where dataTypeId=@dataTypeId order by Name",
@@ -311,41 +327,55 @@ namespace umbraco.cms.businesslogic.propertytype
PropertyType pt = GetPropertyType(dr.GetInt("id"));
if (pt != null)
result.Add(pt);
}
}
}
return result.ToList();
}
public void delete()
{
public void delete()
{
// flush cache
FlushCache();
// clean all properties on inherited document types (if this propertytype is removed from a master)
cleanPropertiesOnDeletion(_contenttypeid);
// DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentType == _contenttypeid).ForEach(dt => cleanPropertiesOnDeletion(dt.Id));
// DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentType == _contenttypeid).ForEach(dt => cleanPropertiesOnDeletion(dt.Id));
// Delete all properties of propertytype
cleanPropertiesOnDeletion(_contenttypeid);
// Delete PropertyType ..
SqlHelper.ExecuteNonQuery("Delete from cmsPropertyType where id = " + this.Id);
SqlHelper.ExecuteNonQuery("Delete from cmsPropertyType where id = " + Id);
// delete
this.InvalidateCache();
}
// delete cache from either master (via tabid) or current contentype
FlushCacheBasedOnTab();
InvalidateCache();
}
public void FlushCacheBasedOnTab()
{
if (TabId != 0)
{
ContentType.FlushFromCache(ContentType.Tab.GetTab(TabId).ContentType);
}
else
{
ContentType.FlushFromCache(ContentTypeId);
}
}
private void cleanPropertiesOnDeletion(int contentTypeId)
{
// first delete from all master document types
DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentType == contentTypeId).ForEach(dt => cleanPropertiesOnDeletion(dt.Id));
DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentType == contentTypeId).ForEach(
dt => cleanPropertiesOnDeletion(dt.Id));
// then remove from the current doc type
var objs = Content.getContentOfContentType(new ContentType(contentTypeId));
Content[] objs = Content.getContentOfContentType(new ContentType(contentTypeId));
foreach (Content c in objs.ToList())
{
var prop = c.getProperty(this);
Property prop = c.getProperty(this);
if (prop != null)
{
prop.delete();
@@ -353,34 +383,34 @@ namespace umbraco.cms.businesslogic.propertytype
}
// invalidate content type cache
ContentType.GetContentType(contentTypeId).FlushFromCache(contentTypeId);
ContentType.FlushFromCache(contentTypeId);
}
public IDataType GetEditControl(object Value, bool IsPostBack)
{
IDataType dt = this.DataTypeDefinition.DataType;
dt.DataEditor.Editor.ID = this.Alias;
IData df = this.DataTypeDefinition.DataType.Data;
((Control)dt.DataEditor.Editor).ID = this.Alias;
public IDataType GetEditControl(object value, bool isPostBack)
{
IDataType dt = DataTypeDefinition.DataType;
dt.DataEditor.Editor.ID = Alias;
IData df = DataTypeDefinition.DataType.Data;
(dt.DataEditor.Editor).ID = Alias;
if(!IsPostBack)
{
if(Value != null)
dt.Data.Value = Value;
else
dt.Data.Value = "";
}
if (!isPostBack)
{
if (value != null)
dt.Data.Value = value;
else
dt.Data.Value = "";
}
return dt;
}
return dt;
}
/// <summary>
/// Used to persist object changes to the database. In Version3.0 it's just a stub for future compatibility
/// </summary>
public virtual void Save()
{
/// <summary>
/// Used to persist object changes to the database. In Version3.0 it's just a stub for future compatibility
/// </summary>
public virtual void Save()
{
FlushCache();
}
}
protected virtual void FlushCache()
{
@@ -388,40 +418,40 @@ namespace umbraco.cms.businesslogic.propertytype
Cache.ClearCacheItem(GetCacheKey(Id));
// clear cache in contentype
Cache.ClearCacheItem("ContentType_PropertyTypes_Content:" + this._contenttypeid.ToString());
Cache.ClearCacheItem("ContentType_PropertyTypes_Content:" + _contenttypeid);
// clear cache in tab
foreach(umbraco.cms.businesslogic.ContentType.TabI t in new ContentType(ContentTypeId).getVirtualTabs)
foreach (ContentType.TabI t in new ContentType(ContentTypeId).getVirtualTabs)
ContentType.FlushTabCache(t.Id, t.ContentType);
}
public static PropertyType GetPropertyType(int id)
{
return Cache.GetCacheItem<PropertyType>(GetCacheKey(id), propertyTypeCacheSyncLock,
TimeSpan.FromMinutes(30),
delegate
{
try
{
return new PropertyType(id);
}
catch
{
return null;
}
});
}
public static PropertyType GetPropertyType(int id)
{
return Cache.GetCacheItem(GetCacheKey(id), propertyTypeCacheSyncLock,
TimeSpan.FromMinutes(30),
delegate
{
try
{
return new PropertyType(id);
}
catch
{
return null;
}
});
}
private void InvalidateCache()
{
Cache.ClearCacheItem(GetCacheKey(this.Id));
}
private void InvalidateCache()
{
Cache.ClearCacheItem(GetCacheKey(Id));
}
private static string GetCacheKey(int id)
{
return UmbracoPropertyTypeCacheKey + id;
}
private static string GetCacheKey(int id)
{
return UmbracoPropertyTypeCacheKey + id;
}
#endregion
}
}
#endregion
}
}

View File

@@ -55,7 +55,7 @@ namespace umbraco.controls
{
base.OnInit(e);
int docTypeId = int.Parse(Request.QueryString["id"]);
int docTypeId = getDocTypeId();
cType = new cms.businesslogic.ContentType(docTypeId);
setupInfoPane();
@@ -68,6 +68,11 @@ namespace umbraco.controls
}
private int getDocTypeId()
{
return int.Parse(Request.QueryString["id"]);
}
protected void Page_Load(object sender, System.EventArgs e)
{
@@ -109,6 +114,9 @@ namespace umbraco.controls
SaveTabs();
SaveAllowedChildTypes();
// reload content type (due to caching)
cType = new ContentType(cType.Id);
bindDataGenericProperties(true);
// we need to re-bind the alias as the SafeAlias method can have changed it
@@ -554,8 +562,7 @@ jQuery(function() { refreshDropDowns(); });
if (cType.getPropertyType(Casing.SafeAliasWithForcingCheck(gpData.Alias.Trim())) == null)
{
string[] info = { gpData.Name, gpData.Type.ToString() };
cType.AddPropertyType(cms.businesslogic.datatype.DataTypeDefinition.GetDataTypeDefinition(gpData.Type), Casing.SafeAliasWithForcingCheck(gpData.Alias.Trim()), gpData.Name);
cms.businesslogic.propertytype.PropertyType pt = cType.getPropertyType(Casing.SafeAliasWithForcingCheck(gpData.Alias.Trim()));
cms.businesslogic.propertytype.PropertyType pt = cType.AddPropertyType(cms.businesslogic.datatype.DataTypeDefinition.GetDataTypeDefinition(gpData.Type), Casing.SafeAliasWithForcingCheck(gpData.Alias.Trim()), gpData.Name);
pt.Mandatory = gpData.Mandatory;
pt.ValidationRegExp = gpData.Validation;
pt.Description = gpData.Description;

View File

@@ -1,49 +1,43 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using umbraco.BasePages;
namespace umbraco.cms.presentation.developer
{
/// <summary>
/// Summary description for viewCacheItem.
/// </summary>
public partial class viewCacheItem : BasePages.UmbracoEnsuredPage
{
protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Panel1.Text = ui.Text("viewCacheItem");
string cacheKey = Request.QueryString["key"];
LabelCacheAlias.Text = cacheKey;
LabelCacheValue.Text = System.Web.HttpRuntime.Cache[cacheKey].ToString();
}
/// <summary>
/// Summary description for viewCacheItem.
/// </summary>
public partial class viewCacheItem : UmbracoEnsuredPage
{
protected void Page_Load(object sender, EventArgs e)
{
// Put user code to initialize the page here
Panel1.Text = ui.Text("viewCacheItem");
string cacheKey = Request.QueryString["key"];
LabelCacheAlias.Text = cacheKey;
object cacheItem = HttpRuntime.Cache[cacheKey];
LabelCacheValue.Text = cacheItem != null ? cacheItem.ToString() : "Cache item isn't in cache anymore!";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
#region Web Form Designer generated code
}
#endregion
}
}
protected override void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
}
}