diff --git a/lib/Vroom/I18N/en.pm b/lib/Vroom/I18N/en.pm index b7266fd..a75d87d 100644 --- a/lib/Vroom/I18N/en.pm +++ b/lib/Vroom/I18N/en.pm @@ -16,6 +16,7 @@ our %Lexicon = ( "ERROR_OCCURRED" => "An error occurred", "ERROR_NOT_LOGGED_IN" => "Sorry, your not logged in", "ERROR_DB_UNAVAILABLE" => "The database is not available", + "ERROR_DB_VERSION_MISMATCH" => "The database must be updated", "JS_REQUIRED" => "VROOM needs javascript to work properly", "EMAIL_INVITATION" => "Video conference invitation", "INVITE_SENT_TO_s" => "An invitation was sent to the following addresses\n%s", diff --git a/lib/Vroom/I18N/fr.pm b/lib/Vroom/I18N/fr.pm index 075e305..5d7d7fe 100644 --- a/lib/Vroom/I18N/fr.pm +++ b/lib/Vroom/I18N/fr.pm @@ -18,6 +18,7 @@ our %Lexicon = ( "ERROR_OCCURRED" => "Une erreur est survenue", "ERROR_NOT_LOGGED_IN" => "Désolé, vous n'êtes pas identifié",, "ERROR_DB_UNAVAILABLE" => "La base de données n'est pas accessible", + "ERROR_DB_VERSION_MISMATCH" => "La base de donnée doit être mise à jour", "JS_REQUIRED" => "VROOM nécessite l'activation du javascript", "EMAIL_INVITATION" => "Invitation à une conférence vidéo", "YOU_ARE_INVITED_TO_A_MEETING" => "Vous êtes attendu sur un salon de vidéo conférence. " . diff --git a/vroom.pl b/vroom.pl index 5cb2c80..2f3667f 100755 --- a/vroom.pl +++ b/vroom.pl @@ -73,6 +73,9 @@ if ($config->{'etherpad.uri'} =~ m/https?:\/\/.*/ && $config->{'etherpad.api_key } } +# GLobal error check +our $error = undef; + # Load I18N, and declare supported languages plugin I18N => { namespace => 'Vroom::I18N', @@ -137,6 +140,21 @@ helper valid_email => sub { # Various helpers # ########################## +# Check if the database schema is the one we expect +helper check_db_version => sub { + my $self = shift; + my $sth = eval { + $self->db->prepare('SELECT `value` + FROM `config` + WHERE `key`=\'schema_version\''); + }; + $sth->execute; + my $ver = undef; + $sth->bind_columns(\$ver); + $sth->fetch; + return ($ver eq Vroom::Constants::DB_VERSION) ? '1' : '0'; +}; + # Create a cookie based session helper login => sub { my $self = shift; @@ -1962,14 +1980,21 @@ app->hook(before_dispatch => sub { $self->stash(config => $config); # Check db is available - if (!$self->db){ - $self->app->log->info("Connect connect to the database"); + if ($error){ return $self->render('error', - msg => $self->l('ERROR_DB_UNAVAILABLE'), - err => 'ERROR_DB_UNAVAILABLE' + msg => $self->l($error), + err => $error, + room => '' ); } }); + +if (!app->db){ + $error = 'ERROR_DB_UNAVAILABLE'; +} +if (!app->check_db_version){ + $error = 'ERROR_DB_VERSION_MISMATCH'; +} # Are we running in hypnotoad ? app->config( hypnotoad => {