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 (-1 / +10 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-472 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
471
    my $versions = C4::Update::Database::list_versions_availables();
472
    for my $v ( @$versions ) {
473
        my $queries;
474
        $queries->{queries} = ["initial setup"];
475
        $queries->{comments} = ["initial setup"];
476
        C4::Update::Database::set_infos($v,$queries,undef,undef);
477
    }
478
    # mark the "old" 3.6 version number
470
    my $kohaversion=C4::Context::KOHAVERSION;
479
    my $kohaversion=C4::Context::KOHAVERSION;
471
    # remove the 3 last . to have a Perl number
480
    # remove the 3 last . to have a Perl number
472
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
481
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
(-)a/C4/Update/Database.pm (-23 / +168 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
    }
83
138
84
    return $report
139
    return $report
85
        if ( defined $$report{$version} );
140
        if ( defined $report->{$version} );
86
141
87
    my $errors;
142
    my $errors;
88
    for my $query ( @{$$queries{queries}} ) {
143
    for my $query ( @{$queries->{queries}} ) {
89
        eval {
144
        eval {
90
            check_coherency( $query );
145
            check_coherency( $query );
91
        };
146
        };
Lines 96-112 sub execute_version { Link Here
96
151
97
    if ( $errors ) {
152
    if ( $errors ) {
98
        $_ =~ s/at [^ ]* line \d*\.$// for @$errors;
153
        $_ =~ s/at [^ ]* line \d*\.$// for @$errors;
99
        $$report{$version} = $errors;
154
        $report->{$version} = $errors;
100
        return $report;
155
        return $report;
101
    }
156
    }
102
157
103
    $errors = execute ( $queries );
158
    $errors = execute ( $queries );
104
    $$report{$version} = scalar( @$errors ) ? $errors : "OK";
159
    $report->{$version} = scalar( @$errors ) ? $errors : "OK";
105
    set_infos ( $version, $queries, $errors, $md5 );
160
    set_infos ( $version, $queries, $errors, $md5 );
106
107
    return $report;
161
    return $report;
108
}
162
}
109
163
164
=head2 list_versions_availables
165
166
  my @versions = list_versions_availables;
167
  return an array with all version available 
168
  This list is retrieved from the directory defined in the etc/update/database/config.yaml, versions_dir parameter
169
170
=cut
171
110
sub list_versions_availables {
172
sub list_versions_availables {
111
    my @versions;
173
    my @versions;
112
    opendir DH, $VERSIONS_PATH or die "Cannot open directory ($!)";
174
    opendir DH, $VERSIONS_PATH or die "Cannot open directory ($!)";
Lines 120-156 sub list_versions_availables { Link Here
120
    return \@versions;
182
    return \@versions;
121
}
183
}
122
184
185
=head2 list_versions_already_knows
186
187
  my @versions = list_versions_availables;
188
  return an array with all version that have already been applied
189
  This sub check first that the updatedb tables exist and create them if needed
190
191
=cut
192
123
sub list_versions_already_knows {
193
sub list_versions_already_knows {
194
    # 1st check if tables exist, otherwise create them
195
        $dbh->do(qq{
196
                CREATE TABLE IF NOT EXISTS `updatedb_error` ( `version` varchar(32) DEFAULT NULL, `error` text ) ENGINE=InnoDB CHARSET=utf8;
197
        });
198
            $dbh->do(qq{
199
            CREATE TABLE  IF NOT EXISTS `updatedb_query` ( `version` varchar(32) DEFAULT NULL, `query` text ) ENGINE=InnoDB CHARSET=utf8;
200
        });
201
        $dbh->do(qq{
202
            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;
203
        });
204
    
124
    my $query = qq/ SELECT version, comment, status FROM updatedb_report /;
205
    my $query = qq/ SELECT version, comment, status FROM updatedb_report /;
125
    my $sth = $dbh->prepare( $query );
206
    my $sth = $dbh->prepare( $query );
126
    $sth->execute;
207
    $sth->execute;
127
    my $versions = $sth->fetchall_arrayref( {} );
208
    my $versions = $sth->fetchall_arrayref( {} );
128
    map {
209
    map {
129
        my $version = $_;
210
        my $version = $_;
130
        my @comments = defined $$_{comment} ? split '\\\n', $$_{comment} : "";
211
        my @comments = defined $_->{comment} ? split '\\\n', $_->{comment} : "";
131
        push @{ $$version{comments} }, { comment => $_ } for @comments;
212
        push @{ $version->{comments} }, { comment => $_ } for @comments;
132
        delete $$version{comment};
213
        delete $version->{comment};
133
    } @$versions;
214
    } @$versions;
134
    $sth->finish;
215
    $sth->finish;
135
    for my $version ( @$versions ) {
216
    for my $version ( @$versions ) {
136
        $query = qq/ SELECT query FROM updatedb_query WHERE version = ? /;
217
        $query = qq/ SELECT query FROM updatedb_query WHERE version = ? /;
137
        $sth = $dbh->prepare( $query );
218
        $sth = $dbh->prepare( $query );
138
        $sth->execute( $$version{version} );
219
        $sth->execute( $version->{version} );
139
        $$version{queries} = $sth->fetchall_arrayref( {} );
220
        $version->{queries} = $sth->fetchall_arrayref( {} );
140
        $sth->finish;
221
        $sth->finish;
141
        $query = qq/ SELECT error FROM updatedb_error WHERE version = ? /;
222
        $query = qq/ SELECT error FROM updatedb_error WHERE version = ? /;
142
        $sth = $dbh->prepare( $query );
223
        $sth = $dbh->prepare( $query );
143
        $sth->execute( $$version{version} );
224
        $sth->execute( $version->{version} );
144
        $$version{errors} = $sth->fetchall_arrayref( {} );
225
        $version->{errors} = $sth->fetchall_arrayref( {} );
145
        $sth->finish;
226
        $sth->finish;
146
    }
227
    }
147
    return $versions;
228
    return $versions;
148
}
229
}
149
230
231
=head2 execute
232
233
  my @errors = $execute(\@queries);
234
  This sub will execute queries coming from an execute_version based on a .sql file
235
  
236
=cut
237
150
sub execute {
238
sub execute {
151
    my ( $queries ) = @_;
239
    my ( $queries ) = @_;
152
    my @errors;
240
    my @errors;
153
    for my $query ( @{$$queries{queries}} ) {
241
    for my $query ( @{$queries->{queries}} ) {
154
        eval {
242
        eval {
155
            $dbh->do( $query );
243
            $dbh->do( $query );
156
        };
244
        };
Lines 159-164 sub execute { Link Here
159
    return \@errors;
247
    return \@errors;
160
}
248
}
161
249
250
=head2 get_tables_name
251
252
  my $tables = get_tables_name;
253
  return an array with all Koha mySQL table names
254
255
=cut
256
162
sub get_tables_name {
257
sub get_tables_name {
163
    my $sth = $dbh->prepare("SHOW TABLES");
258
    my $sth = $dbh->prepare("SHOW TABLES");
164
    $sth->execute();
259
    $sth->execute();
Lines 169-174 sub get_tables_name { Link Here
169
    return \@tables;
264
    return \@tables;
170
}
265
}
171
my $tables;
266
my $tables;
267
268
=head2 check_coherency
269
270
  my $errors = check_coherency($query);
271
  This sub will try to check if a SQL query is useless or no.
272
  for queries that are CREATE TABLE, it will check if the table already exists
273
  for queries that are ALTER TABLE, it will search if the modification has already been made
274
  for queries that are INSERT, it will search if the insert has already been made if it's a syspref or a permission
275
  
276
  Those test cover 90% of the updatedatabases cases. That will help finding duplicate or inconsistencies
277
278
=cut
279
172
sub check_coherency {
280
sub check_coherency {
173
    my ( $query ) = @_;
281
    my ( $query ) = @_;
174
    $tables = get_tables_name() if not $tables;
282
    $tables = get_tables_name() if not $tables;
Lines 226-231 sub check_coherency { Link Here
226
    return 1;
334
    return 1;
227
}
335
}
228
336
337
=head2 get_error
338
339
  my $errors = get_error()
340
  This sub will return any mySQL error that occured during an update
341
342
=cut
343
229
sub get_error {
344
sub get_error {
230
    my @errors = $dbh->selectrow_array(qq{SHOW ERRORS}); # Get errors
345
    my @errors = $dbh->selectrow_array(qq{SHOW ERRORS}); # Get errors
231
    my @warnings = $dbh->selectrow_array(qq{SHOW WARNINGS}); # Get warnings
346
    my @warnings = $dbh->selectrow_array(qq{SHOW WARNINGS}); # Get warnings
Lines 238-243 sub get_error { Link Here
238
    return;
353
    return;
239
}
354
}
240
355
356
=head2
357
358
  my $result = get_queries($filepath);
359
  this sub will return a hashref with 2 entries:
360
    $result->{queries} is an array with all queries to execute
361
    $result->{comments} is an array with all comments in the .sql file
362
363
=cut
364
241
sub get_queries {
365
sub get_queries {
242
    my ( $filepath ) = @_;
366
    my ( $filepath ) = @_;
243
    open my $fh, "<", $filepath;
367
    open my $fh, "<", $filepath;
Lines 265-270 sub get_queries { Link Here
265
    return { queries => \@queries, comments => \@comments };
389
    return { queries => \@queries, comments => \@comments };
266
}
390
}
267
391
392
=head2 md5_already_exists
393
394
  my $result = md5_already_exists($md5);
395
  check if the md5 of an update has already been applied on the database.
396
  If yes, it will return a hash with the version related to this md5
397
398
=cut
399
268
sub md5_already_exists {
400
sub md5_already_exists {
269
    my ( $md5 ) = @_;
401
    my ( $md5 ) = @_;
270
    my $query = qq/SELECT version, md5 FROM updatedb_report WHERE md5 = ?/;
402
    my $query = qq/SELECT version, md5 FROM updatedb_report WHERE md5 = ?/;
Lines 278-287 sub md5_already_exists { Link Here
278
    return \@r;
410
    return \@r;
279
}
411
}
280
412
413
=head2 set_infos
414
415
  set_info($version,$queries, $error, $md5);
416
  this sub will insert into the updatedb tables what has been made on the database (queries, errors, result)
417
418
=cut
281
sub set_infos {
419
sub set_infos {
282
    my ( $version, $queries, $errors, $md5 ) = @_;
420
    my ( $version, $queries, $errors, $md5 ) = @_;
283
    #SetVersion($DBversion) if not -s $errors;
421
    #SetVersion($DBversion) if not -s $errors;
284
    for my $query ( @{ $$queries{queries} } ) {
422
    for my $query ( @{ $queries->{queries} } ) {
285
        my $sth = $dbh->prepare("INSERT INTO updatedb_query(version, query) VALUES (?, ?)");
423
        my $sth = $dbh->prepare("INSERT INTO updatedb_query(version, query) VALUES (?, ?)");
286
        $sth->execute( $version, $query );
424
        $sth->execute( $version, $query );
287
        $sth->finish;
425
        $sth->finish;
Lines 294-304 sub set_infos { Link Here
294
    $sth->execute(
432
    $sth->execute(
295
        $version,
433
        $version,
296
        $md5,
434
        $md5,
297
        join ('\n', @{ $$queries{comments} }),
435
        join ('\n', @{ $queries->{comments} }),
298
        ( @$errors > 0 ) ? 0 : 1
436
        ( @$errors > 0 ) ? 0 : 1
299
    );
437
    );
300
}
438
}
301
439
440
=head2 mark_as_ok
441
  
442
  $mark_as_ok($version);
443
  this sub will force to mark as "OK" an update that has failed
444
  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
445
  
446
=cut
302
sub mark_as_ok {
447
sub mark_as_ok {
303
    my ( $version ) = @_;
448
    my ( $version ) = @_;
304
    my $sth = $dbh->prepare( "UPDATE updatedb_report SET status = 2 WHERE version=?" );
449
    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;
453
        my $filepath = get_filepath $version;
309
        my $queries = get_queries $filepath;
454
        my $queries = get_queries $filepath;
310
        my $errors;
455
        my $errors;
311
        for my $query ( @{$$queries{queries}} ) {
456
        for my $query ( @{$queries->{queries}} ) {
312
            eval {
457
            eval {
313
                check_coherency( $query );
458
                check_coherency( $query );
314
            };
459
            };
Lines 326-335 sub mark_as_ok { Link Here
326
    $sth->finish;
471
    $sth->finish;
327
}
472
}
328
473
329
=item TransformToNum
474
=head2 TransformToNum
330
475
331
  Transform the Koha version from a 4 parts string
476
  Transform the Koha version from a 4 parts string
332
  to a number, with just 1 .
477
  to a number, with just 1 . (ie: it's a number)
333
478
334
=cut
479
=cut
335
480
(-)a/about.pl (-1 / +8 lines)
Lines 32-37 use C4::Output; Link Here
32
use C4::Auth;
32
use C4::Auth;
33
use C4::Context;
33
use C4::Context;
34
use C4::Installer;
34
use C4::Installer;
35
use C4::Update::Database;
35
36
36
my $query = new CGI;
37
my $query = new CGI;
37
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 45-51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
45
    }
46
    }
46
);
47
);
47
48
48
my $kohaVersion   = C4::Context::KOHAVERSION;
49
my $kohaVersion   = C4::Context->preference("Version");
50
# the $kohaVersion is duplicated since 3.7: the 3.6 (that uses the old mechanism) and the 3.7 (new mechanism). 
51
# Both versions reflects how the database has been upgraded
52
my $already_knows = C4::Update::Database::list_versions_already_knows();
53
for my $v ( @$already_knows ) {
54
        $kohaVersion .= " / ".$v->{version};
55
}
49
my $osVersion     = `uname -a`;
56
my $osVersion     = `uname -a`;
50
my $perl_path = $^X;
57
my $perl_path = $^X;
51
if ($^O ne 'VMS') {
58
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/installer/data/mysql/updatedatabase.pl (-15 lines)
Lines 4550-4570 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
4550
    SetVersion ($DBversion);
4550
    SetVersion ($DBversion);
4551
}
4551
}
4552
4552
4553
$DBversion = "3.06.00.XXX";
4554
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4555
    $dbh->do(qq{
4556
        CREATE TABLE `updatedb_error` ( `version` varchar(32) DEFAULT NULL, `error` text ) ENGINE=InnoDB CHARSET=utf8;
4557
    });
4558
    $dbh->do(qq{
4559
        CREATE TABLE `updatedb_query` ( `version` varchar(32) DEFAULT NULL, `query` text ) ENGINE=InnoDB CHARSET=utf8;
4560
    });
4561
    $dbh->do(qq{
4562
        CREATE TABLE `updatedb_report` ( `version` text, `md5` varchar(50) DEFAULT NULL, `comment` text, `status` int(1) DEFAULT NULL ) ENGINE=InnoDB CHARSET=utf8;
4563
    });
4564
    print "Upgrade to $DBversion done (Add tables for new updatedatabase version)\n";
4565
    SetVersion ($DBversion);
4566
}
4567
4568
=head1 FUNCTIONS
4553
=head1 FUNCTIONS
4569
4554
4570
=head2 DropAllForeignKeys($table)
4555
=head2 DropAllForeignKeys($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt (-2 / +2 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 %]
Lines 88-94 Link Here
88
                <td>[% v.version %]</td>
88
                <td>[% v.version %]</td>
89
                <td>
89
                <td>
90
                    <ul class="comments">
90
                    <ul class="comments">
91
                    [% FOREACH c IN comments %]
91
                    [% FOREACH c IN v.comments %]
92
                        <li>[% c.comment %]</li>
92
                        <li>[% c.comment %]</li>
93
                    [% END %]
93
                    [% END %]
94
                    </ul>
94
                    </ul>
(-)a/mainpage.pl (-1 / +26 lines)
Lines 27-32 use C4::Auth; Link Here
27
use C4::AuthoritiesMarc;
27
use C4::AuthoritiesMarc;
28
use C4::Koha;
28
use C4::Koha;
29
use C4::NewsChannels;
29
use C4::NewsChannels;
30
use C4::Update::Database;
31
30
my $query     = new CGI;
32
my $query     = new CGI;
31
my $authtypes = getauthtypes;
33
my $authtypes = getauthtypes;
32
my @authtypesloop;
34
my @authtypesloop;
Lines 55-60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
55
    }
57
    }
56
);
58
);
57
59
60
#
61
# check if you're uptodate, and if you're not, head to updater
62
#
63
my $koha36= C4::Context::KOHAVERSION;
64
$koha36 =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
65
66
if (C4::Context->preference('Version') < $koha36) {
67
    print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3");
68
    exit;
69
} 
70
my $versions_availables = C4::Update::Database::list_versions_availables;
71
my $versions = C4::Update::Database::list_versions_already_knows;
72
my $uptodate=1;
73
for my $v ( @$versions_availables ) {
74
    if ( not grep { $v eq $$_{version} } @$versions ) {
75
        $uptodate=0;
76
    }
77
}
78
unless ($uptodate) {
79
    # not uptodate, redirect to updatedatabase page
80
    print $query->redirect("/cgi-bin/koha/admin/updatedatabase.pl");
81
    exit;
82
}
83
58
$template->param(
84
$template->param(
59
    authtypesloop => \@authtypesloop
85
    authtypesloop => \@authtypesloop
60
);
86
);
61
- 

Return to bug 7167