From 9334f55fa6964b055e87efbf1e1943fc238d319e Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 20 Dec 2012 16:20:56 -0100 Subject: [PATCH] When trying to query the umbracoApp table, check if it exists first In the package installer, after creating a docType, also save it (now required) In DocumentType, use the whole contentType to new-up a docType and check if the allowedtemplate isn't null Properties can have empty strings as values, can't convert those to int/datetime Seperator character in ExpressionHelper was string.Empty, got malformed queries --- .../Persistence/Factories/PropertyFactory.cs | 4 +-- .../Persistence/Querying/ExpressionHelper.cs | 2 +- .../ApplicationRegistrar.cs | 30 +++++++++++-------- .../businesslogic/Packager/Installer.cs | 1 + .../businesslogic/web/DocumentType.cs | 11 +++---- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs index 93d137d1b1..789646df2d 100644 --- a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs @@ -54,11 +54,11 @@ namespace Umbraco.Core.Persistence.Factories if (property.HasIdentity) dto.Id = property.Id; - if (property.DataTypeDatabaseType == DataTypeDatabaseType.Integer && property.Value != null) + if (property.DataTypeDatabaseType == DataTypeDatabaseType.Integer && property.Value != null && string.IsNullOrWhiteSpace(property.Value.ToString()) == false) { dto.Integer = int.Parse(property.Value.ToString()); } - else if (property.DataTypeDatabaseType == DataTypeDatabaseType.Date && property.Value != null) + else if (property.DataTypeDatabaseType == DataTypeDatabaseType.Date && property.Value != null && string.IsNullOrWhiteSpace(property.Value.ToString()) == false) { dto.Date = DateTime.Parse(property.Value.ToString()); } diff --git a/src/Umbraco.Core/Persistence/Querying/ExpressionHelper.cs b/src/Umbraco.Core/Persistence/Querying/ExpressionHelper.cs index 72e785e8b3..48d9731149 100644 --- a/src/Umbraco.Core/Persistence/Querying/ExpressionHelper.cs +++ b/src/Umbraco.Core/Persistence/Querying/ExpressionHelper.cs @@ -21,7 +21,7 @@ namespace Umbraco.Core.Persistence.Querying IList updateFields = new List(); IList insertFields = new List(); - private string sep = string.Empty; + private string sep = " "; private bool useFieldName = false; private Database.PocoData pd; diff --git a/src/umbraco.businesslogic/ApplicationRegistrar.cs b/src/umbraco.businesslogic/ApplicationRegistrar.cs index 2432ad783c..12e53a38eb 100644 --- a/src/umbraco.businesslogic/ApplicationRegistrar.cs +++ b/src/umbraco.businesslogic/ApplicationRegistrar.cs @@ -3,6 +3,7 @@ using System.Data.SqlClient; using System.Linq; using System.Xml.Linq; using Umbraco.Core; +using Umbraco.Core.Persistence; using umbraco.BusinessLogic.Utils; using umbraco.DataLayer; using umbraco.businesslogic; @@ -58,20 +59,25 @@ namespace umbraco.BusinessLogic new XAttribute("icon", attr.Icon), new XAttribute("sortOrder", attr.SortOrder))); } - - var dbApps = SqlHelper.ExecuteReader("SELECT * FROM umbracoApp WHERE appAlias NOT IN (" + inString + ")"); - while (dbApps.Read()) - { - doc.Root.Add(new XElement("add", - new XAttribute("alias", dbApps.GetString("appAlias")), - new XAttribute("name", dbApps.GetString("appName")), - new XAttribute("icon", dbApps.GetString("appIcon")), - new XAttribute("sortOrder", dbApps.GetByte("sortOrder")))); - } - + + var db = ApplicationContext.Current.DatabaseContext.Database; + var exist = db.TableExist("umbracoApp"); + if (exist) + { + var dbApps = SqlHelper.ExecuteReader("SELECT * FROM umbracoApp WHERE appAlias NOT IN (" + inString + ")"); + while (dbApps.Read()) + { + doc.Root.Add(new XElement("add", + new XAttribute("alias", dbApps.GetString("appAlias")), + new XAttribute("name", dbApps.GetString("appName")), + new XAttribute("icon", dbApps.GetString("appIcon")), + new XAttribute("sortOrder", dbApps.GetByte("sortOrder")))); + } + } }, true); - + + //TODO Shouldn't this be enabled and then delete the whole table? //SqlHelper.ExecuteNonQuery("DELETE FROM umbracoApp"); } } diff --git a/src/umbraco.cms/businesslogic/Packager/Installer.cs b/src/umbraco.cms/businesslogic/Packager/Installer.cs index f5a0b26563..4c18d9cb5a 100644 --- a/src/umbraco.cms/businesslogic/Packager/Installer.cs +++ b/src/umbraco.cms/businesslogic/Packager/Installer.cs @@ -856,6 +856,7 @@ namespace umbraco.cms.businesslogic.packager foreach (DocumentType.TabI t in dt.getVirtualTabs.ToList()) DocumentType.FlushTabCache(t.Id, dt.Id); + dt.Save(); } /// diff --git a/src/umbraco.cms/businesslogic/web/DocumentType.cs b/src/umbraco.cms/businesslogic/web/DocumentType.cs index c203a81b63..13dd7cbf40 100644 --- a/src/umbraco.cms/businesslogic/web/DocumentType.cs +++ b/src/umbraco.cms/businesslogic/web/DocumentType.cs @@ -29,7 +29,8 @@ namespace umbraco.cms.businesslogic.web public DocumentType(int id, bool noSetup) : base(id, noSetup) { } - internal DocumentType(IContentType contentType) : base(contentType) + internal DocumentType(IContentType contentType) + : base(contentType) { SetupNode(contentType); } @@ -123,7 +124,7 @@ namespace umbraco.cms.businesslogic.web return dtd.ToString(); } - + [Obsolete("Deprecated, Use Umbraco.Core.Services.ContentTypeService.GetContentType()", false)] public new static DocumentType GetByAlias(string Alias) { @@ -143,7 +144,7 @@ namespace umbraco.cms.businesslogic.web { var contentType = new Umbraco.Core.Models.ContentType(-1) { Name = Text, Alias = Text, CreatorId = u.Id, Thumbnail = "folder.png", Icon = "folder.gif" }; ApplicationContext.Current.Services.ContentTypeService.Save(contentType, u.Id); - var newDt = new DocumentType(contentType.Id); + var newDt = new DocumentType(contentType); //event NewEventArgs e = new NewEventArgs(); @@ -459,7 +460,7 @@ namespace umbraco.cms.businesslogic.web _defaultTemplate = 0; var template = _contentType.DefaultTemplate; - if(template != null) + if (template != null) _contentType.RemoveTemplate(template); //SqlHelper.ExecuteNonQuery("update cmsDocumentType set IsDefault = 0 where contentTypeNodeId = " + Id.ToString()); @@ -531,7 +532,7 @@ namespace umbraco.cms.businesslogic.web private void SetupNode(IContentType contentType) { _contentType = contentType; - foreach (var template in _contentType.AllowedTemplates) + foreach (var template in _contentType.AllowedTemplates.Where(t => t != null)) { _templateIds.Add(template.Id); }