Bump version to 4.0.0; change transaction ID scheme

This commit is contained in:
Juerd Waalboer 2023-09-20 20:14:04 +02:00
parent e613ff28e6
commit 560242a4bc
4 changed files with 165 additions and 12 deletions

View file

@ -93,7 +93,20 @@ sub checkout($self, $user) {
}
RevBank::FileIO::with_lock {
my $transaction_id = time() - 1300000000;
my $fn = ".revbank.nextid";
my $transaction_id = eval { RevBank::FileIO::slurp($fn) };
my $legacy_id = 0;
if (defined $transaction_id) {
chomp $transaction_id;
if ($transaction_id eq "LEGACY") {
$legacy_id = 1;
$transaction_id = time() - 1300000000;;
}
} else {
warn "Could not read $fn; using timestamp as first transaction ID.\n";
$transaction_id = time() - 1300000000;
}
RevBank::Plugins::call_hooks("checkout_prepare", $self, $user, $transaction_id);
for my $entry (@$entries) {
@ -101,6 +114,8 @@ sub checkout($self, $user) {
$entry->user($user) if not $entry->user;
}
RevBank::FileIO::spurt($fn, ++(my $next_id = $transaction_id)) unless $legacy_id;
RevBank::Plugins::call_hooks("checkout", $self, $user, $transaction_id);
my %deltas = ($user => RevBank::Amount->new(0));