View | Details | Raw Unified | Return to bug 7167
Collapse All | Expand All

(-)a/C4/Installer.pm (-1 / +1 lines)
Lines 468-474 Koha software version. Link Here
468
sub set_version_syspref {
468
sub set_version_syspref {
469
    my $self = shift;
469
    my $self = shift;
470
    # get all updatedatabase, and mark them as passed, as it's a fresh install
470
    # get all updatedatabase, and mark them as passed, as it's a fresh install
471
    my $versions = C4::Update::Database::list_versions_availables();
471
    my $versions = C4::Update::Database::list_versions_available();
472
    for my $v ( @$versions ) {
472
    for my $v ( @$versions ) {
473
        my $queries;
473
        my $queries;
474
        $queries->{queries} = ["initial setup"];
474
        $queries->{queries} = ["initial setup"];
(-)a/C4/Update/Database.pm (-11 / +10 lines)
Lines 1-6 Link Here
1
package C4::Update::Database;
1
package C4::Update::Database;
2
2
3
# Copyright 2011 BibLibre
3
# Copyright Biblibre 2012
4
#
4
#
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
Lines 158-172 sub execute_version { Link Here
158
    return $report;
158
    return $report;
159
}
159
}
160
160
161
=head2 list_versions_availables
161
=head2 list_versions_available
162
162
163
  my @versions = list_versions_availables;
163
  my @versions = list_versions_available;
164
  return an array with all version available
164
  return an array with all version available
165
  This list is retrieved from the directory defined in the etc/update/database/config.yaml, versions_dir parameter
166
165
167
=cut
166
=cut
168
167
169
sub list_versions_availables {
168
sub list_versions_available {
170
    my @versions;
169
    my @versions;
171
170
172
    my @files = File::Find::Rule->file->name( "*.sql", "*.pl" ) ->in( ( $VERSIONS_PATH ) );
171
    my @files = File::Find::Rule->file->name( "*.sql", "*.pl" ) ->in( ( $VERSIONS_PATH ) );
Lines 179-193 sub list_versions_availables { Link Here
179
    return \@versions;
178
    return \@versions;
180
}
179
}
181
180
182
=head2 list_versions_already_knows
181
=head2 list_versions_already_applied
183
182
184
  my @versions = list_versions_availables;
183
  my @versions = list_versions_available;
185
  return an array with all version that have already been applied
184
  return an array with all version that have already been applied
186
  This sub check first that the updatedb tables exist and create them if needed
185
  This sub check first that the updatedb tables exist and create them if needed
187
186
188
=cut
187
=cut
189
188
190
sub list_versions_already_knows {
189
sub list_versions_already_applied {
191
    # 1st check if tables exist, otherwise create them
190
    # 1st check if tables exist, otherwise create them
192
        $dbh->do(qq{
191
        $dbh->do(qq{
193
                CREATE TABLE IF NOT EXISTS `updatedb_error` ( `version` varchar(32) DEFAULT NULL, `error` text ) ENGINE=InnoDB CHARSET=utf8;
192
                CREATE TABLE IF NOT EXISTS `updatedb_error` ( `version` varchar(32) DEFAULT NULL, `error` text ) ENGINE=InnoDB CHARSET=utf8;
Lines 489-497 sub mark_as_ok { Link Here
489
  The database is up to date if all versions are excecuted.
488
  The database is up to date if all versions are excecuted.
490
=cut
489
=cut
491
sub is_uptodate {
490
sub is_uptodate {
492
    my $versions_availables = C4::Update::Database::list_versions_availables;
491
    my $versions_available = C4::Update::Database::list_versions_available;
493
    my $versions = C4::Update::Database::list_versions_already_knows;
492
    my $versions = C4::Update::Database::list_versions_already_applied;
494
    for my $v ( @$versions_availables ) {
493
    for my $v ( @$versions_available ) {
495
        if ( not grep { $v eq $$_{version} } @$versions ) {
494
        if ( not grep { $v eq $$_{version} } @$versions ) {
496
            return 0;
495
            return 0;
497
        }
496
        }
(-)a/about.pl (-2 / +2 lines)
Lines 58-69 my $dbrev_applied=""; # the list of database revisions Link Here
58
58
59
# the $kohaVersion is duplicated since 3.7: the 3.6 (that uses the old mechanism) and the 3.7 (new mechanism).
59
# the $kohaVersion is duplicated since 3.7: the 3.6 (that uses the old mechanism) and the 3.7 (new mechanism).
60
# Both versions reflects how the database has been upgraded
60
# Both versions reflects how the database has been upgraded
61
my $already_knows = C4::Update::Database::list_versions_already_knows();
61
my $already_applied = C4::Update::Database::list_versions_already_applied();
62
# $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
62
# $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
63
my $last_known=0;
63
my $last_known=0;
64
# $last_known_sep contains the previous DBrev applied with the separator (used for display)
64
# $last_known_sep contains the previous DBrev applied with the separator (used for display)
65
my $last_known_sep="";
65
my $last_known_sep="";
66
for my $v ( @$already_knows ) {
66
for my $v ( @$already_applied ) {
67
    my $current = $v->{version};
67
    my $current = $v->{version};
68
    $current =~s/\.//g;
68
    $current =~s/\.//g;
69
    # if the current number is the previous one +1, then just add a ., for a better display N.........N+10, for example
69
    # 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 (-1 / +1 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright 2011 BibLibre
3
# Copyright BibLibre 2012
4
#
4
#
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
(-)a/admin/updatedatabase.pl (-8 / +9 lines)
Lines 1-5 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright Biblibre 2012
4
#
3
# This file is part of Koha.
5
# This file is part of Koha.
4
#
6
#
5
# Koha is free software; you can redistribute it and/or modify it under the
7
# Koha is free software; you can redistribute it and/or modify it under the
Lines 16-22 Link Here
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
19
18
use Modern::Perl;
20
use Modern::Perl;
19
use strict;
20
use CGI;
21
use CGI;
21
use C4::Auth;
22
use C4::Auth;
22
use C4::Output;
23
use C4::Output;
Lines 71-80 if ( $op eq 'mark_as_ok' ) { Link Here
71
}
72
}
72
73
73
if ( $op eq 'list' ) {
74
if ( $op eq 'list' ) {
74
    my $versions_availables = C4::Update::Database::list_versions_availables;
75
    my $versions_available = C4::Update::Database::list_versions_available;
75
    my $versions = C4::Update::Database::list_versions_already_knows;
76
    my $versions = C4::Update::Database::list_versions_already_applied;
76
77
77
    for my $v ( @$versions_availables ) {
78
    for my $v ( @$versions_available ) {
78
        if ( not grep { $v eq $$_{version} } @$versions ) {
79
        if ( not grep { $v eq $$_{version} } @$versions ) {
79
            push @$versions, {
80
            push @$versions, {
80
                version => $v,
81
                version => $v,
Lines 86-99 if ( $op eq 'list' ) { Link Here
86
        C4::Update::Database::TransformToNum( $$a{version} ) <=> C4::Update::Database::TransformToNum( $$b{version} )
87
        C4::Update::Database::TransformToNum( $$a{version} ) <=> C4::Update::Database::TransformToNum( $$b{version} )
87
    } @$versions;
88
    } @$versions;
88
89
89
    my @availables = grep { defined $$_{available} and $$_{available} == 1 } @sorted;
90
    my @available = grep { defined $$_{available} and $$_{available} == 1 } @sorted;
90
    my @v_availables = map { {version => $$_{version}} } @availables;
91
    my @v_available = map { {version => $$_{version}} } @available;
91
92
92
    $template->param(
93
    $template->param(
93
        dev_mode => $ENV{DEBUG},
94
        dev_mode => $ENV{DEBUG},
94
        versions => \@sorted,
95
        versions => \@sorted,
95
        nb_availables => scalar @availables,
96
        nb_available => scalar @available,
96
        availables => [ map { {version => $$_{version}} } @availables ],
97
        available => [ map { {version => $$_{version}} } @available ],
97
    );
98
    );
98
}
99
}
99
100
(-)a/installer/data/mysql/update.pl (-85 lines)
Lines 1-85 Link Here
1
use Modern::Perl;
2
3
use C4::Context;
4
use C4::Update::Database;
5
use Getopt::Long;
6
7
my $help;
8
my $version;
9
my $list;
10
my $all;
11
my $min;
12
13
GetOptions(
14
    'h|help|?'     => \$help,
15
    'm:s'   => \$version,
16
    'l|list'     => \$list,
17
    'a|all'   => \$all,
18
    'min:s' => \$min,
19
);
20
21
if ( $help or not ($version or $list or $all) ) {
22
    usage();
23
    exit;
24
}
25
26
my @reports;
27
if ( $version ) {
28
    my $report = C4::Update::Database::execute_version($version);
29
    push @reports, $report;
30
}
31
32
if ( $list ) {
33
    my $versions = C4::Update::Database::list_versions_availables();
34
    say "Versions availables:";
35
    say "\t- $_" for @$versions;
36
    $versions = C4::Update::Database::list_versions_already_knows();
37
    say "Versions already knows:";
38
    say "\t- $$_{version}" for @$versions;
39
40
}
41
42
if ( $all ) {
43
    my $versions_availables = C4::Update::Database::list_versions_availables();
44
    my $versions = C4::Update::Database::list_versions_already_knows;
45
    my $min_version = $min
46
        ? $min =~ m/\d\.\d{2}\.\d{2}\.\d{3}/
47
            ? C4::Update::Database::TransformToNum( $min )
48
            : $min
49
        : 0;
50
51
    for my $v ( @$versions_availables ) {
52
        if ( not grep { $v eq $$_{version} } @$versions
53
             and C4::Update::Database::TransformToNum( $v ) >= $min_version
54
        ) {
55
            my $report = C4::Update::Database::execute_version $v;
56
            push @reports, $report;
57
        }
58
    }
59
}
60
61
if ( $version or $all ) {
62
    say @reports ? "Report:": "Nothing to report";
63
    for my $report ( @reports ) {
64
        my ( $v, $r ) = each %$report;
65
        if ( ref( $r ) eq 'HASH' ) {
66
            say "\t$v => $r->{error}";
67
        } elsif ( ref ( $r ) eq 'ARRAY' ) {
68
            say "\t$_" for @$r;
69
        } else {
70
            say "\t$v => $r";
71
        }
72
    }
73
}
74
75
sub usage {
76
    say "update.pl";
77
    say "This script updates your database for you";
78
    say "Usage:";
79
    say "\t-h\tShow this help message";
80
    say "\t-m\tExecute a given version";
81
    say "\t-l\tList all the versions";
82
    say "\t-all\tExecute all available versions";
83
    say "\t-min\tWith -all, Execute all available versions since a given version";
84
    say "\t\tCan be X.XX.XX.XXX or X.XXXXXXX";
85
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt (-1 / +1 lines)
Lines 37-43 Link Here
37
37
38
        <table>
38
        <table>
39
            <caption>Server information</caption>
39
            <caption>Server information</caption>
40
            <tr><th scope="row">Koha version: </th><td>[% kohaVersion |html %] with the following database revisionapplied: [% dbrev_applied|html %]</td></tr>
40
            <tr><th scope="row">Koha version: </th><td>[% kohaVersion |html %] with the following database revisions applied: [% dbrev_applied|html %]</td></tr>
41
            <tr><th scope="row">OS version ('uname -a'): </th><td>[% osVersion |html %]</td></tr>
41
            <tr><th scope="row">OS version ('uname -a'): </th><td>[% osVersion |html %]</td></tr>
42
            <tr><th scope="row">Perl interpreter: </th><td>[% perlPath |html %]</td></tr>
42
            <tr><th scope="row">Perl interpreter: </th><td>[% perlPath |html %]</td></tr>
43
            <tr><th scope="row">Perl version: </th><td>[% perlVersion |html %]</td></tr>
43
            <tr><th scope="row">Perl version: </th><td>[% perlVersion |html %]</td></tr>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt (-6 / +9 lines)
Lines 104-118 Link Here
104
    </div>
104
    </div>
105
    [% END %]
105
    [% END %]
106
    <span class="infos" style="display:block; margin:1em;">
106
    <span class="infos" style="display:block; margin:1em;">
107
        [% IF nb_availables %]
107
        [% IF nb_available %]
108
            Your datebase is not up to date.<br/>
108
            Your datebase is not up to date.<br/>
109
            [% IF nb_availables == 1 %]
109
            [% IF nb_available == 1 %]
110
                1 update available [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% availables.first.version %]">UPDATE [% availables.first.version %]</a>]
110
                1 update available [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% available.first.version %]">UPDATE [% available.first.version %]</a>]
111
            [% ELSE %]
111
            [% ELSE %]
112
                [% nb_availables %] updates available [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update[% FOREACH av IN availables %]&version=[% av.version %][% END %]">UPDATE ALL</a>]:
112
                [% nb_available %] updates available [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update[% FOREACH av IN available %]&version=[% av.version %][% END %]">UPDATE ALL</a>]:
113
                [% IF ( dev_mode ) %]
113
                [% IF ( dev_mode ) %]
114
                  <ul>
114
                  <ul>
115
                    [% FOREACH av IN availables %]
115
                    [% FOREACH av IN available %]
116
                      <li>[% av.version %] [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% av.version %]">UPDATE</a>]</li>
116
                      <li>[% av.version %] [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% av.version %]">UPDATE</a>]</li>
117
                    [% END %]
117
                    [% END %]
118
                  </ul>
118
                  </ul>
Lines 145-151 Link Here
145
                    [% ELSE %]
145
                    [% ELSE %]
146
                        [% SWITCH v.status %]
146
                        [% SWITCH v.status %]
147
                        [% CASE 0 %]
147
                        [% CASE 0 %]
148
                            <span style="color:red;">Applied and failed</span>
148
                            <span style="color:red;">
149
                              Applied and failed
150
                              [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% v.version %]">Mark as OK</a>]
151
                            </span>
149
                        [% CASE 1 %]
152
                        [% CASE 1 %]
150
                            <span style="color:green;">Applied and OK</span>
153
                            <span style="color:green;">Applied and OK</span>
151
                        [% CASE 2 %]
154
                        [% CASE 2 %]
(-)a/misc/bin/updatedb.pl (-1 / +112 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright Biblibre 2012
4
#
5
# This file is part of Koha.
6
#
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
10
# version.
11
#
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.
15
#
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.
19
20
use Modern::Perl;
21
22
use C4::Context;
23
use C4::Update::Database;
24
use Getopt::Long;
25
26
my $help;
27
my $version;
28
my $list;
29
my $all;
30
my $min;
31
32
GetOptions(
33
    'h|help|?' => \$help,
34
    'm:s'      => \$version,
35
    'l|list'   => \$list,
36
    'a|all'    => \$all,
37
    'min:s'    => \$min,
38
);
39
40
if ( $help or not( $version or $list or $all ) ) {
41
    usage();
42
    exit;
43
}
44
45
my @reports;
46
if ($version) {
47
    my $report = C4::Update::Database::execute_version($version);
48
    push @reports, $report;
49
}
50
51
if ($list) {
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 ) {
57
            say "\t- $_" for $v;
58
        }
59
    }
60
    say "Versions already applied:";
61
    say "\t- $_->{version}" for @$already_applied;
62
63
}
64
65
if ($all) {
66
    my $versions_available = C4::Update::Database::list_versions_available();
67
    my $versions = C4::Update::Database::list_versions_already_applied;
68
    my $min_version =
69
        $min
70
      ? $min =~ m/\d\.\d{2}\.\d{2}\.\d{3}/
71
          ? C4::Update::Database::TransformToNum($min)
72
          : $min
73
      : 0;
74
75
    for my $v (@$versions_available) {
76
        if ( not grep { $v eq $_->{version} } @$versions
77
            and C4::Update::Database::TransformToNum($v) >= $min_version )
78
        {
79
            my $report = C4::Update::Database::execute_version $v;
80
            push @reports, $report;
81
        }
82
    }
83
}
84
85
if ( $version or $all ) {
86
    say @reports ? "Report:" : "Nothing to report";
87
    for my $report (@reports) {
88
        my ( $v, $r ) = each %$report;
89
        if ( ref($r) eq 'HASH' ) {
90
            say "\t$v => $r->{error}";
91
        }
92
        elsif ( ref($r) eq 'ARRAY' ) {
93
            say "\t$_" for @$r;
94
        }
95
        else {
96
            say "\t$v => $r";
97
        }
98
    }
99
}
100
101
sub usage {
102
    say "update.pl";
103
    say "This script updates your database for you";
104
    say "Usage:";
105
    say "\t-h\tShow this help message";
106
    say "\t-m\tExecute a given version";
107
    say "\t-l\tList all the versions";
108
    say "\t-all\tExecute all available versions";
109
    say
110
      "\t-min\tWith -all, Execute all available versions since a given version";
111
    say "\t\tCan be X.XX.XX.XXX or X.XXXXXXX";
112
}

Return to bug 7167