From 762cca145fbcb8a6b0b62d0f534573b58e63f7d2 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Fri, 22 Mar 2013 21:59:21 +0600 Subject: [PATCH] Fixes: #U4-1931 - allow empty string in dictionary item. --- .../settings/EditDictionaryItem.aspx.cs | 8 ++- src/umbraco.cms/businesslogic/Dictionary.cs | 56 ++++++++----------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs index 20b406281d..fbc579d8f4 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs @@ -88,8 +88,12 @@ namespace umbraco.settings private void save_click(object sender, System.Web.UI.ImageClickEventArgs e) { - foreach (TextBox t in languageFields) { - if (t.Text != "") { + foreach (TextBox t in languageFields) + { + //check for null but allow empty string! + // http://issues.umbraco.org/issue/U4-1931 + if (t.Text != null) + { currentItem.setValue(int.Parse(t.ID),t.Text); } } diff --git a/src/umbraco.cms/businesslogic/Dictionary.cs b/src/umbraco.cms/businesslogic/Dictionary.cs index 80646d9f65..a7e9ab0de7 100644 --- a/src/umbraco.cms/businesslogic/Dictionary.cs +++ b/src/umbraco.cms/businesslogic/Dictionary.cs @@ -17,10 +17,10 @@ namespace umbraco.cms.businesslogic /// public class Dictionary { - private static volatile bool cacheIsEnsured = false; - private static readonly object m_Locker = new object(); - private static Hashtable DictionaryItems = Hashtable.Synchronized(new Hashtable()); - private static Guid topLevelParent = new Guid("41c7638d-f529-4bff-853e-59a0c2fb1bde"); + private static volatile bool _cacheIsEnsured = false; + private static readonly object Locker = new object(); + private static readonly Hashtable DictionaryItems = Hashtable.Synchronized(new Hashtable()); + private static readonly Guid TopLevelParent = new Guid("41c7638d-f529-4bff-853e-59a0c2fb1bde"); protected static ISqlHelper SqlHelper { @@ -30,13 +30,13 @@ namespace umbraco.cms.businesslogic /// /// Reads all items from the database and stores in local cache /// - private static void ensureCache() + private static void EnsureCache() { - if (!cacheIsEnsured) + if (!_cacheIsEnsured) { - lock (m_Locker) + lock (Locker) { - if (!cacheIsEnsured) + if (!_cacheIsEnsured) { using (IRecordsReader dr = SqlHelper.ExecuteReader("Select pk, id, [key], parent from cmsDictionary")) { @@ -55,7 +55,7 @@ namespace umbraco.cms.businesslogic } } - cacheIsEnsured = true; + _cacheIsEnsured = true; } } } @@ -68,10 +68,10 @@ namespace umbraco.cms.businesslogic { get { - ensureCache(); + EnsureCache(); return DictionaryItems.Values.Cast() - .Where(x => x.ParentId == topLevelParent).OrderBy(item => item.key) + .Where(x => x.ParentId == TopLevelParent).OrderBy(item => item.key) .ToArray(); } } @@ -105,11 +105,9 @@ namespace umbraco.cms.businesslogic public DictionaryItem(string key) { - ensureCache(); + EnsureCache(); - var item = DictionaryItems.Values.Cast() - .Where(x => x.key == key) - .SingleOrDefault(); + var item = DictionaryItems.Values.Cast().SingleOrDefault(x => x.key == key); if (item == null) { @@ -124,11 +122,9 @@ namespace umbraco.cms.businesslogic public DictionaryItem(Guid id) { - ensureCache(); + EnsureCache(); - var item = DictionaryItems.Values.Cast() - .Where(x => x.UniqueId == id) - .SingleOrDefault(); + var item = DictionaryItems.Values.Cast().SingleOrDefault(x => x.UniqueId == id); if (item == null) { @@ -143,11 +139,9 @@ namespace umbraco.cms.businesslogic public DictionaryItem(int id) { - ensureCache(); + EnsureCache(); - var item = DictionaryItems.Values.Cast() - .Where(x => x.id == id) - .SingleOrDefault(); + var item = DictionaryItems.Values.Cast().SingleOrDefault(x => x.id == id); if (item == null) { @@ -170,7 +164,7 @@ namespace umbraco.cms.businesslogic return DictionaryItems.Values.Cast() .Where(x => x.id == id) .Select(x => x.ParentId) - .SingleOrDefault() == topLevelParent; + .SingleOrDefault() == TopLevelParent; } /// @@ -182,9 +176,7 @@ namespace umbraco.cms.businesslogic { if (_parent == null) { - var p = DictionaryItems.Values.Cast() - .Where(x => x.UniqueId == this.ParentId) - .SingleOrDefault(); + var p = DictionaryItems.Values.Cast().SingleOrDefault(x => x.UniqueId == this.ParentId); if (p == null) { @@ -221,7 +213,7 @@ namespace umbraco.cms.businesslogic public static bool hasKey(string key) { - ensureCache(); + EnsureCache(); return DictionaryItems.ContainsKey(key); } @@ -243,7 +235,7 @@ namespace umbraco.cms.businesslogic { if (!hasKey(value)) { - lock (m_Locker) + lock (Locker) { SqlHelper.ExecuteNonQuery("Update cmsDictionary set [key] = @key WHERE pk = @Id", SqlHelper.CreateParameter("@key", value), SqlHelper.CreateParameter("@Id", id)); @@ -329,7 +321,7 @@ namespace umbraco.cms.businesslogic public static int addKey(string key, string defaultValue, string parentKey) { - ensureCache(); + EnsureCache(); if (hasKey(parentKey)) { @@ -342,8 +334,8 @@ namespace umbraco.cms.businesslogic public static int addKey(string key, string defaultValue) { - ensureCache(); - int retval = createKey(key, topLevelParent, defaultValue); + EnsureCache(); + int retval = createKey(key, TopLevelParent, defaultValue); return retval; }