Check DB version when starting

Also do not run checks on each page rendering, just once at startup
master
Daniel Berteaud 10 years ago
parent 2b861dba96
commit 63dbf66b89
  1. 1
      lib/Vroom/I18N/en.pm
  2. 1
      lib/Vroom/I18N/fr.pm
  3. 33
      vroom.pl

@ -16,6 +16,7 @@ our %Lexicon = (
"ERROR_OCCURRED" => "An error occurred", "ERROR_OCCURRED" => "An error occurred",
"ERROR_NOT_LOGGED_IN" => "Sorry, your not logged in", "ERROR_NOT_LOGGED_IN" => "Sorry, your not logged in",
"ERROR_DB_UNAVAILABLE" => "The database is not available", "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", "JS_REQUIRED" => "VROOM needs javascript to work properly",
"EMAIL_INVITATION" => "Video conference invitation", "EMAIL_INVITATION" => "Video conference invitation",
"INVITE_SENT_TO_s" => "An invitation was sent to the following addresses\n%s", "INVITE_SENT_TO_s" => "An invitation was sent to the following addresses\n%s",

@ -18,6 +18,7 @@ our %Lexicon = (
"ERROR_OCCURRED" => "Une erreur est survenue", "ERROR_OCCURRED" => "Une erreur est survenue",
"ERROR_NOT_LOGGED_IN" => "Désolé, vous n'êtes pas identifié",, "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_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", "JS_REQUIRED" => "VROOM nécessite l'activation du javascript",
"EMAIL_INVITATION" => "Invitation à une conférence vidéo", "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. " . "YOU_ARE_INVITED_TO_A_MEETING" => "Vous êtes attendu sur un salon de vidéo conférence. " .

@ -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 # Load I18N, and declare supported languages
plugin I18N => { plugin I18N => {
namespace => 'Vroom::I18N', namespace => 'Vroom::I18N',
@ -137,6 +140,21 @@ helper valid_email => sub {
# Various helpers # # 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 # Create a cookie based session
helper login => sub { helper login => sub {
my $self = shift; my $self = shift;
@ -1962,14 +1980,21 @@ app->hook(before_dispatch => sub {
$self->stash(config => $config); $self->stash(config => $config);
# Check db is available # Check db is available
if (!$self->db){ if ($error){
$self->app->log->info("Connect connect to the database");
return $self->render('error', return $self->render('error',
msg => $self->l('ERROR_DB_UNAVAILABLE'), msg => $self->l($error),
err => 'ERROR_DB_UNAVAILABLE' 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 ? # Are we running in hypnotoad ?
app->config( app->config(
hypnotoad => { hypnotoad => {

Loading…
Cancel
Save