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

(-)a/C4/Auth.pm (-72 / +12 lines)
Lines 35-41 use POSIX qw/strftime/; Link Here
35
use List::MoreUtils qw/ any /;
35
use List::MoreUtils qw/ any /;
36
36
37
# use utf8;
37
# use utf8;
38
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout $servers $memcached);
38
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout $servers $memcached);
39
39
40
BEGIN {
40
BEGIN {
41
    sub psgi_env { any { /^psgi\./ } keys %ENV }
41
    sub psgi_env { any { /^psgi\./ } keys %ENV }
Lines 44-50 BEGIN { Link Here
44
	else { exit }
44
	else { exit }
45
    }
45
    }
46
46
47
    $VERSION     = 3.02;                                                                                                            # set version for version checking
48
    $debug       = $ENV{DEBUG};
47
    $debug       = $ENV{DEBUG};
49
    @ISA         = qw(Exporter);
48
    @ISA         = qw(Exporter);
50
    @EXPORT      = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
49
    @EXPORT      = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
Lines 580-628 has authenticated. Link Here
580
579
581
=cut
580
=cut
582
581
583
sub _version_check ($$) {
584
    my $type = shift;
585
    my $query = shift;
586
    my $version;
587
    # If Version syspref is unavailable, it means Koha is beeing installed,
588
    # and so we must redirect to OPAC maintenance page or to the WebInstaller
589
	# also, if OpacMaintenance is ON, OPAC should redirect to maintenance
590
	if (C4::Context->preference('OpacMaintenance') && $type eq 'opac') {
591
        warn "OPAC Install required, redirecting to maintenance";
592
        print $query->redirect("/cgi-bin/koha/maintenance.pl");
593
    }
594
    unless ( $version = C4::Context->preference('Version') ) {    # assignment, not comparison
595
        if ( $type ne 'opac' ) {
596
            warn "Install required, redirecting to Installer";
597
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
598
        } else {
599
            warn "OPAC Install required, redirecting to maintenance";
600
            print $query->redirect("/cgi-bin/koha/maintenance.pl");
601
        }
602
        safe_exit;
603
    }
604
605
    # check that database and koha version are the same
606
    # there is no DB version, it's a fresh install,
607
    # go to web installer
608
    # there is a DB version, compare it to the code version
609
    my $kohaversion=C4::Context::KOHAVERSION;
610
    # remove the 3 last . to have a Perl number
611
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
612
    $debug and print STDERR "kohaversion : $kohaversion\n";
613
    if ($version < $kohaversion){
614
        my $warning = "Database update needed, redirecting to %s. Database is $version and Koha is $kohaversion";
615
        if ($type ne 'opac'){
616
            warn sprintf($warning, 'Installer');
617
            print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3");
618
        } else {
619
            warn sprintf("OPAC: " . $warning, 'maintenance');
620
            print $query->redirect("/cgi-bin/koha/maintenance.pl");
621
        }
622
        safe_exit;
623
    }
624
}
625
626
sub _session_log {
582
sub _session_log {
627
    (@_) or return 0;
583
    (@_) or return 0;
628
    open L, ">>/tmp/sessionlog" or warn "ERROR: Cannot append to /tmp/sessionlog";
584
    open L, ">>/tmp/sessionlog" or warn "ERROR: Cannot append to /tmp/sessionlog";
Lines 646-653 sub checkauth { Link Here
646
        $timeout = $1 * 86400;
602
        $timeout = $1 * 86400;
647
    };
603
    };
648
    $timeout = 600 unless $timeout;
604
    $timeout = 600 unless $timeout;
605
    # check we have a Version. Otherwise => go to installer
606
    unless ( C4::Context->preference('Version') ) {    # assignment, not comparison
607
        if ( $type ne 'opac' ) {
608
            warn "Install required, redirecting to Installer";
609
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
610
        } else {
611
            warn "OPAC Install required, redirecting to maintenance";
612
            print $query->redirect("/cgi-bin/koha/maintenance.pl");
613
        }
614
        safe_exit;
615
    }
649
616
650
    _version_check($type,$query);
651
    # state variables
617
    # state variables
652
    my $loggedin = 0;
618
    my $loggedin = 0;
653
    my %info;
619
    my %info;
Lines 1089-1107 sub check_api_auth { Link Here
1089
    my $timeout = C4::Context->preference('timeout');
1055
    my $timeout = C4::Context->preference('timeout');
1090
    $timeout = 600 unless $timeout;
1056
    $timeout = 600 unless $timeout;
1091
1057
1092
    unless (C4::Context->preference('Version')) {
1093
        # database has not been installed yet
1094
        return ("maintenance", undef, undef);
1095
    }
1096
    my $kohaversion=C4::Context::KOHAVERSION;
1097
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
1098
    if (C4::Context->preference('Version') < $kohaversion) {
1099
        # database in need of version update; assume that
1100
        # no API should be called while databsae is in
1101
        # this condition.
1102
        return ("maintenance", undef, undef);
1103
    }
1104
1105
    # FIXME -- most of what follows is a copy-and-paste
1058
    # FIXME -- most of what follows is a copy-and-paste
1106
    # of code from checkauth.  There is an obvious need
1059
    # of code from checkauth.  There is an obvious need
1107
    # for refactoring to separate the various parts of
1060
    # for refactoring to separate the various parts of
Lines 1322-1340 sub check_cookie_auth { Link Here
1322
    my $timeout = C4::Context->preference('timeout');
1275
    my $timeout = C4::Context->preference('timeout');
1323
    $timeout = 600 unless $timeout;
1276
    $timeout = 600 unless $timeout;
1324
1277
1325
    unless (C4::Context->preference('Version')) {
1326
        # database has not been installed yet
1327
        return ("maintenance", undef);
1328
    }
1329
    my $kohaversion=C4::Context::KOHAVERSION;
1330
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
1331
    if (C4::Context->preference('Version') < $kohaversion) {
1332
        # database in need of version update; assume that
1333
        # no API should be called while databsae is in
1334
        # this condition.
1335
        return ("maintenance", undef);
1336
    }
1337
1338
    # FIXME -- most of what follows is a copy-and-paste
1278
    # FIXME -- most of what follows is a copy-and-paste
1339
    # of code from checkauth.  There is an obvious need
1279
    # of code from checkauth.  There is an obvious need
1340
    # for refactoring to separate the various parts of
1280
    # for refactoring to separate the various parts of
(-)a/C4/Config/File/YAML.pm (+60 lines)
Line 0 Link Here
1
package C4::Config::File::YAML;
2
# Copyright 2011 BibLibre
3
#
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 2 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along
16
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
use Modern::Perl;
20
use YAML;
21
22
sub _fileload{
23
    my ($filename)=shift;
24
    return YAML::LoadFile($filename);
25
}
26
27
sub _dirload{
28
    my $dirname=shift;
29
    my $result;
30
    opendir D, $dirname;
31
    for my $name (readdir(D)){
32
        next if $name=~/^\./;
33
        if (-d $name){
34
            $result->{$name}=_dirload($dirname."/".$name);
35
        }
36
        if ((-e $dirname."/".$name) and ($name=~/\.ya?ml/) ){
37
            $result=($result
38
                    ? [%$result,%{_fileload($dirname."/".$name)}]
39
                    : _fileload($dirname."/".$name));
40
        }
41
    }
42
    close D;
43
    return $result;
44
}
45
46
47
sub new{
48
    my $config;
49
    my $self=shift;
50
    my $name=shift;
51
    if (-f $name){
52
        $config=_fileload($name);
53
    }
54
    if (-d $name){
55
        $config->{$name}=_dirload($name);
56
    }
57
    return $config;
58
}
59
1;
60
(-)a/C4/Installer.pm (-4 / +15 lines)
Lines 22-27 use strict; Link Here
22
22
23
our $VERSION = 3.00;
23
our $VERSION = 3.00;
24
use C4::Context;
24
use C4::Context;
25
use C4::Update::Database;
25
use C4::Installer::PerlModules 1.000000;
26
use C4::Installer::PerlModules 1.000000;
26
27
27
=head1 NAME
28
=head1 NAME
Lines 466-475 Koha software version. Link Here
466
467
467
sub set_version_syspref {
468
sub set_version_syspref {
468
    my $self = shift;
469
    my $self = shift;
469
470
    # get all updatedatabase, and mark them as passed, as it's a fresh install
470
    my $kohaversion=C4::Context::KOHAVERSION;
471
    my $versions = C4::Update::Database::list_versions_availables();
471
    # remove the 3 last . to have a Perl number
472
    my $kohaversion=0;
472
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
473
    for my $v ( @$versions ) {
474
        my $queries;
475
        $queries->{queries} = ["initial setup"];
476
        $queries->{comments} = ["initial setup"];
477
        C4::Update::Database::set_infos($v,$queries,undef,undef);
478
        # remove the 3 last . to have a Perl number
479
        $v =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
480
        if ($v>$kohaversion) {
481
            $kohaversion = $v;
482
        }
483
    }
473
    if (C4::Context->preference('Version')) {
484
    if (C4::Context->preference('Version')) {
474
        warn "UPDATE Version";
485
        warn "UPDATE Version";
475
        my $finish=$self->{'dbh'}->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
486
        my $finish=$self->{'dbh'}->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
(-)a/C4/Update/Database.pm (-23 / +173 lines)
Lines 1-5 Link Here
1
package C4::Update::Database;
1
package C4::Update::Database;
2
2
3
# Copyright 2011 BibLibre
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
3
use Modern::Perl;
20
use Modern::Perl;
4
21
5
use C4::Context;
22
use C4::Context;
Lines 9-15 use File::Basename; Link Here
9
use Digest::MD5;
26
use Digest::MD5;
10
use List::MoreUtils qw/uniq/;
27
use List::MoreUtils qw/uniq/;
11
28
12
my $config = C4::Config::File::YAML->new( C4::Context->config("installdir") . qq{/etc/update/database/config.yaml} );
29
=head1 NAME
30
31
C4::Update::Database.pm
32
33
=head1 SYNOPSIS
34
35
  use C4::Update::Database;
36
  
37
  This package is used by admin/updatedatabase.pl, to manage DB updates
38
39
=head1 FUNCTIONS
40
41
=cut
42
my $config = C4::Config::File::YAML->new( C4::Context->config("intranetdir") . qq{/etc/update/database/config.yaml} );
13
my $VERSIONS_PATH = C4::Context->config('intranetdir') . '/' . $config->{versions_dir};
43
my $VERSIONS_PATH = C4::Context->config('intranetdir') . '/' . $config->{versions_dir};
14
44
15
my $version;
45
my $version;
Lines 17-32 my $list; Link Here
17
47
18
my $dbh = C4::Context->dbh;
48
my $dbh = C4::Context->dbh;
19
49
50
=head2
51
52
  my $file = get_filepath($version);
53
  this sub will return the full path of a given DB update number
54
55
=cut
56
20
sub get_filepath {
57
sub get_filepath {
21
    my ( $version ) = @_;
58
    my ( $version ) = @_;
22
    my @files = <$VERSIONS_PATH/$version*>;
59
    my @files = <$VERSIONS_PATH/$version*>;
23
    if ( scalar @files != 1 ) {
60
    if ( scalar @files != 1 ) {
24
        die "This version ($version) returned more than one file (or any) corresponding!";
61
        die "This version ($version) returned has ".scalar @files." corresponding, need only 1";
25
    }
62
    }
26
63
27
    return $files[0];
64
    return $files[0];
28
}
65
}
29
66
67
=head2 get_md5
68
69
  my $md5 = get_md5($filepath)
70
  returns the md5sum of the selected file.
71
  This is used to check consistency of updates
72
    
73
=cut
30
sub get_md5 {
74
sub get_md5 {
31
    my ( $filepath ) = @_;
75
    my ( $filepath ) = @_;
32
    open(FILE, $filepath);
76
    open(FILE, $filepath);
Lines 38-43 sub get_md5 { Link Here
38
    return $md5;
82
    return $md5;
39
}
83
}
40
84
85
=head2 execute_version
86
87
  $result = execute_version($version_number);
88
  Execute an update.
89
  This sub will detect if the number is made through a .pl or a .sql, and behave accordingly
90
  if there is more than 1 file with the same number, an error will be issued
91
  if you try to execute a version_number that has already be executed, then it will also issue an error
92
  the sub return an result hash, with the version number and the result
93
    
94
=cut
95
41
sub execute_version {
96
sub execute_version {
42
    my ( $version ) = @_;
97
    my ( $version ) = @_;
43
    my $report;
98
    my $report;
Lines 58-64 sub execute_version { Link Here
58
    my $r = md5_already_exists( $md5 );
113
    my $r = md5_already_exists( $md5 );
59
    if ( scalar @$r ) {
114
    if ( scalar @$r ) {
60
        my $p = @$r[0];
115
        my $p = @$r[0];
61
        $$report{$version} = "This file ( $filepath ) still already execute in version " . @$r[0]->{version} . " : same md5 (" . @$r[0]->{md5} . ")";
116
        $report->{$version} = "This file ( $filepath ) still already execute in version " . @$r[0]->{version} . " : same md5 (" . @$r[0]->{md5} . ")";
62
        return $report;
117
        return $report;
63
    }
118
    }
64
119
Lines 73-91 sub execute_version { Link Here
73
            if ( do $version_file ) {
128
            if ( do $version_file ) {
74
                $queries = _get_queries();
129
                $queries = _get_queries();
75
            } else {
130
            } else {
76
                $$report{$version} = "Load functions in $filename failed";
131
                $report->{$version} = "Load functions in $filename failed";
77
            }
132
            }
78
        }
133
        }
79
        default {
134
        default {
80
            $$report{$version} = "This extension ($extension) is not take into account (only .pl or .sql)";
135
            $report->{$version} = "This extension ($extension) is not take into account (only .pl or .sql)";
81
        }
136
        }
82
    }
137
    }
138
    # check Koha version, and if this patch has a higher number, update it
139
    warn "VERSION : ".C4::Context->preference("Version")." against < ".TransformToNum($version);
140
    if (C4::Context->preference("Version") < TransformToNum($version)) {
141
        SetVersion(TransformToNum($version));
142
    }
83
143
84
    return $report
144
    return $report
85
        if ( defined $$report{$version} );
145
        if ( defined $report->{$version} );
86
146
87
    my $errors;
147
    my $errors;
88
    for my $query ( @{$$queries{queries}} ) {
148
    for my $query ( @{$queries->{queries}} ) {
89
        eval {
149
        eval {
90
            check_coherency( $query );
150
            check_coherency( $query );
91
        };
151
        };
Lines 96-112 sub execute_version { Link Here
96
156
97
    if ( $errors ) {
157
    if ( $errors ) {
98
        $_ =~ s/at [^ ]* line \d*\.$// for @$errors;
158
        $_ =~ s/at [^ ]* line \d*\.$// for @$errors;
99
        $$report{$version} = $errors;
159
        $report->{$version} = $errors;
100
        return $report;
160
        return $report;
101
    }
161
    }
102
162
103
    $errors = execute ( $queries );
163
    $errors = execute ( $queries );
104
    $$report{$version} = scalar( @$errors ) ? $errors : "OK";
164
    $report->{$version} = scalar( @$errors ) ? $errors : "OK";
105
    set_infos ( $version, $queries, $errors, $md5 );
165
    set_infos ( $version, $queries, $errors, $md5 );
106
107
    return $report;
166
    return $report;
108
}
167
}
109
168
169
=head2 list_versions_availables
170
171
  my @versions = list_versions_availables;
172
  return an array with all version available 
173
  This list is retrieved from the directory defined in the etc/update/database/config.yaml, versions_dir parameter
174
175
=cut
176
110
sub list_versions_availables {
177
sub list_versions_availables {
111
    my @versions;
178
    my @versions;
112
    opendir DH, $VERSIONS_PATH or die "Cannot open directory ($!)";
179
    opendir DH, $VERSIONS_PATH or die "Cannot open directory ($!)";
Lines 120-156 sub list_versions_availables { Link Here
120
    return \@versions;
187
    return \@versions;
121
}
188
}
122
189
190
=head2 list_versions_already_knows
191
192
  my @versions = list_versions_availables;
193
  return an array with all version that have already been applied
194
  This sub check first that the updatedb tables exist and create them if needed
195
196
=cut
197
123
sub list_versions_already_knows {
198
sub list_versions_already_knows {
199
    # 1st check if tables exist, otherwise create them
200
        $dbh->do(qq{
201
                CREATE TABLE IF NOT EXISTS `updatedb_error` ( `version` varchar(32) DEFAULT NULL, `error` text ) ENGINE=InnoDB CHARSET=utf8;
202
        });
203
            $dbh->do(qq{
204
            CREATE TABLE  IF NOT EXISTS `updatedb_query` ( `version` varchar(32) DEFAULT NULL, `query` text ) ENGINE=InnoDB CHARSET=utf8;
205
        });
206
        $dbh->do(qq{
207
            CREATE TABLE  IF NOT EXISTS `updatedb_report` ( `version` text, `md5` varchar(50) DEFAULT NULL, `comment` text, `status` int(1) DEFAULT NULL ) ENGINE=InnoDB CHARSET=utf8;
208
        });
209
    
124
    my $query = qq/ SELECT version, comment, status FROM updatedb_report /;
210
    my $query = qq/ SELECT version, comment, status FROM updatedb_report /;
125
    my $sth = $dbh->prepare( $query );
211
    my $sth = $dbh->prepare( $query );
126
    $sth->execute;
212
    $sth->execute;
127
    my $versions = $sth->fetchall_arrayref( {} );
213
    my $versions = $sth->fetchall_arrayref( {} );
128
    map {
214
    map {
129
        my $version = $_;
215
        my $version = $_;
130
        my @comments = defined $$_{comment} ? split '\\\n', $$_{comment} : "";
216
        my @comments = defined $_->{comment} ? split '\\\n', $_->{comment} : "";
131
        push @{ $$version{comments} }, { comment => $_ } for @comments;
217
        push @{ $version->{comments} }, { comment => $_ } for @comments;
132
        delete $$version{comment};
218
        delete $version->{comment};
133
    } @$versions;
219
    } @$versions;
134
    $sth->finish;
220
    $sth->finish;
135
    for my $version ( @$versions ) {
221
    for my $version ( @$versions ) {
136
        $query = qq/ SELECT query FROM updatedb_query WHERE version = ? /;
222
        $query = qq/ SELECT query FROM updatedb_query WHERE version = ? /;
137
        $sth = $dbh->prepare( $query );
223
        $sth = $dbh->prepare( $query );
138
        $sth->execute( $$version{version} );
224
        $sth->execute( $version->{version} );
139
        $$version{queries} = $sth->fetchall_arrayref( {} );
225
        $version->{queries} = $sth->fetchall_arrayref( {} );
140
        $sth->finish;
226
        $sth->finish;
141
        $query = qq/ SELECT error FROM updatedb_error WHERE version = ? /;
227
        $query = qq/ SELECT error FROM updatedb_error WHERE version = ? /;
142
        $sth = $dbh->prepare( $query );
228
        $sth = $dbh->prepare( $query );
143
        $sth->execute( $$version{version} );
229
        $sth->execute( $version->{version} );
144
        $$version{errors} = $sth->fetchall_arrayref( {} );
230
        $version->{errors} = $sth->fetchall_arrayref( {} );
145
        $sth->finish;
231
        $sth->finish;
146
    }
232
    }
147
    return $versions;
233
    return $versions;
148
}
234
}
149
235
236
=head2 execute
237
238
  my @errors = $execute(\@queries);
239
  This sub will execute queries coming from an execute_version based on a .sql file
240
  
241
=cut
242
150
sub execute {
243
sub execute {
151
    my ( $queries ) = @_;
244
    my ( $queries ) = @_;
152
    my @errors;
245
    my @errors;
153
    for my $query ( @{$$queries{queries}} ) {
246
    for my $query ( @{$queries->{queries}} ) {
154
        eval {
247
        eval {
155
            $dbh->do( $query );
248
            $dbh->do( $query );
156
        };
249
        };
Lines 159-164 sub execute { Link Here
159
    return \@errors;
252
    return \@errors;
160
}
253
}
161
254
255
=head2 get_tables_name
256
257
  my $tables = get_tables_name;
258
  return an array with all Koha mySQL table names
259
260
=cut
261
162
sub get_tables_name {
262
sub get_tables_name {
163
    my $sth = $dbh->prepare("SHOW TABLES");
263
    my $sth = $dbh->prepare("SHOW TABLES");
164
    $sth->execute();
264
    $sth->execute();
Lines 169-174 sub get_tables_name { Link Here
169
    return \@tables;
269
    return \@tables;
170
}
270
}
171
my $tables;
271
my $tables;
272
273
=head2 check_coherency
274
275
  my $errors = check_coherency($query);
276
  This sub will try to check if a SQL query is useless or no.
277
  for queries that are CREATE TABLE, it will check if the table already exists
278
  for queries that are ALTER TABLE, it will search if the modification has already been made
279
  for queries that are INSERT, it will search if the insert has already been made if it's a syspref or a permission
280
  
281
  Those test cover 90% of the updatedatabases cases. That will help finding duplicate or inconsistencies
282
283
=cut
284
172
sub check_coherency {
285
sub check_coherency {
173
    my ( $query ) = @_;
286
    my ( $query ) = @_;
174
    $tables = get_tables_name() if not $tables;
287
    $tables = get_tables_name() if not $tables;
Lines 226-231 sub check_coherency { Link Here
226
    return 1;
339
    return 1;
227
}
340
}
228
341
342
=head2 get_error
343
344
  my $errors = get_error()
345
  This sub will return any mySQL error that occured during an update
346
347
=cut
348
229
sub get_error {
349
sub get_error {
230
    my @errors = $dbh->selectrow_array(qq{SHOW ERRORS}); # Get errors
350
    my @errors = $dbh->selectrow_array(qq{SHOW ERRORS}); # Get errors
231
    my @warnings = $dbh->selectrow_array(qq{SHOW WARNINGS}); # Get warnings
351
    my @warnings = $dbh->selectrow_array(qq{SHOW WARNINGS}); # Get warnings
Lines 238-243 sub get_error { Link Here
238
    return;
358
    return;
239
}
359
}
240
360
361
=head2
362
363
  my $result = get_queries($filepath);
364
  this sub will return a hashref with 2 entries:
365
    $result->{queries} is an array with all queries to execute
366
    $result->{comments} is an array with all comments in the .sql file
367
368
=cut
369
241
sub get_queries {
370
sub get_queries {
242
    my ( $filepath ) = @_;
371
    my ( $filepath ) = @_;
243
    open my $fh, "<", $filepath;
372
    open my $fh, "<", $filepath;
Lines 265-270 sub get_queries { Link Here
265
    return { queries => \@queries, comments => \@comments };
394
    return { queries => \@queries, comments => \@comments };
266
}
395
}
267
396
397
=head2 md5_already_exists
398
399
  my $result = md5_already_exists($md5);
400
  check if the md5 of an update has already been applied on the database.
401
  If yes, it will return a hash with the version related to this md5
402
403
=cut
404
268
sub md5_already_exists {
405
sub md5_already_exists {
269
    my ( $md5 ) = @_;
406
    my ( $md5 ) = @_;
270
    my $query = qq/SELECT version, md5 FROM updatedb_report WHERE md5 = ?/;
407
    my $query = qq/SELECT version, md5 FROM updatedb_report WHERE md5 = ?/;
Lines 278-287 sub md5_already_exists { Link Here
278
    return \@r;
415
    return \@r;
279
}
416
}
280
417
418
=head2 set_infos
419
420
  set_info($version,$queries, $error, $md5);
421
  this sub will insert into the updatedb tables what has been made on the database (queries, errors, result)
422
423
=cut
281
sub set_infos {
424
sub set_infos {
282
    my ( $version, $queries, $errors, $md5 ) = @_;
425
    my ( $version, $queries, $errors, $md5 ) = @_;
283
    #SetVersion($DBversion) if not -s $errors;
426
    #SetVersion($DBversion) if not -s $errors;
284
    for my $query ( @{ $$queries{queries} } ) {
427
    for my $query ( @{ $queries->{queries} } ) {
285
        my $sth = $dbh->prepare("INSERT INTO updatedb_query(version, query) VALUES (?, ?)");
428
        my $sth = $dbh->prepare("INSERT INTO updatedb_query(version, query) VALUES (?, ?)");
286
        $sth->execute( $version, $query );
429
        $sth->execute( $version, $query );
287
        $sth->finish;
430
        $sth->finish;
Lines 294-304 sub set_infos { Link Here
294
    $sth->execute(
437
    $sth->execute(
295
        $version,
438
        $version,
296
        $md5,
439
        $md5,
297
        join ('\n', @{ $$queries{comments} }),
440
        join ('\n', @{ $queries->{comments} }),
298
        ( @$errors > 0 ) ? 0 : 1
441
        ( @$errors > 0 ) ? 0 : 1
299
    );
442
    );
300
}
443
}
301
444
445
=head2 mark_as_ok
446
  
447
  $mark_as_ok($version);
448
  this sub will force to mark as "OK" an update that has failed
449
  once this has been made, the status will look as "forced OK", and appear in green like versions that have been applied without any problem
450
  
451
=cut
302
sub mark_as_ok {
452
sub mark_as_ok {
303
    my ( $version ) = @_;
453
    my ( $version ) = @_;
304
    my $sth = $dbh->prepare( "UPDATE updatedb_report SET status = 2 WHERE version=?" );
454
    my $sth = $dbh->prepare( "UPDATE updatedb_report SET status = 2 WHERE version=?" );
Lines 308-314 sub mark_as_ok { Link Here
308
        my $filepath = get_filepath $version;
458
        my $filepath = get_filepath $version;
309
        my $queries = get_queries $filepath;
459
        my $queries = get_queries $filepath;
310
        my $errors;
460
        my $errors;
311
        for my $query ( @{$$queries{queries}} ) {
461
        for my $query ( @{$queries->{queries}} ) {
312
            eval {
462
            eval {
313
                check_coherency( $query );
463
                check_coherency( $query );
314
            };
464
            };
Lines 326-335 sub mark_as_ok { Link Here
326
    $sth->finish;
476
    $sth->finish;
327
}
477
}
328
478
329
=item TransformToNum
479
=head2 TransformToNum
330
480
331
  Transform the Koha version from a 4 parts string
481
  Transform the Koha version from a 4 parts string
332
  to a number, with just 1 .
482
  to a number, with just 1 . (ie: it's a number)
333
483
334
=cut
484
=cut
335
485
(-)a/about.pl (-1 / +1 lines)
Lines 45-51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
45
    }
45
    }
46
);
46
);
47
47
48
my $kohaVersion   = C4::Context::KOHAVERSION;
48
my $kohaVersion   = C4::Context->preference("Version");
49
my $osVersion     = `uname -a`;
49
my $osVersion     = `uname -a`;
50
my $perl_path = $^X;
50
my $perl_path = $^X;
51
if ($^O ne 'VMS') {
51
if ($^O ne 'VMS') {
(-)a/installer/data/mysql/kohastructure.sql (+21 lines)
Lines 1955-1960 CREATE TABLE `tags_index` ( Link Here
1955
        REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1955
        REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1956
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1956
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1957
1957
1958
1959
--
1960
-- Table structure for database updates
1961
--
1962
CREATE TABLE`updatedb_error` (
1963
    `version` varchar(32) DEFAULT NULL,
1964
    `error` text
1965
) ENGINE=InnoDB CHARSET=utf8;
1966
1967
CREATE TABLE `updatedb_query` (
1968
    `version` varchar(32) DEFAULT NULL,
1969
    `query` text
1970
) ENGINE=InnoDB CHARSET=utf8;
1971
1972
CREATE TABLE `updatedb_report` ( 
1973
    `version` text,
1974
    `md5` varchar(50) DEFAULT NULL,
1975
    `comment` text,
1976
    `status` int(1) DEFAULT NULL
1977
) ENGINE=InnoDB CHARSET=utf8;
1978
1958
--
1979
--
1959
-- Table structure for table `userflags`
1980
-- Table structure for table `userflags`
1960
--
1981
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt (-1 / +1 lines)
Lines 35-41 Link Here
35
            
35
            
36
        <table>
36
        <table>
37
            <caption>Server information</caption>
37
            <caption>Server information</caption>
38
            <tr><th scope="row">Koha version: </th><td>[% kohaVersion |html %]</td></tr>
38
            <tr><th scope="row">Koha version: </th><td>[% kohaVersion |html %] (IMPORTANT: this number is the number of the highest update added. Since Koha 3.8, updates are non-linear. Go to admin section to check if every update has been added)</td></tr>
39
            <tr><th scope="row">OS version ('uname -a'): </th><td>[% osVersion |html %]</td></tr>
39
            <tr><th scope="row">OS version ('uname -a'): </th><td>[% osVersion |html %]</td></tr>
40
            <tr><th scope="row">Perl interpreter: </th><td>[% perlPath |html %]</td></tr>
40
            <tr><th scope="row">Perl interpreter: </th><td>[% perlPath |html %]</td></tr>
41
            <tr><th scope="row">Perl version: </th><td>[% perlVersion |html %]</td></tr>
41
            <tr><th scope="row">Perl version: </th><td>[% perlVersion |html %]</td></tr>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt (-2 / +1 lines)
Lines 57-63 Link Here
57
                    [% r.error %];
57
                    [% r.error %];
58
                [% END %]
58
                [% END %]
59
                [% IF report_loo.coherency %]
59
                [% IF report_loo.coherency %]
60
                    [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% version %]">Mark as OK</a>]
60
                    [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% report_loo.version %]">Mark as OK</a>]
61
                [% END %]
61
                [% END %]
62
            </li>
62
            </li>
63
        [% END %]
63
        [% END %]
64
- 

Return to bug 7167