-my $kohaversion = C4::Context::KOHAVERSION;
-$kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
-
-#warn "db: $koha_db_version, koha: $kohaversion";
-
-if ( $kohaversion > $koha_db_version or C4::Context->preference('OpacMaintenance') ) {
- output_html_with_http_headers $input, '', $template->output;
+my $kohaversion = Koha::version();
+# Strip dots from version
+$kohaversion =~ s/\.//g if defined $kohaversion;
+$koha_db_version =~ s/\.//g if defined $koha_db_version;
+
+if ( !defined $koha_db_version || # DB not populated
+ $kohaversion > $koha_db_version || # Update needed
+ C4::Context->preference('OpacMaintenance') ) { # Maintenance mode enabled
+ output_html_with_http_headers $query, '', $template->output;