Allows for passing in an Unknown object type to the IEntityService.GetIdForKey and GetKeyForId methods

This commit is contained in:
Shannon
2018-01-15 18:05:52 +11:00
parent b3cbcebf5b
commit fef743517f
2 changed files with 40 additions and 4 deletions

View File

@@ -39,8 +39,16 @@ namespace Umbraco.Core.Services
int? val;
using (var uow = _uowProvider.GetUnitOfWork())
{
val = uow.Database.ExecuteScalar<int?>("SELECT id FROM umbracoNode WHERE uniqueId=@id AND (nodeObjectType=@type OR nodeObjectType=@reservation)",
new { id = key, type = GetNodeObjectTypeGuid(umbracoObjectType), reservation = Constants.ObjectTypes.IdReservationGuid });
//if it's unknown don't include the nodeObjectType in the query
if (umbracoObjectType == UmbracoObjectTypes.Unknown)
{
val = uow.Database.ExecuteScalar<int?>("SELECT id FROM umbracoNode WHERE uniqueId=@id", new { id = key});
}
else
{
val = uow.Database.ExecuteScalar<int?>("SELECT id FROM umbracoNode WHERE uniqueId=@id AND (nodeObjectType=@type OR nodeObjectType=@reservation)",
new { id = key, type = GetNodeObjectTypeGuid(umbracoObjectType), reservation = Constants.ObjectTypes.IdReservationGuid });
}
uow.Commit();
}
@@ -92,8 +100,16 @@ namespace Umbraco.Core.Services
Guid? val;
using (var uow = _uowProvider.GetUnitOfWork())
{
val = uow.Database.ExecuteScalar<Guid?>("SELECT uniqueId FROM umbracoNode WHERE id=@id AND (nodeObjectType=@type OR nodeObjectType=@reservation)",
new { id, type = GetNodeObjectTypeGuid(umbracoObjectType), reservation = Constants.ObjectTypes.IdReservationGuid });
//if it's unknown don't include the nodeObjectType in the query
if (umbracoObjectType == UmbracoObjectTypes.Unknown)
{
val = uow.Database.ExecuteScalar<Guid?>("SELECT uniqueId FROM umbracoNode WHERE id=@id", new { id });
}
else
{
val = uow.Database.ExecuteScalar<Guid?>("SELECT uniqueId FROM umbracoNode WHERE id=@id AND (nodeObjectType=@type OR nodeObjectType=@reservation)",
new { id, type = GetNodeObjectTypeGuid(umbracoObjectType), reservation = Constants.ObjectTypes.IdReservationGuid });
}
uow.Commit();
}

View File

@@ -533,6 +533,16 @@ namespace Umbraco.Tests.Services
Assert.AreEqual(mediaObjectType, UmbracoObjectTypes.MediaType);
}
[Test]
public void EntityService_Can_Get_Key_For_Id_With_Unknown_Type()
{
var service = ServiceContext.EntityService;
var result = service.GetKeyForId(1060, UmbracoObjectTypes.Unknown);
Assert.IsTrue(result.Success);
Assert.AreEqual(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), result.Result);
}
[Test]
public void EntityService_Can_Get_Key_For_Id()
{
@@ -554,6 +564,16 @@ namespace Umbraco.Tests.Services
Assert.IsFalse(result2.Success);
}
[Test]
public void EntityService_Can_Get_Id_For_Key_With_Unknown_Type()
{
var service = ServiceContext.EntityService;
var result = service.GetIdForKey(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.Unknown);
Assert.IsTrue(result.Success);
Assert.AreEqual(1060, result.Result);
}
[Test]
public void EntityService_Can_Get_Id_For_Key()
{