@@ -, +, @@ --- C4/Installer.pm | 2 +- C4/Update/Database.pm | 21 ++-- about.pl | 4 +- admin/ajax-updatedb-getinfos.pl | 2 +- admin/updatedatabase.pl | 17 +-- installer/data/mysql/update.pl | 85 --------------- koha-tmpl/intranet-tmpl/prog/en/modules/about.tt | 2 +- .../prog/en/modules/admin/updatedatabase.tt | 15 +-- misc/bin/updatedb.pl | 112 ++++++++++++++++++++ 9 files changed, 145 insertions(+), 115 deletions(-) delete mode 100644 installer/data/mysql/update.pl create mode 100644 misc/bin/updatedb.pl --- a/C4/Installer.pm +++ a/C4/Installer.pm @@ -468,7 +468,7 @@ Koha software version. sub set_version_syspref { my $self = shift; # get all updatedatabase, and mark them as passed, as it's a fresh install - my $versions = C4::Update::Database::list_versions_availables(); + my $versions = C4::Update::Database::list_versions_available(); for my $v ( @$versions ) { my $queries; $queries->{queries} = ["initial setup"]; --- a/C4/Update/Database.pm +++ a/C4/Update/Database.pm @@ -1,6 +1,6 @@ package C4::Update::Database; -# Copyright 2011 BibLibre +# Copyright Biblibre 2012 # # This file is part of Koha. # @@ -158,15 +158,14 @@ sub execute_version { return $report; } -=head2 list_versions_availables +=head2 list_versions_available - my @versions = list_versions_availables; + my @versions = list_versions_available; return an array with all version available - This list is retrieved from the directory defined in the etc/update/database/config.yaml, versions_dir parameter =cut -sub list_versions_availables { +sub list_versions_available { my @versions; my @files = File::Find::Rule->file->name( "*.sql", "*.pl" ) ->in( ( $VERSIONS_PATH ) ); @@ -179,15 +178,15 @@ sub list_versions_availables { return \@versions; } -=head2 list_versions_already_knows +=head2 list_versions_already_applied - my @versions = list_versions_availables; + my @versions = list_versions_available; return an array with all version that have already been applied This sub check first that the updatedb tables exist and create them if needed =cut -sub list_versions_already_knows { +sub list_versions_already_applied { # 1st check if tables exist, otherwise create them $dbh->do(qq{ CREATE TABLE IF NOT EXISTS `updatedb_error` ( `version` varchar(32) DEFAULT NULL, `error` text ) ENGINE=InnoDB CHARSET=utf8; @@ -489,9 +488,9 @@ sub mark_as_ok { The database is up to date if all versions are excecuted. =cut sub is_uptodate { - my $versions_availables = C4::Update::Database::list_versions_availables; - my $versions = C4::Update::Database::list_versions_already_knows; - for my $v ( @$versions_availables ) { + my $versions_available = C4::Update::Database::list_versions_available; + my $versions = C4::Update::Database::list_versions_already_applied; + for my $v ( @$versions_available ) { if ( not grep { $v eq $$_{version} } @$versions ) { return 0; } --- a/about.pl +++ a/about.pl @@ -58,12 +58,12 @@ my $dbrev_applied=""; # the list of database revisions # the $kohaVersion is duplicated since 3.7: the 3.6 (that uses the old mechanism) and the 3.7 (new mechanism). # Both versions reflects how the database has been upgraded -my $already_knows = C4::Update::Database::list_versions_already_knows(); +my $already_applied = C4::Update::Database::list_versions_already_applied(); # $last_known contains the previous DBrev applied number (all . removed). It's used to have a . instead of a number in case of continuous updates my $last_known=0; # $last_known_sep contains the previous DBrev applied with the separator (used for display) my $last_known_sep=""; -for my $v ( @$already_knows ) { +for my $v ( @$already_applied ) { my $current = $v->{version}; $current =~s/\.//g; # if the current number is the previous one +1, then just add a ., for a better display N.........N+10, for example --- a/admin/ajax-updatedb-getinfos.pl +++ a/admin/ajax-updatedb-getinfos.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Copyright 2011 BibLibre +# Copyright BibLibre 2012 # # This file is part of Koha. # --- a/admin/updatedatabase.pl +++ a/admin/updatedatabase.pl @@ -1,5 +1,7 @@ #!/usr/bin/perl +# Copyright Biblibre 2012 +# # This file is part of Koha. # # Koha is free software; you can redistribute it and/or modify it under the @@ -16,7 +18,6 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use Modern::Perl; -use strict; use CGI; use C4::Auth; use C4::Output; @@ -71,10 +72,10 @@ if ( $op eq 'mark_as_ok' ) { } if ( $op eq 'list' ) { - my $versions_availables = C4::Update::Database::list_versions_availables; - my $versions = C4::Update::Database::list_versions_already_knows; + my $versions_available = C4::Update::Database::list_versions_available; + my $versions = C4::Update::Database::list_versions_already_applied; - for my $v ( @$versions_availables ) { + for my $v ( @$versions_available ) { if ( not grep { $v eq $$_{version} } @$versions ) { push @$versions, { version => $v, @@ -86,14 +87,14 @@ if ( $op eq 'list' ) { C4::Update::Database::TransformToNum( $$a{version} ) <=> C4::Update::Database::TransformToNum( $$b{version} ) } @$versions; - my @availables = grep { defined $$_{available} and $$_{available} == 1 } @sorted; - my @v_availables = map { {version => $$_{version}} } @availables; + my @available = grep { defined $$_{available} and $$_{available} == 1 } @sorted; + my @v_available = map { {version => $$_{version}} } @available; $template->param( dev_mode => $ENV{DEBUG}, versions => \@sorted, - nb_availables => scalar @availables, - availables => [ map { {version => $$_{version}} } @availables ], + nb_available => scalar @available, + available => [ map { {version => $$_{version}} } @available ], ); } --- a/installer/data/mysql/update.pl +++ a/installer/data/mysql/update.pl @@ -1,85 +0,0 @@ -use Modern::Perl; - -use C4::Context; -use C4::Update::Database; -use Getopt::Long; - -my $help; -my $version; -my $list; -my $all; -my $min; - -GetOptions( - 'h|help|?' => \$help, - 'm:s' => \$version, - 'l|list' => \$list, - 'a|all' => \$all, - 'min:s' => \$min, -); - -if ( $help or not ($version or $list or $all) ) { - usage(); - exit; -} - -my @reports; -if ( $version ) { - my $report = C4::Update::Database::execute_version($version); - push @reports, $report; -} - -if ( $list ) { - my $versions = C4::Update::Database::list_versions_availables(); - say "Versions availables:"; - say "\t- $_" for @$versions; - $versions = C4::Update::Database::list_versions_already_knows(); - say "Versions already knows:"; - say "\t- $$_{version}" for @$versions; - -} - -if ( $all ) { - my $versions_availables = C4::Update::Database::list_versions_availables(); - my $versions = C4::Update::Database::list_versions_already_knows; - my $min_version = $min - ? $min =~ m/\d\.\d{2}\.\d{2}\.\d{3}/ - ? C4::Update::Database::TransformToNum( $min ) - : $min - : 0; - - for my $v ( @$versions_availables ) { - if ( not grep { $v eq $$_{version} } @$versions - and C4::Update::Database::TransformToNum( $v ) >= $min_version - ) { - my $report = C4::Update::Database::execute_version $v; - push @reports, $report; - } - } -} - -if ( $version or $all ) { - say @reports ? "Report:": "Nothing to report"; - for my $report ( @reports ) { - my ( $v, $r ) = each %$report; - if ( ref( $r ) eq 'HASH' ) { - say "\t$v => $r->{error}"; - } elsif ( ref ( $r ) eq 'ARRAY' ) { - say "\t$_" for @$r; - } else { - say "\t$v => $r"; - } - } -} - -sub usage { - say "update.pl"; - say "This script updates your database for you"; - say "Usage:"; - say "\t-h\tShow this help message"; - say "\t-m\tExecute a given version"; - say "\t-l\tList all the versions"; - say "\t-all\tExecute all available versions"; - say "\t-min\tWith -all, Execute all available versions since a given version"; - say "\t\tCan be X.XX.XX.XXX or X.XXXXXXX"; -} --- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt @@ -37,7 +37,7 @@ - + --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt @@ -104,15 +104,15 @@ [% END %] - [% IF nb_availables %] + [% IF nb_available %] Your datebase is not up to date.
- [% IF nb_availables == 1 %] - 1 update available [UPDATE [% availables.first.version %]] + [% IF nb_available == 1 %] + 1 update available [UPDATE [% available.first.version %]] [% ELSE %] - [% nb_availables %] updates available [UPDATE ALL]: + [% nb_available %] updates available [UPDATE ALL]: [% IF ( dev_mode ) %] @@ -145,7 +145,10 @@ [% ELSE %] [% SWITCH v.status %] [% CASE 0 %] - Applied and failed + + Applied and failed + [Mark as OK] + [% CASE 1 %] Applied and OK [% CASE 2 %] --- a/misc/bin/updatedb.pl +++ a/misc/bin/updatedb.pl @@ -0,0 +1,112 @@ +#!/usr/bin/perl + +# Copyright Biblibre 2012 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use C4::Context; +use C4::Update::Database; +use Getopt::Long; + +my $help; +my $version; +my $list; +my $all; +my $min; + +GetOptions( + 'h|help|?' => \$help, + 'm:s' => \$version, + 'l|list' => \$list, + 'a|all' => \$all, + 'min:s' => \$min, +); + +if ( $help or not( $version or $list or $all ) ) { + usage(); + exit; +} + +my @reports; +if ($version) { + my $report = C4::Update::Database::execute_version($version); + push @reports, $report; +} + +if ($list) { + my $available = C4::Update::Database::list_versions_available(); + my $already_applied = C4::Update::Database::list_versions_already_applied(); + say "Versions available:"; + for my $v (@$available) { + if ( not grep { $v eq $_->{version} } @$already_applied ) { + say "\t- $_" for $v; + } + } + say "Versions already applied:"; + say "\t- $_->{version}" for @$already_applied; + +} + +if ($all) { + my $versions_available = C4::Update::Database::list_versions_available(); + my $versions = C4::Update::Database::list_versions_already_applied; + my $min_version = + $min + ? $min =~ m/\d\.\d{2}\.\d{2}\.\d{3}/ + ? C4::Update::Database::TransformToNum($min) + : $min + : 0; + + for my $v (@$versions_available) { + if ( not grep { $v eq $_->{version} } @$versions + and C4::Update::Database::TransformToNum($v) >= $min_version ) + { + my $report = C4::Update::Database::execute_version $v; + push @reports, $report; + } + } +} + +if ( $version or $all ) { + say @reports ? "Report:" : "Nothing to report"; + for my $report (@reports) { + my ( $v, $r ) = each %$report; + if ( ref($r) eq 'HASH' ) { + say "\t$v => $r->{error}"; + } + elsif ( ref($r) eq 'ARRAY' ) { + say "\t$_" for @$r; + } + else { + say "\t$v => $r"; + } + } +} + +sub usage { + say "update.pl"; + say "This script updates your database for you"; + say "Usage:"; + say "\t-h\tShow this help message"; + say "\t-m\tExecute a given version"; + say "\t-l\tList all the versions"; + say "\t-all\tExecute all available versions"; + say + "\t-min\tWith -all, Execute all available versions since a given version"; + say "\t\tCan be X.XX.XX.XXX or X.XXXXXXX"; +} --
Server information
Koha version: [% kohaVersion |html %] with the following database revisionapplied: [% dbrev_applied|html %]
Koha version: [% kohaVersion |html %] with the following database revisions applied: [% dbrev_applied|html %]
OS version ('uname -a'): [% osVersion |html %]
Perl interpreter: [% perlPath |html %]
Perl version: [% perlVersion |html %]