Don't allow undoing undos

This commit is contained in:
Juerd Waalboer 2022-06-12 04:56:17 +02:00
parent 2371e41f71
commit 8ebe489ade

View file

@ -38,6 +38,8 @@ sub command :Tab(undo) ($self, $cart, $command, @) {
sub tab { @TAB }
my $doing_undo = 0; # Ugly but works, just like the rest of this plugin
sub undo :Tab(&tab) ($self, $cart, $tid, @) {
open my $in, '<', $filename or die "$filename: $!";
open my $out, '>', "$filename.$$" or die "$filename.$$: $!";
@ -61,7 +63,9 @@ sub undo :Tab(&tab) ($self, $cart, $tid, @) {
close $out or die $!;
if ($cart->size) {
rename "$filename.$$", $filename or die $!;
$doing_undo = 1; # don't allow undoing undos
$cart->checkout('-undo');
$doing_undo = 0;
} else {
return ABORT, "Transaction ID '$tid' not found in undo log.";
}
@ -70,6 +74,8 @@ sub undo :Tab(&tab) ($self, $cart, $tid, @) {
}
sub hook_user_balance($class, $username, $old, $delta, $new, $transaction_id, @) {
return if $doing_undo; # don't allow undoing undos
open my $fh, '>>', $filename or die "$filename: $!";
print {$fh} join " ", $transaction_id, $username, -$delta, now(), "\n";
close $fh or die "$filename: $!";