Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/Umbraco.Core/Events/MoveEventInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ public class MoveEventInfo<TEntity> : MoveEventInfoBase<TEntity>
/// <param name="originalPath">The original path of the entity.</param>
/// <param name="newParentId">The identifier of the new parent.</param>
/// <param name="newParentKey">The unique identifier of the new parent.</param>
[Obsolete("Use the overload without the newParentId parameter instead. Scheduled for removal in v19.")]
public MoveEventInfo(TEntity entity, string originalPath, int newParentId, Guid? newParentKey)
: base(entity, originalPath)
: this(entity, originalPath, newParentKey)
{
NewParentId = newParentId;
NewParentKey = newParentKey;
}

/// <summary>
Expand All @@ -26,15 +25,23 @@ public MoveEventInfo(TEntity entity, string originalPath, int newParentId, Guid?
/// <param name="entity">The entity being moved.</param>
/// <param name="originalPath">The original path of the entity.</param>
/// <param name="newParentId">The identifier of the new parent.</param>
public MoveEventInfo(TEntity entity, string originalPath, int newParentId) : this(entity, originalPath, newParentId, null)
[Obsolete("Use the overload with the newParentKey parameter instead. Scheduled for removal in v19.")]
public MoveEventInfo(TEntity entity, string originalPath, int newParentId)
Comment thread
AndyButland marked this conversation as resolved.
: this(entity, originalPath, null)
{
}

/// <summary>
/// Gets or sets the identifier of the new parent.
/// Initializes a new instance of the <see cref="MoveEventInfo{TEntity}" /> class.
/// </summary>
[Obsolete("Please use NewParentKey instead. Scheduled for removal in Umbraco 18.")]
public int NewParentId { get; set; }
/// <param name="entity">The entity being moved.</param>
/// <param name="originalPath">The original path of the entity.</param>
/// <param name="newParentKey">The unique identifier of the new parent.</param>
public MoveEventInfo(TEntity entity, string originalPath, Guid? newParentKey)
: base(entity, originalPath)
{
NewParentKey = newParentKey;
}

/// <summary>
/// Gets the unique identifier of the new parent.
Expand All @@ -57,7 +64,7 @@ public MoveEventInfo(TEntity entity, string originalPath, int newParentId) : thi
/// </summary>
/// <param name="other">The other instance to compare.</param>
/// <returns><c>true</c> if the instances are equal; otherwise, <c>false</c>.</returns>
public bool Equals(MoveEventInfo<TEntity>? other) => NewParentId == other?.NewParentId && NewParentKey == other.NewParentKey && base.Equals(other);
public bool Equals(MoveEventInfo<TEntity>? other) => NewParentKey == other?.NewParentKey && base.Equals(other);

/// <inheritdoc />
public override int GetHashCode()
Expand All @@ -67,7 +74,7 @@ public override int GetHashCode()
var hashCode = Entity is not null
? EqualityComparer<TEntity>.Default.GetHashCode(Entity)
: base.GetHashCode();
hashCode = (hashCode * 397) ^ NewParentId;
hashCode = (hashCode * 397) ^ NewParentKey.GetHashCode();
hashCode = (hashCode * 397) ^ OriginalPath.GetHashCode();
return hashCode;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Umbraco.Core/Services/ContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ public OperationResult Move(IContent content, int parentId, int userId = Constan
}

TryGetParentKey(parentId, out Guid? parentKey);
var moveEventInfo = new MoveEventInfo<IContent>(content, content.Path, parentId, parentKey);
var moveEventInfo = new MoveEventInfo<IContent>(content, content.Path, parentKey);

var movingNotification = new ContentMovingNotification(moveEventInfo, eventMessages);
if (scope.Notifications.PublishCancelable(movingNotification))
Expand Down Expand Up @@ -1226,7 +1226,7 @@ public OperationResult Move(IContent content, int parentId, int userId = Constan
.Select(x =>
{
TryGetParentKey(x.Item1.ParentId, out Guid? itemParentKey);
return new MoveEventInfo<IContent>(x.Item1, x.Item2, x.Item1.ParentId, itemParentKey);
return new MoveEventInfo<IContent>(x.Item1, x.Item2, itemParentKey);
})
.ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ public void Delete(IEnumerable<TItem> items, int userId = Constants.Security.Sup
var moveInfo = new List<MoveEventInfo<TItem>>();
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
{
var moveEventInfo = new MoveEventInfo<TItem>(toMove, toMove.Path, containerId.Value);
var moveEventInfo = new MoveEventInfo<TItem>(toMove, toMove.Path, containerKey);
MovingNotification<TItem> movingNotification = GetMovingNotification(moveEventInfo, eventMessages);
if (scope.Notifications.PublishCancelable(movingNotification))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Umbraco.Core/Services/DataTypeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public async Task<Attempt<IDataType, DataTypeOperationStatus>> MoveAsync(IDataTy
return Attempt.SucceedWithStatus(DataTypeOperationStatus.Success, toMove);
}

var moveEventInfo = new MoveEventInfo<IDataType>(toMove, toMove.Path, parentId, containerKey);
var moveEventInfo = new MoveEventInfo<IDataType>(toMove, toMove.Path, containerKey);
var movingDataTypeNotification = new DataTypeMovingNotification(moveEventInfo, eventMessages);
if (scope.Notifications.PublishCancelable(movingDataTypeNotification))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Umbraco.Core/Services/DictionaryItemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
dictionaryItem.ParentId = parentId;

EventMessages eventMessages = EventMessagesFactory.Get();
var moveEventInfo = new MoveEventInfo<IDictionaryItem>(dictionaryItem, string.Empty, parent?.Id ?? Constants.System.Root, parentId);
var moveEventInfo = new MoveEventInfo<IDictionaryItem>(dictionaryItem, string.Empty, parentId);

Check notice on line 297 in src/Umbraco.Core/Services/DictionaryItemService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (v18/dev)

✅ Getting better: Complex Method

MoveAsync decreases in cyclomatic complexity from 10 to 9, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
var movingNotification = new DictionaryItemMovingNotification(moveEventInfo, eventMessages);
if (await scope.Notifications.PublishCancelableAsync(movingNotification))
{
Expand Down
4 changes: 2 additions & 2 deletions src/Umbraco.Core/Services/ElementContainerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ private async Task<Attempt<EntityContainerOperationStatus>> HandleMoveAsync(
: EntityContainerOperationStatus.Success,
(cont, eventMessages) =>
{
var moveEventInfo = new MoveEventInfo<EntityContainer>(cont, originalPath, parentId, parentKey);
var moveEventInfo = new MoveEventInfo<EntityContainer>(cont, originalPath, parentKey);
return new EntityContainerMovingNotification(moveEventInfo, eventMessages);
},
(cont, eventMessages) =>
{
var moveEventInfo = new MoveEventInfo<EntityContainer>(cont, originalPath, parentId, parentKey);
var moveEventInfo = new MoveEventInfo<EntityContainer>(cont, originalPath, parentKey);
return new EntityContainerMovedNotification(moveEventInfo, eventMessages);
});

Expand Down
4 changes: 2 additions & 2 deletions src/Umbraco.Core/Services/ElementEditingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,12 @@ private async Task<Attempt<ContentEditingOperationStatus>> HandleElementMoveAsyn
userKey,
(elem, eventMessages) =>
{
var moveEventInfo = new MoveEventInfo<IElement>(elem, originalPath, parentId, containerKey);
var moveEventInfo = new MoveEventInfo<IElement>(elem, originalPath, containerKey);
return new ElementMovingNotification(moveEventInfo, eventMessages);
},
(elem, eventMessages) =>
{
var moveEventInfo = new MoveEventInfo<IElement>(elem, originalPath, parentId, containerKey);
var moveEventInfo = new MoveEventInfo<IElement>(elem, originalPath, containerKey);
return new ElementMovedNotification(moveEventInfo, eventMessages);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public IEnumerable<MoveEventInfo<TEntity>> Move(TEntity moving, EntityContainer?
}

// track moved entities
var moveInfo = new List<MoveEventInfo<TEntity>> { new(moving, moving.Path, parentId, parentKey) };
var moveInfo = new List<MoveEventInfo<TEntity>> { new(moving, moving.Path, parentKey) };

// get the level delta (old pos to new pos)
var levelDelta = container == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,27 @@
[Test]
public void Can_Equate_Move_Event_Infos_Parent_Key_Null()
{
var moveEvent = new MoveEventInfo<string>("entity", "path", 123, null);
var moveEventTwo = new MoveEventInfo<string>("entity", "path", 123, null);
var moveEvent = new MoveEventInfo<string>("entity", "path", null);
var moveEventTwo = new MoveEventInfo<string>("entity", "path", null);
Assert.IsTrue(moveEvent.Equals(moveEventTwo));
}

[Test]
public void Can_Equate_Move_Event_Infos_All_Params_Null_Or_Empty()
{
var moveEvent = new MoveEventInfo<string>(string.Empty, string.Empty, 0, null);
var moveEventTwo = new MoveEventInfo<string>(string.Empty, string.Empty, 0, null);
var moveEvent = new MoveEventInfo<string>(string.Empty, string.Empty, null);
var moveEventTwo = new MoveEventInfo<string>(string.Empty, string.Empty, null);
Assert.IsTrue(moveEvent.Equals(moveEventTwo));
}

[TestCase(123, "entity", "", "063897F1-194A-4C42-B406-CA80DBC12968", false)]
[TestCase(123, "", "path", "063897F1-194A-4C42-B406-CA80DBC12968", false)]
[TestCase(12, "entity", "path", "063897F1-194A-4C42-B406-CA80DBC12968", false)]
[TestCase(123, "entity", "path", "C6D6EA3E-C2B0-483F-B772-2F4D8BBF5027", false)]
[TestCase(123, "entity", "path", "063897F1-194A-4C42-B406-CA80DBC12968", true)]
public void Can_Equate_Move_Event_Infos(int parentId, string entity, string originalPath, Guid parentKey, bool expectedResult)
[TestCase("entity", "", "063897F1-194A-4C42-B406-CA80DBC12968", false)]
[TestCase("", "path", "063897F1-194A-4C42-B406-CA80DBC12968", false)]
[TestCase("entity", "path", "C6D6EA3E-C2B0-483F-B772-2F4D8BBF5027", false)]
[TestCase("entity", "path", "063897F1-194A-4C42-B406-CA80DBC12968", true)]
public void Can_Equate_Move_Event_Infos(string entity, string originalPath, Guid parentKey, bool expectedResult)
{
var moveEvent = new MoveEventInfo<string>(entity, originalPath, parentId, parentKey);
var moveEventTwo = new MoveEventInfo<string>("entity", "path", 123, new Guid("063897F1-194A-4C42-B406-CA80DBC12968"));
var moveEvent = new MoveEventInfo<string>(entity, originalPath, parentKey);
var moveEventTwo = new MoveEventInfo<string>("entity", "path", new Guid("063897F1-194A-4C42-B406-CA80DBC12968"));

Check notice on line 51 in tests/Umbraco.Tests.UnitTests/Umbraco.Core/Events/MoveEventInfoTests.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (v18/dev)

✅ No longer an issue: Excess Number of Function Arguments

Can_Equate_Move_Event_Infos is no longer above the threshold for number of arguments
Assert.AreEqual(expectedResult, moveEvent.Equals(moveEventTwo));
}
}
Loading