rollbackToVersion method
ENH-96 (withHistory only): re-activates contentVersion — if more
than one history entry shares that version number (same version
re-applied more than once), the most-recently-applied one wins, same
"latest wins" convention currentContentVersion itself uses. Returns
SdkFailure (no mutation) if no history entry matches.
Implementation
Future<SdkResult<T>> rollbackToVersion(int contentVersion) async {
_ensureHistoryLoaded();
final matches = _history
.where((r) => r.contentVersion == contentVersion)
.toList();
if (matches.isEmpty) {
return const SdkFailure(
kind: SdkErrorKind.validation,
message: 'No history entry matches that content version',
);
}
matches.sort((a, b) => a.appliedAtMs.compareTo(b.appliedAtMs));
return _activateHistoryRecord(matches.last);
}