From 304e7976bc4477cadcefde0e166d1a922d013b6c Mon Sep 17 00:00:00 2001 From: "agrath@gmail.com" Date: Mon, 4 Jul 2011 15:17:44 -1200 Subject: [PATCH] Detects a null reference exception which occurs when a document type is not transferred properly and cmsPropertyData is missing records and rethrow it with detail about the problem --- .../umbraco/controls/ContentControl.cs | 121 ++++++++++-------- 1 file changed, 65 insertions(+), 56 deletions(-) diff --git a/umbraco/presentation/umbraco/controls/ContentControl.cs b/umbraco/presentation/umbraco/controls/ContentControl.cs index 6487f74757..2c116e3410 100644 --- a/umbraco/presentation/umbraco/controls/ContentControl.cs +++ b/umbraco/presentation/umbraco/controls/ContentControl.cs @@ -33,7 +33,7 @@ namespace umbraco.controls public event EventHandler Save; private publishModes CanPublish = publishModes.NoPublish; public TabPage tpProp; - public bool DoesPublish = false; + public bool DoesPublish = false; public TextBox NameTxt = new TextBox(); public PlaceHolder NameTxtHolder = new PlaceHolder(); public RequiredFieldValidator NameTxtValidator = new RequiredFieldValidator(); @@ -57,21 +57,21 @@ namespace umbraco.controls { } - // zb-00036 #29889 : load it only once - List virtualTabs; + // zb-00036 #29889 : load it only once + List virtualTabs; - /// - /// Constructor to set default properties. - /// - /// - /// - /// - /// - /// This method used to create all of the child controls too which is BAD since - /// the page hasn't started initializing yet. Control IDs were not being named - /// correctly, etc... I've moved the child control setup/creation to the CreateChildControls - /// method where they are suposed to be. - /// + /// + /// Constructor to set default properties. + /// + /// + /// + /// + /// + /// This method used to create all of the child controls too which is BAD since + /// the page hasn't started initializing yet. Control IDs were not being named + /// correctly, etc... I've moved the child control setup/creation to the CreateChildControls + /// method where they are suposed to be. + /// public ContentControl(Content c, publishModes CanPublish, string Id) { ID = Id; @@ -82,12 +82,12 @@ namespace umbraco.controls Height = 350; SaveAndPublish += new EventHandler(standardSaveAndPublishHandler); - Save += new EventHandler(standardSaveAndPublishHandler); - prntpage = (UmbracoEnsuredPage)Page; + Save += new EventHandler(standardSaveAndPublishHandler); + prntpage = (UmbracoEnsuredPage)Page; - // zb-00036 #29889 : load it only once - if (virtualTabs == null) - virtualTabs = _content.ContentType.getVirtualTabs.ToList(); + // zb-00036 #29889 : load it only once + if (virtualTabs == null) + virtualTabs = _content.ContentType.getVirtualTabs.ToList(); foreach (ContentType.TabI t in virtualTabs) { @@ -103,47 +103,56 @@ namespace umbraco.controls { base.CreateChildControls(); - SaveAndPublish += new EventHandler(standardSaveAndPublishHandler); - Save += new EventHandler(standardSaveAndPublishHandler); - prntpage = (UmbracoEnsuredPage)Page; + SaveAndPublish += new EventHandler(standardSaveAndPublishHandler); + Save += new EventHandler(standardSaveAndPublishHandler); + prntpage = (UmbracoEnsuredPage)Page; int i = 0; var inTab = new Hashtable(); - // zb-00036 #29889 : load it only once - if (virtualTabs == null) - virtualTabs = _content.ContentType.getVirtualTabs.ToList(); + // zb-00036 #29889 : load it only once + if (virtualTabs == null) + virtualTabs = _content.ContentType.getVirtualTabs.ToList(); - foreach (ContentType.TabI t in virtualTabs) - { - var tp = this.Panels[i] as TabPage; - if (tp == null) + foreach (ContentType.TabI tab in virtualTabs) + { + var tabPage = this.Panels[i] as TabPage; + if (tabPage == null) { - throw new ArgumentException("Unable to load tab \"" + t.Caption + "\""); + throw new ArgumentException("Unable to load tab \"" + tab.Caption + "\""); } - //TabPage tp = NewTabPage(t.Caption); - //addSaveAndPublishButtons(ref tp); + //TabPage tp = NewTabPage(t.Caption); + //addSaveAndPublishButtons(ref tp); - tp.Style.Add("text-align", "center"); + tabPage.Style.Add("text-align", "center"); - // Iterate through the property types and add them to the tab - // zb-00036 #29889 : fix property types getter to get the right set of properties - foreach (PropertyType pt in t.GetPropertyTypes(_content.ContentType.Id)) - { - // table.Rows.Add(addControl(_content.getProperty(editPropertyType.Alias), tp)); - addControlNew(_content.getProperty(pt), tp, t.Caption); - inTab.Add(pt.Id.ToString(), true); - } + // Iterate through the property types and add them to the tab + // zb-00036 #29889 : fix property types getter to get the right set of properties + // ge : had a bit of a corrupt db and got weird NRE errors so rewrote this to catch the error and rethrow with detail + foreach (PropertyType propertyType in tab.GetPropertyTypes(_content.ContentType.Id)) + { + // table.Rows.Add(addControl(_content.getProperty(editPropertyType.Alias), tp)); + var property = _content.getProperty(propertyType); + if (property != null && tabPage != null) + { + addControlNew(property, tabPage, tab.Caption); + inTab.Add(propertyType.Id.ToString(), true); + } + else + { + throw new ArgumentNullException(string.Format("Property {0} ({1}) on Content Type {2} could not be retrieved for Document {3} on Tab Page {4}. To fix this problem, delete the property and recreate it.", propertyType.Alias, propertyType.Id, _content.ContentType.Alias, _content.Id, tab.Caption)); + } + } i++; - } + } - // Add property pane - tpProp = NewTabPage(ui.Text("general", "properties", null)); - addSaveAndPublishButtons(ref tpProp); - tpProp.Controls.Add( - new LiteralControl("
There were errors - data has not been saved!
")); + // Add property pane + tpProp = NewTabPage(ui.Text("general", "properties", null)); + addSaveAndPublishButtons(ref tpProp); + tpProp.Controls.Add( + new LiteralControl("
There were errors - data has not been saved!
")); //if the property is not in a tab, add it to the general tab var props = _content.GenericProperties; @@ -153,17 +162,17 @@ namespace umbraco.controls addControlNew(p, tpProp, ui.Text("general", "properties", null)); } - } + } - /// - /// Initializes the control and ensures child controls are setup - /// - /// + /// + /// Initializes the control and ensures child controls are setup + /// + /// protected override void OnInit(EventArgs e) { base.OnInit(e); - EnsureChildControls(); + EnsureChildControls(); // Add extras for the property tabpage. . ContentControlLoadEventArgs contentcontrolEvent = new ContentControlLoadEventArgs(); @@ -207,7 +216,7 @@ namespace umbraco.controls } protected override void OnLoad(EventArgs e) - { + { base.OnLoad(e); ContentControlLoadEventArgs contentcontrolEvent = new ContentControlLoadEventArgs();