protected bool ChangeBranchIfNeeded(IItemData serializedItemData, Item targetItem, bool newItemWasCreated) { if (targetItem.BranchId.Guid.Equals(serializedItemData.BranchId)) { return(false); } Guid oldBranchId = targetItem.BranchId.Guid; targetItem.Editing.BeginEdit(); targetItem.RuntimeSettings.ReadOnlyStatistics = true; targetItem.BranchId = ID.Parse(serializedItemData.BranchId); targetItem.Editing.EndEdit(); ClearCaches(targetItem.Database, targetItem.ID); targetItem.Reload(); if (oldBranchId != serializedItemData.BranchId && !newItemWasCreated) { _logger.ChangedBranchTemplate(targetItem, new ID(oldBranchId).Guid.ToString("P")); return(true); } return(false); }
protected void RenameIfNeeded(IItemData serializedItemData, Item targetItem) { if (targetItem.Name == serializedItemData.Name && targetItem.BranchId.Guid.Equals(serializedItemData.BranchId)) { return; } string oldName = targetItem.Name; Guid oldBranchId = targetItem.BranchId.Guid; using (new EditContext(targetItem)) { targetItem.RuntimeSettings.ReadOnlyStatistics = true; targetItem.Name = serializedItemData.Name; targetItem.BranchId = ID.Parse(serializedItemData.BranchId); } ClearCaches(targetItem.Database, targetItem.ID); targetItem.Reload(); if (oldName != serializedItemData.Name) { _logger.RenamedItem(targetItem, oldName); } if (oldBranchId != serializedItemData.BranchId) { _logger.ChangedBranchTemplate(targetItem, new ID(oldBranchId).ToString()); } }