refactor(core): delegate Rollback to VersionOperationService

Part of ContentService refactoring Phase 3.
Notification ordering preserved: RollingBack -> RolledBack.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-23 04:01:37 +00:00
parent 651f6c5241
commit 026d074819

View File

@@ -269,61 +269,7 @@ public class ContentService : RepositoryService, IContentService
#region Rollback
public OperationResult Rollback(int id, int versionId, string culture = "*", int userId = Constants.Security.SuperUserId)
{
EventMessages evtMsgs = EventMessagesFactory.Get();
// Get the current copy of the node
IContent? content = GetById(id);
// Get the version
IContent? version = GetVersion(versionId);
// Good old null checks
if (content == null || version == null || content.Trashed)
{
return new OperationResult(OperationResultType.FailedCannot, evtMsgs);
}
// Store the result of doing the save of content for the rollback
OperationResult rollbackSaveResult;
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
{
var rollingBackNotification = new ContentRollingBackNotification(content, evtMsgs);
if (scope.Notifications.PublishCancelable(rollingBackNotification))
{
scope.Complete();
return OperationResult.Cancel(evtMsgs);
}
// Copy the changes from the version
content.CopyFrom(version, culture);
// Save the content for the rollback
rollbackSaveResult = Save(content, userId);
// Depending on the save result - is what we log & audit along with what we return
if (rollbackSaveResult.Success == false)
{
// Log the error/warning
_logger.LogError(
"User '{UserId}' was unable to rollback content '{ContentId}' to version '{VersionId}'", userId, id, versionId);
}
else
{
scope.Notifications.Publish(
new ContentRolledBackNotification(content, evtMsgs).WithStateFrom(rollingBackNotification));
// Logging & Audit message
_logger.LogInformation("User '{UserId}' rolled back content '{ContentId}' to version '{VersionId}'", userId, id, versionId);
Audit(AuditType.RollBack, userId, id, $"Content '{content.Name}' was rolled back to version '{versionId}'");
}
scope.Complete();
}
return rollbackSaveResult;
}
=> VersionOperationService.Rollback(id, versionId, culture, userId);
#endregion