From 03c74296537daad591cb2b4269a74072c41ffe73 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 5 Jul 2017 18:23:51 +1000 Subject: [PATCH] FIxes SQL statement when upgrading with SQLCE and fixes GetAll when passing in an array of ints to ensure that we check if the int array is empty or not --- .../TargetVersionSevenSevenZero/AddUserGroupTables.cs | 11 ++++------- src/Umbraco.Web/Editors/EntityController.cs | 10 ++++++---- src/Umbraco.Web/Models/Mapping/UserModelMapper.cs | 5 ++++- .../Trees/ContentBlueprintTreeController.cs | 7 +++++-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSevenZero/AddUserGroupTables.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSevenZero/AddUserGroupTables.cs index af9805221d..127e1baca5 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSevenZero/AddUserGroupTables.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenSevenZero/AddUserGroupTables.cs @@ -79,13 +79,10 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenSevenZe // Add each user to the group created from their type Execute.Sql(@"INSERT INTO umbracoUser2UserGroup (userId, userGroupId) - SELECT u.id,( - SELECT ug.id - FROM umbracoUserGroup ug - INNER JOIN umbracoUserType ut ON ut.userTypeAlias = ug.userGroupAlias - WHERE u.userType = ut.id - ) - FROM umbracoUser u"); + SELECT u.id, ug.id + FROM umbracoUser u + INNER JOIN umbracoUserType ut ON ut.id = u.userType + INNER JOIN umbracoUserGroup ug ON ug.userGroupAlias = ut.userTypeAlias"); // Add the built-in administrator account to all apps Execute.Sql(@"INSERT INTO umbracoUserGroup2app (userGroupId,app) diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index 119a7e7ed0..37d712c362 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -918,10 +918,12 @@ namespace Umbraco.Web.Editors var ids = Services.EntityService.Get(id).Path.Split(',').Select(int.Parse).Distinct().ToArray(); - return Services.EntityService.GetAll(objectType.Value, ids) - .WhereNotNull() - .OrderBy(x => x.Level) - .Select(Mapper.Map); + return ids.Length == 0 + ? Enumerable.Empty() + : Services.EntityService.GetAll(objectType.Value, ids) + .WhereNotNull() + .OrderBy(x => x.Level) + .Select(Mapper.Map); } //now we need to convert the unknown ones switch (entityType) diff --git a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs index 95dd27845c..8bcae0df8b 100644 --- a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs @@ -194,8 +194,11 @@ namespace Umbraco.Web.Models.Mapping var allContentPermissions = applicationContext.Services.UserService.GetPermissions(group, true) .ToDictionary(x => x.EntityId, x => x); + + var contentEntities = allContentPermissions.Keys.Count == 0 + ? new IUmbracoEntity[0] + : applicationContext.Services.EntityService.GetAll(UmbracoObjectTypes.Document, allContentPermissions.Keys.ToArray()); - var contentEntities = applicationContext.Services.EntityService.GetAll(UmbracoObjectTypes.Document, allContentPermissions.Keys.ToArray()); var allAssignedPermissions = new List(); foreach (var entity in contentEntities) { diff --git a/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs b/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs index ff029a020a..8c9f40493e 100644 --- a/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs @@ -45,9 +45,12 @@ namespace Umbraco.Web.Trees //get all blueprint content types var contentTypeAliases = entities.Select(x => ((UmbracoEntity) x).ContentTypeAlias).Distinct(); //get the ids - var contentTypeIds = Services.ContentTypeService.GetAllContentTypeIds(contentTypeAliases.ToArray()); + var contentTypeIds = Services.ContentTypeService.GetAllContentTypeIds(contentTypeAliases.ToArray()).ToArray(); + //now get the entities ... it's a bit round about but still smaller queries than getting all document types - var docTypeEntities = Services.EntityService.GetAll(UmbracoObjectTypes.DocumentType, contentTypeIds.ToArray()).ToArray(); + var docTypeEntities = contentTypeIds.Length == 0 + ? new IUmbracoEntity[0] + : Services.EntityService.GetAll(UmbracoObjectTypes.DocumentType, contentTypeIds).ToArray(); nodes.AddRange(docTypeEntities .Select(entity =>