3 # Copyright Biblibre 2012
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use C4::Update::Database;
40 if ( $help or not( $version or $list or $all ) ) {
47 my $report = C4::Update::Database::execute_version($version);
48 push @reports, $report;
52 my $available = C4::Update::Database::list_versions_available();
53 my $already_applied = C4::Update::Database::list_versions_already_applied();
54 say "Versions available:";
55 for my $v (@$available) {
56 if ( not grep { $v eq $_->{version} } @$already_applied ) {
60 say "Versions already applied:";
61 say "\t- $_->{version}" for @$already_applied;
66 my $versions_available = C4::Update::Database::list_versions_available();
67 my $versions = C4::Update::Database::list_versions_already_applied;
70 ? $min =~ m/\d\.\d{2}\.\d{2}\.\d{3}/
71 ? C4::Update::Database::TransformToNum($min)
75 for my $v (@$versions_available) {
76 # We execute ALL versions where version number >= min_version
77 # OR version is not a number
78 if ( not grep { $v eq $_->{version} } @$versions
79 and ( not $v =~ /\d\.\d{2}\.\d{2}\.\d{3}/ or
80 C4::Update::Database::TransformToNum($v) >= $min_version ) )
82 my $report = C4::Update::Database::execute_version $v;
83 push @reports, $report;
88 if ( $version or $all ) {
89 say @reports ? "Report:" : "Nothing to report";
90 for my $report (@reports) {
91 my ( $v, $r ) = each %$report;
92 if ( ref($r) eq 'HASH' ) {
93 say "\t$v => $r->{error}";
95 elsif ( ref($r) eq 'ARRAY' ) {
106 say "This script updates your database for you";
108 say "\t-h\tShow this help message";
109 say "\t-m\tExecute a given version";
110 say "\t-l\tList all the versions";
111 say "\t-all\tExecute all available versions";
113 "\t-min\tWith -all, Execute all available versions since a given version";
114 say "\t\tCan be X.XX.XX.XXX or X.XXXXXXX";