summaryrefslogtreecommitdiff
path: root/index.pl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-02-15 19:29:57 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-02-15 19:29:57 +0100
commitaf1e1a8294abce86371dc67fe494ffdd01fefa05 (patch)
tree122150c0b202bf752c0476c8777c9ad48a5175a8 /index.pl
parent130d598a9e0ddb2283a14d54a99d2327c458f975 (diff)
checkin: ensure that users are checked out first
Diffstat (limited to 'index.pl')
-rwxr-xr-xindex.pl16
1 files changed, 16 insertions, 0 deletions
diff --git a/index.pl b/index.pl
index 176f4f5..89555cd 100755
--- a/index.pl
+++ b/index.pl
@@ -264,6 +264,22 @@ helper 'checkin' => sub {
return ( undef, "Train ${train_id} not found" );
}
else {
+
+ my $user = $self->get_user_status;
+ if ( $user->{checked_in} ) {
+
+ # If a user is already checked in, we assume that they forgot to
+ # check out and do it for them.
+ # XXX this is an ugly workaround for the UNIQUE constraint on
+ # (user id, action timestamp): Ensure that checkout and re-checkin
+ # work even if the previous checkin was less than a second ago.
+ sleep(1);
+ $self->checkout( $station, 1 );
+
+ # XXX same workaround: We can't checkin immediately after checkout.
+ sleep(1);
+ }
+
my $success = $self->app->checkin_query->execute(
$self->get_user_id,
$self->get_station_id(