From f2594248c70e1fc5ba8e724e9b463f2c083296ec Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 18 Jul 2014 18:35:32 +0200 Subject: [PATCH] Add a get_all_rooms helper And expire rooms before entering the admin page --- public/vroom.pl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/public/vroom.pl b/public/vroom.pl index f7837f3..ed6be77 100755 --- a/public/vroom.pl +++ b/public/vroom.pl @@ -401,6 +401,20 @@ helper delete_room => sub { return 1; }; +# Retrieve the list of rooms +helper get_all_rooms => sub { + my $self = shift; + my @rooms; + my $sth = eval { + $self->db->prepare("SELECT `name` FROM `rooms`;"); + } || return undef; + $sth->execute() || return undef; + while (my $name = $sth->fetchrow_array){ + push @rooms, $name; + } + return @rooms; +}; + # Just update the activity timestamp # so we can detect unused rooms helper ping_room => sub { @@ -709,7 +723,10 @@ get '/about' => sub { get '/help' => 'help'; # Route for the admin page -get 'admin' => 'admin'; +get '/admin' => sub { + my $self = shift; + $self->delete_rooms; +} => 'admin'; # Routes for feedback. One get to display the form # and one post to get data from it