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

(-)a/C4/Auth.pm (-67 / +40 lines)
Lines 28-33 require Exporter; Link Here
28
use C4::Context;
28
use C4::Context;
29
use C4::Templates;    # to get the template
29
use C4::Templates;    # to get the template
30
use C4::Branch; # GetBranches
30
use C4::Branch; # GetBranches
31
use C4::Update::Database;
31
use C4::VirtualShelves;
32
use C4::VirtualShelves;
32
use POSIX qw/strftime/;
33
use POSIX qw/strftime/;
33
use List::MoreUtils qw/ any /;
34
use List::MoreUtils qw/ any /;
Lines 133-141 sub get_template_and_user { Link Here
133
    my $in       = shift;
134
    my $in       = shift;
134
    my $template =
135
    my $template =
135
      C4::Templates::gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} );
136
      C4::Templates::gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} );
136
    my ( $user, $cookie, $sessionID, $flags );
137
    my ( $user, $cookie, $sessionID, $flags, $new_session );
137
    if ( $in->{'template_name'} !~m/maintenance/ ) {
138
    if ( $in->{'template_name'} !~m/maintenance/ ) {
138
        ( $user, $cookie, $sessionID, $flags ) = checkauth(
139
        ( $user, $cookie, $sessionID, $flags, $new_session ) = checkauth(
139
            $in->{'query'},
140
            $in->{'query'},
140
            $in->{'authnotrequired'},
141
            $in->{'authnotrequired'},
141
            $in->{'flagsrequired'},
142
            $in->{'flagsrequired'},
Lines 477-482 sub get_template_and_user { Link Here
477
478
478
        $template->param(OpacPublic => '1') if ($user || C4::Context->preference("OpacPublic"));
479
        $template->param(OpacPublic => '1') if ($user || C4::Context->preference("OpacPublic"));
479
    }
480
    }
481
482
    if ( $new_session ) {
483
        # Check the version and redirect if DB is not up-to-date
484
        version_check($in->{query}, $in->{'type'}, $cookie);
485
    }
486
480
    return ( $template, $borrowernumber, $cookie, $flags);
487
    return ( $template, $borrowernumber, $cookie, $flags);
481
}
488
}
482
489
Lines 558-611 has authenticated. Link Here
558
565
559
=cut
566
=cut
560
567
561
sub _version_check ($$) {
568
sub _session_log {
562
    my $type = shift;
569
    (@_) or return 0;
563
    my $query = shift;
570
    open L, ">>/tmp/sessionlog" or warn "ERROR: Cannot append to /tmp/sessionlog";
564
    my $version;
571
    printf L join("\n",@_);
565
    # If Version syspref is unavailable, it means Koha is beeing installed,
572
    close L;
566
    # and so we must redirect to OPAC maintenance page or to the WebInstaller
573
}
567
	# also, if OpacMaintenance is ON, OPAC should redirect to maintenance
574
568
	if (C4::Context->preference('OpacMaintenance') && $type eq 'opac') {
575
sub version_check {
569
        warn "OPAC Install required, redirecting to maintenance";
576
    my ( $query, $type, $cookie ) = @_;
570
        print $query->redirect("/cgi-bin/koha/maintenance.pl");
577
    # check we have a Version. Otherwise => go to installer
571
    }
578
    unless ( C4::Context->preference('Version') ) {
572
    unless ( $version = C4::Context->preference('Version') ) {    # assignment, not comparison
573
        if ( $type ne 'opac' ) {
579
        if ( $type ne 'opac' ) {
574
            warn "Install required, redirecting to Installer";
580
            $debug && warn "Install required, redirecting to Installer";
575
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
581
            print $query->redirect("/cgi-bin/koha/installer/install.pl");
576
        } else {
582
        } else {
577
            warn "OPAC Install required, redirecting to maintenance";
583
            $debug && warn "OPAC Install required, redirecting to maintenance";
578
            print $query->redirect("/cgi-bin/koha/maintenance.pl");
584
            print $query->redirect("/cgi-bin/koha/maintenance.pl");
579
        }
585
        }
580
        safe_exit;
586
        safe_exit;
581
    }
587
    }
582
588
583
    # check that database and koha version are the same
589
    # check if you're uptodate, and if you're not, head to updater
584
    # there is no DB version, it's a fresh install,
590
    my $koha39 = "3.0900026";
585
    # go to web installer
591
586
    # there is a DB version, compare it to the code version
592
    # Old updatedatabase method
587
    my $kohaversion=C4::Context::KOHAVERSION;
593
    if (C4::Context->preference('Version') < $koha39) {
588
    # remove the 3 last . to have a Perl number
594
        print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3");
589
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
590
    $debug and print STDERR "kohaversion : $kohaversion\n";
591
    if ($version < $kohaversion){
592
        my $warning = "Database update needed, redirecting to %s. Database is $version and Koha is $kohaversion";
593
        if ($type ne 'opac'){
594
            warn sprintf($warning, 'Installer');
595
            print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3");
596
        } else {
597
            warn sprintf("OPAC: " . $warning, 'maintenance');
598
            print $query->redirect("/cgi-bin/koha/maintenance.pl");
599
        }
600
        safe_exit;
595
        safe_exit;
601
    }
596
    }
602
}
603
597
604
sub _session_log {
598
    # New updatedatabase method
605
    (@_) or return 0;
599
    unless ( C4::Update::Database::is_uptodate() ) {
606
    open L, ">>/tmp/sessionlog" or warn "ERROR: Cannot append to /tmp/sessionlog";
600
        # not up-to-date, redirect to updatedatabase page
607
    printf L join("\n",@_);
601
        warn "redirect to updatedatabase";
608
    close L;
602
        print $query->redirect(-location => "/cgi-bin/koha/admin/updatedatabase.pl", -cookie => $cookie);
603
        safe_exit;
604
    }
609
}
605
}
610
606
611
sub checkauth {
607
sub checkauth {
Lines 616-621 sub checkauth { Link Here
616
    my $flagsrequired   = shift;
612
    my $flagsrequired   = shift;
617
    my $type            = shift;
613
    my $type            = shift;
618
    $type = 'opac' unless $type;
614
    $type = 'opac' unless $type;
615
    my $new_session = 0;
619
616
620
    my $dbh     = C4::Context->dbh;
617
    my $dbh     = C4::Context->dbh;
621
    my $timeout = C4::Context->preference('timeout');
618
    my $timeout = C4::Context->preference('timeout');
Lines 625-631 sub checkauth { Link Here
625
    };
622
    };
626
    $timeout = 600 unless $timeout;
623
    $timeout = 600 unless $timeout;
627
624
628
    _version_check($type,$query);
629
    # state variables
625
    # state variables
630
    my $loggedin = 0;
626
    my $loggedin = 0;
631
    my %info;
627
    my %info;
Lines 729-734 sub checkauth { Link Here
729
        my $sessionID = $session->id;
725
        my $sessionID = $session->id;
730
        C4::Context->_new_userenv($sessionID);
726
        C4::Context->_new_userenv($sessionID);
731
        $cookie = $query->cookie( CGISESSID => $sessionID );
727
        $cookie = $query->cookie( CGISESSID => $sessionID );
728
732
        $userid = $query->param('userid');
729
        $userid = $query->param('userid');
733
        if (   ( $cas && $query->param('ticket') )
730
        if (   ( $cas && $query->param('ticket') )
734
            || $userid
731
            || $userid
Lines 743-748 sub checkauth { Link Here
743
                  checkpw( $dbh, $userid, $password, $query );
740
                  checkpw( $dbh, $userid, $password, $query );
744
                $userid = $retuserid;
741
                $userid = $retuserid;
745
                $info{'invalidCasLogin'} = 1 unless ($return);
742
                $info{'invalidCasLogin'} = 1 unless ($return);
743
                $new_session = 1;
746
            }
744
            }
747
            elsif (
745
            elsif (
748
                ( $pki_field eq 'Common Name' && $ENV{'SSL_CLIENT_S_DN_CN'} )
746
                ( $pki_field eq 'Common Name' && $ENV{'SSL_CLIENT_S_DN_CN'} )
Lines 781-786 sub checkauth { Link Here
781
                ( $return, $cardnumber, $retuserid ) =
779
                ( $return, $cardnumber, $retuserid ) =
782
                  checkpw( $dbh, $userid, $password, $query );
780
                  checkpw( $dbh, $userid, $password, $query );
783
                $userid = $retuserid if ( $retuserid ne '' );
781
                $userid = $retuserid if ( $retuserid ne '' );
782
                $new_session = 1;
784
            }
783
            }
785
		if ($return) {
784
		if ($return) {
786
               #_session_log(sprintf "%20s from %16s logged in  at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime));
785
               #_session_log(sprintf "%20s from %16s logged in  at %30s.\n", $userid,$ENV{'REMOTE_ADDR'},(strftime '%c', localtime));
Lines 922-928 sub checkauth { Link Here
922
        unless ($cookie) {
921
        unless ($cookie) {
923
            $cookie = $query->cookie( CGISESSID => '' );
922
            $cookie = $query->cookie( CGISESSID => '' );
924
        }
923
        }
925
        return ( $userid, $cookie, $sessionID, $flags );
924
        return ( $userid, $cookie, $sessionID, $flags, $new_session );
926
    }
925
    }
927
926
928
#
927
#
Lines 1081-1099 sub check_api_auth { Link Here
1081
    my $timeout = C4::Context->preference('timeout');
1080
    my $timeout = C4::Context->preference('timeout');
1082
    $timeout = 600 unless $timeout;
1081
    $timeout = 600 unless $timeout;
1083
1082
1084
    unless (C4::Context->preference('Version')) {
1085
        # database has not been installed yet
1086
        return ("maintenance", undef, undef);
1087
    }
1088
    my $kohaversion=C4::Context::KOHAVERSION;
1089
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
1090
    if (C4::Context->preference('Version') < $kohaversion) {
1091
        # database in need of version update; assume that
1092
        # no API should be called while databsae is in
1093
        # this condition.
1094
        return ("maintenance", undef, undef);
1095
    }
1096
1097
    # FIXME -- most of what follows is a copy-and-paste
1083
    # FIXME -- most of what follows is a copy-and-paste
1098
    # of code from checkauth.  There is an obvious need
1084
    # of code from checkauth.  There is an obvious need
1099
    # for refactoring to separate the various parts of
1085
    # for refactoring to separate the various parts of
Lines 1314-1332 sub check_cookie_auth { Link Here
1314
    my $timeout = C4::Context->preference('timeout');
1300
    my $timeout = C4::Context->preference('timeout');
1315
    $timeout = 600 unless $timeout;
1301
    $timeout = 600 unless $timeout;
1316
1302
1317
    unless (C4::Context->preference('Version')) {
1318
        # database has not been installed yet
1319
        return ("maintenance", undef);
1320
    }
1321
    my $kohaversion=C4::Context::KOHAVERSION;
1322
    $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
1323
    if (C4::Context->preference('Version') < $kohaversion) {
1324
        # database in need of version update; assume that
1325
        # no API should be called while databsae is in
1326
        # this condition.
1327
        return ("maintenance", undef);
1328
    }
1329
1330
    # FIXME -- most of what follows is a copy-and-paste
1303
    # FIXME -- most of what follows is a copy-and-paste
1331
    # of code from checkauth.  There is an obvious need
1304
    # of code from checkauth.  There is an obvious need
1332
    # for refactoring to separate the various parts of
1305
    # for refactoring to separate the various parts of
(-)a/C4/Installer.pm (-1 / +10 lines)
Lines 23-28 use strict; Link Here
23
our $VERSION = 3.07.00.049;
23
our $VERSION = 3.07.00.049;
24
use C4::Context;
24
use C4::Context;
25
use C4::Installer::PerlModules;
25
use C4::Installer::PerlModules;
26
use C4::Update::Database;
26
27
27
=head1 NAME
28
=head1 NAME
28
29
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 (+545 lines)
Line 0 Link Here
1
package C4::Update::Database;
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
20
use Modern::Perl;
21
22
use C4::Context;
23
24
use File::Basename;
25
use File::Find::Rule;
26
use Digest::MD5;
27
use List::MoreUtils qw/uniq/;
28
use YAML;
29
30
=head1 NAME
31
32
C4::Update::Database.pm
33
34
=head1 SYNOPSIS
35
36
  use C4::Update::Database;
37
38
  This package is used by admin/updatedatabase.pl, to manage DB updates
39
40
=head1 FUNCTIONS
41
42
=cut
43
44
my $VERSIONS_PATH = C4::Context->config('intranetdir') . '/installer/data/mysql/versions';
45
46
my $version;
47
my $list;
48
49
my $dbh = C4::Context->dbh;
50
51
=head2
52
53
  my $file = get_filepath($version);
54
  this sub will return the full path of a given DB update number
55
56
=cut
57
58
sub get_filepath {
59
    my ( $version ) = @_;
60
    my @files = File::Find::Rule->file->name( "$version.sql", "$version.pl" ) ->in( ( $VERSIONS_PATH ) );
61
62
    if ( scalar @files != 1 ) {
63
        die "This version ($version) returned has ".scalar @files." corresponding, need only 1";
64
    }
65
66
    return $files[0];
67
}
68
69
=head2 get_md5
70
71
  my $md5 = get_md5($filepath)
72
  returns the md5sum of the selected file.
73
  This is used to check consistency of updates
74
75
=cut
76
sub get_md5 {
77
    my ( $filepath ) = @_;
78
    open(FILE, $filepath);
79
80
    my $ctx = Digest::MD5->new;
81
    $ctx->addfile(*FILE);
82
    my $md5 = $ctx->hexdigest;
83
    close(FILE);
84
    return $md5;
85
}
86
87
=head2 execute_version
88
89
  $result = execute_version($version_number);
90
  Execute an update.
91
  This sub will detect if the number is made through a .pl or a .sql, and behave accordingly
92
  if there is more than 1 file with the same number, an error will be issued
93
  if you try to execute a version_number that has already be executed, then it will also issue an error
94
  the sub return an result hash, with the version number and the result
95
96
=cut
97
98
sub execute_version {
99
    my ( $version ) = @_;
100
    my $report;
101
102
    my $filepath;
103
    eval {
104
        $filepath = get_filepath $version;
105
    };
106
    if ( $@ ) {
107
        return { $version => $@ };
108
    }
109
110
    my @file_infos = fileparse( $filepath, qr/\.[^.]*/ );
111
    my $extension = $file_infos[2];
112
    my $filename = $version . $extension;
113
114
    my $md5 = get_md5 $filepath;
115
    my $r = md5_already_exists( $md5 );
116
    if ( scalar @$r ) {
117
        my $p = @$r[0];
118
        $report->{$version} = {
119
            error => "ALREADY_EXISTS",
120
            filepath => $filepath,
121
            old_version => @$r[0]->{version},
122
            md5 => @$r[0]->{md5},
123
        };
124
        return $report;
125
    }
126
127
    my $queries;
128
    given ( $extension ) {
129
        when ( /.sql/ ) {
130
            $queries = get_queries ( $filepath );
131
        }
132
        when ( /.pl/ ) {
133
            unless(do $filepath) {
134
                $report->{$version} = {
135
                    error => "PERL_DBREV_FAILED",
136
                    filename => $filename,
137
                };
138
            }
139
        }
140
        default {
141
            $report->{$version} = {
142
                error => "BAD_EXTENSION",
143
                extension => $extension,
144
            };
145
        }
146
    }
147
148
    return $report
149
        if ( defined $report->{$version} );
150
151
    my $errors;
152
    for my $query ( @{$queries->{queries}} ) {
153
        eval {
154
            check_coherency( $query );
155
        };
156
        if ( $@ ) {
157
            push @$errors, $@
158
        }
159
    }
160
161
    if ( $errors ) {
162
        $_ =~ s/at [^ ]* line \d*\.$// for @$errors;
163
        $report->{$version} = $errors;
164
        return $report;
165
    }
166
167
    $errors = execute ( $queries ) if $queries;
168
    $report->{$version} = scalar( @$errors ) ? $errors : "OK";
169
    set_infos ( $version, $queries, $errors, $md5 );
170
    return $report;
171
}
172
173
=head2 list_versions_availables
174
175
  my @versions = list_versions_availables;
176
  return an array with all version available
177
  This list is retrieved from the directory defined in the etc/update/database/config.yaml, versions_dir parameter
178
179
=cut
180
181
sub list_versions_availables {
182
    my @versions;
183
184
    my @files = File::Find::Rule->file->name( "*.sql", "*.pl" ) ->in( ( $VERSIONS_PATH ) );
185
186
    for my $f ( @files ) {
187
        my @file_infos = fileparse( $f, qr/\.[^.]*/ );
188
        push @versions, $file_infos[0];
189
    }
190
    @versions = uniq @versions;
191
    return \@versions;
192
}
193
194
=head2 list_versions_already_knows
195
196
  my @versions = list_versions_availables;
197
  return an array with all version that have already been applied
198
  This sub check first that the updatedb tables exist and create them if needed
199
200
=cut
201
202
sub list_versions_already_knows {
203
    # 1st check if tables exist, otherwise create them
204
        $dbh->do(qq{
205
                CREATE TABLE IF NOT EXISTS `updatedb_error` ( `version` varchar(32) DEFAULT NULL, `error` text ) ENGINE=InnoDB CHARSET=utf8;
206
        });
207
            $dbh->do(qq{
208
            CREATE TABLE  IF NOT EXISTS `updatedb_query` ( `version` varchar(32) DEFAULT NULL, `query` text ) ENGINE=InnoDB CHARSET=utf8;
209
        });
210
        $dbh->do(qq{
211
            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;
212
        });
213
214
    my $query = qq/ SELECT version, comment, status FROM updatedb_report ORDER BY version/;
215
    my $sth = $dbh->prepare( $query );
216
    $sth->execute;
217
    my $versions = $sth->fetchall_arrayref( {} );
218
    map {
219
        my $version = $_;
220
        my @comments = defined $_->{comment} ? split '\\\n', $_->{comment} : "";
221
        push @{ $version->{comments} }, { comment => $_ } for @comments;
222
        delete $version->{comment};
223
    } @$versions;
224
    $sth->finish;
225
    for my $version ( @$versions ) {
226
        $query = qq/ SELECT query FROM updatedb_query WHERE version = ? ORDER BY version/;
227
        $sth = $dbh->prepare( $query );
228
        $sth->execute( $version->{version} );
229
        $version->{queries} = $sth->fetchall_arrayref( {} );
230
        $sth->finish;
231
        $query = qq/ SELECT error FROM updatedb_error WHERE version = ? ORDER BY version/;
232
        $sth = $dbh->prepare( $query );
233
        $sth->execute( $version->{version} );
234
        $version->{errors} = $sth->fetchall_arrayref( {} );
235
        $sth->finish;
236
    }
237
    return $versions;
238
}
239
240
=head2 execute
241
242
  my @errors = $execute(\@queries);
243
  This sub will execute queries coming from an execute_version based on a .sql file
244
245
=cut
246
247
sub execute {
248
    my ( $queries ) = @_;
249
    my @errors;
250
    for my $query ( @{$queries->{queries}} ) {
251
        eval {
252
            $dbh->do( $query );
253
        };
254
        push @errors, get_error();
255
    }
256
    return \@errors;
257
}
258
259
=head2 get_tables_name
260
261
  my $tables = get_tables_name;
262
  return an array with all Koha mySQL table names
263
264
=cut
265
266
sub get_tables_name {
267
    my $sth = $dbh->prepare("SHOW TABLES");
268
    $sth->execute();
269
    my @tables;
270
    while ( my ( $table ) = $sth->fetchrow_array ) {
271
        push @tables, $table;
272
    }
273
    return \@tables;
274
}
275
my $tables;
276
277
=head2 check_coherency
278
279
  my $errors = check_coherency($query);
280
  This sub will try to check if a SQL query is useless or no.
281
  for queries that are CREATE TABLE, it will check if the table already exists
282
  for queries that are ALTER TABLE, it will search if the modification has already been made
283
  for queries that are INSERT, it will search if the insert has already been made if it's a syspref or a permission
284
285
  Those test cover 90% of the updatedatabases cases. That will help finding duplicate or inconsistencies
286
287
=cut
288
289
sub check_coherency {
290
    my ( $query ) = @_;
291
    $tables = get_tables_name() if not $tables;
292
293
    given ( $query ) {
294
        when ( /CREATE TABLE(?:.*?)? `?(\w+)`?/ ) {
295
            my $table_name = $1;
296
            if ( grep { /$table_name/ } @$tables ) {
297
                die "COHERENCY: Table $table_name already exists";
298
            }
299
        }
300
301
        when ( /ALTER TABLE *`?(\w+)`? *ADD *(?:COLUMN)? `?(\w+)`?/ ) {
302
            my $table_name = $1;
303
            my $column_name = $2;
304
            next if $column_name =~ /(UNIQUE|CONSTRAINT|INDEX|KEY|FOREIGN)/;
305
            if ( not grep { /$table_name/ } @$tables ) {
306
                return "COHERENCY: Table $table_name does not exist";
307
            } else {
308
                my $sth = $dbh->prepare( "DESC $table_name $column_name" );
309
                my $rv = $sth->execute;
310
                if ( $rv > 0 ) {
311
                    die "COHERENCY: Field $table_name.$column_name already exists";
312
                }
313
            }
314
        }
315
316
        when ( /INSERT INTO `?(\w+)`?.*?VALUES *\((.*?)\)/ ) {
317
            my $table_name = $1;
318
            my @values = split /,/, $2;
319
            s/^ *'// foreach @values;
320
            s/' *$// foreach @values;
321
            given ( $table_name ) {
322
                when ( /systempreferences/ ) {
323
                    my $syspref = $values[0];
324
                    my $sth = $dbh->prepare( "SELECT COUNT(*) FROM systempreferences WHERE variable = ?" );
325
                    $sth->execute( $syspref );
326
                    if ( ( my $count = $sth->fetchrow_array ) > 0 ) {
327
                        die "COHERENCY: Syspref $syspref already exists";
328
                    }
329
                }
330
331
                when ( /permissions/){
332
                    my $module_bit = $values[0];
333
                    my $code = $values[1];
334
                    my $sth = $dbh->prepare( "SELECT COUNT(*) FROM permissions WHERE module_bit = ? AND code = ?" );
335
                    $sth->execute($module_bit, $code);
336
                    if ( ( my $count = $sth->fetchrow_array ) > 0 ) {
337
                        die "COHERENCY: Permission $code already exists";
338
                    }
339
                }
340
            }
341
        }
342
    }
343
    return 1;
344
}
345
346
=head2 get_error
347
348
  my $errors = get_error()
349
  This sub will return any mySQL error that occured during an update
350
351
=cut
352
353
sub get_error {
354
    my @errors = $dbh->selectrow_array(qq{SHOW ERRORS}); # Get errors
355
    my @warnings = $dbh->selectrow_array(qq{SHOW WARNINGS}); # Get warnings
356
    if ( @errors ) { # Catch specifics errors
357
        return qq{$errors[0] : $errors[1] => $errors[2]};
358
    } elsif ( @warnings ) {
359
        return qq{$warnings[0] : $warnings[1] => $warnings[2]}
360
            if $warnings[0] ne 'Note';
361
    }
362
    return;
363
}
364
365
=head2
366
367
  my $result = get_queries($filepath);
368
  this sub will return a hashref with 2 entries:
369
    $result->{queries} is an array with all queries to execute
370
    $result->{comments} is an array with all comments in the .sql file
371
372
=cut
373
374
sub get_queries {
375
    my ( $filepath ) = @_;
376
    open my $fh, "<", $filepath;
377
    my @queries;
378
    my @comments;
379
    my $old_delimiter = $/;
380
    while ( <$fh> ) {
381
        my $line = $_;
382
        chomp $line;
383
        $line =~ s/^\s*//;
384
        if ( $line =~ s/^--(.*)$// ) {
385
            push @comments, $1;
386
            next;
387
        }
388
        if ( $line =~ /^delimiter (.*)$/i ) {
389
            $/ = $1;
390
            next;
391
        }
392
        $line =~ s#$/##;
393
        push @queries, $line if not $line =~ /^\s*$/; # Push if query is not empty
394
    }
395
    $/ = $old_delimiter;
396
    close $fh;
397
398
    return { queries => \@queries, comments => \@comments };
399
}
400
401
=head2 md5_already_exists
402
403
  my $result = md5_already_exists($md5);
404
  check if the md5 of an update has already been applied on the database.
405
  If yes, it will return a hash with the version related to this md5
406
407
=cut
408
409
sub md5_already_exists {
410
    my ( $md5 ) = @_;
411
    my $query = qq/SELECT version, md5 FROM updatedb_report WHERE md5 = ?/;
412
    my $sth = $dbh->prepare( $query );
413
    $sth->execute( $md5 );
414
    my @r;
415
    while ( my ( $version, $md5 ) = $sth->fetchrow ) {
416
        push @r, { version => $version, md5 => $md5 };
417
    }
418
    $sth->finish;
419
    return \@r;
420
}
421
422
=head2 set_infos
423
424
  set_info($version,$queries, $error, $md5);
425
  this sub will insert into the updatedb tables what has been made on the database (queries, errors, result)
426
427
=cut
428
sub set_infos {
429
    my ( $version, $queries, $errors, $md5 ) = @_;
430
    SetVersion($version) if not -s $errors;
431
    for my $query ( @{ $queries->{queries} } ) {
432
        my $sth = $dbh->prepare("INSERT INTO updatedb_query(version, query) VALUES (?, ?)");
433
        $sth->execute( $version, $query );
434
        $sth->finish;
435
    }
436
    for my $error ( @$errors ) {
437
        my $sth = $dbh->prepare("INSERT INTO updatedb_error(version, error) VALUES (?, ?)");
438
        $sth->execute( $version, $error );
439
    }
440
    my $sth = $dbh->prepare("INSERT INTO updatedb_report(version, md5, comment, status) VALUES (?, ?, ?, ?)");
441
    $sth->execute(
442
        $version,
443
        $md5,
444
        $queries&&exists $queries->{comments}? join ('\n', @{ $queries->{comments} }):'',
445
        ( @$errors > 0 ) ? 0 : 1
446
    );
447
}
448
449
=head2 mark_as_ok
450
451
  mark_as_ok($version);
452
  this sub will force to mark as "OK" an update that has failed
453
  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
454
455
=cut
456
sub mark_as_ok {
457
    my ( $version ) = @_;
458
    my $sth = $dbh->prepare( "UPDATE updatedb_report SET status = 2 WHERE version=?" );
459
    my $affected = $sth->execute( $version );
460
    if ( $affected < 1 ) {
461
        # For "Coherency"
462
        my $filepath = get_filepath $version;
463
        my $queries = get_queries $filepath;
464
        my $errors;
465
        for my $query ( @{$queries->{queries}} ) {
466
            eval {
467
                check_coherency( $query );
468
            };
469
            if ( $@ ) {
470
                push @$errors, $@
471
            }
472
        }
473
474
        $_ =~ s/at [^ ]* line \d*\.$// for @$errors;
475
        my $md5 = get_md5 $filepath;
476
        set_infos $version, $queries, $errors, $md5;
477
478
        $sth->execute( $version );
479
    }
480
    $sth->finish;
481
}
482
483
=head2 is_uptodate
484
  is_uptodate();
485
  return 1 if the database is up to date else 0.
486
  The database is up to date if all versions are excecuted.
487
=cut
488
sub is_uptodate {
489
    my $versions_availables = C4::Update::Database::list_versions_availables;
490
    my $versions = C4::Update::Database::list_versions_already_knows;
491
    for my $v ( @$versions_availables ) {
492
        if ( not grep { $v eq $$_{version} } @$versions ) {
493
            return 0;
494
        }
495
    }
496
    return 1;
497
}
498
499
=head2 TransformToNum
500
501
  Transform the Koha version from a 4 parts string
502
  to a number, with just 1 . (ie: it's a number)
503
504
=cut
505
sub TransformToNum {
506
    my $version = shift;
507
508
    # remove the 3 last . to have a Perl number
509
    $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
510
    $version =~ s/Bug(\d+)/$1/;
511
    return $version;
512
}
513
514
sub SetVersion {
515
    my $new_version = TransformToNum(shift);
516
    my $current_version = TransformToNum( C4::Context->preference('Version') );
517
    unless ( C4::Context->preference('Version') ) {
518
        my $finish = $dbh->prepare(qq{
519
            INSERT IGNORE INTO systempreferences (variable,value,explanation)
520
            VALUES ('Version',?,'The Koha database version. WARNING: Do not change this value manually, it is maintained by the webinstaller')
521
        });
522
        $finish->execute($new_version);
523
        return;
524
    }
525
    if ( $new_version > $current_version ) {
526
        my $finish = $dbh->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
527
        $finish->execute($new_version);
528
    }
529
}
530
531
=head2 TableExists($table)
532
533
=cut
534
sub TableExists {
535
    my $table = shift;
536
    eval {
537
                local $dbh->{PrintError} = 0;
538
                local $dbh->{RaiseError} = 1;
539
                $dbh->do(qq{SELECT * FROM $table WHERE 1 = 0 });
540
            };
541
    return 1 unless $@;
542
    return 0;
543
}
544
545
1;
(-)a/about.pl (-1 / +41 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
#use Smart::Comments '####';
37
#use Smart::Comments '####';
37
38
Lines 47-53 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
47
    }
48
    }
48
);
49
);
49
50
50
my $kohaVersion   = C4::Context::KOHAVERSION;
51
my $kohaVersion   = C4::Context->preference("Version");
52
# restore ., for display consistency
53
$kohaVersion =~ /(.)\.(..)(..)(...)/;
54
# transform digits to Perl number, to display 3.6.1.2 instead of 3.06.01.002
55
$kohaVersion = ($1+0).".".($2+0).".".($3+0).".".($4+0);
56
57
my $dbrev_applied=""; # the list of database revisions
58
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
61
my $already_knows = C4::Update::Database::list_versions_already_knows();
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;
64
# $last_known_sep contains the previous DBrev applied with the separator (used for display)
65
my $last_known_sep="";
66
for my $v ( @$already_knows ) {
67
    my $current = $v->{version};
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
70
    # (instead of N / N+1 / N+2 / ...)
71
    if ($current==$last_known+1) {
72
        $dbrev_applied.=".";
73
    } else { # we're not N+1, start a new range
74
        # if version don't end by a ., no need to add the current loop number
75
        # this avoid having N...N (in case of an isolated BDrev number)
76
        if ($last_known & $dbrev_applied =~ /\.$/) {
77
            $dbrev_applied .= "...".$last_known_sep;
78
        }
79
        # start a new range
80
        $dbrev_applied .= " ".$v->{version};
81
    }
82
    $last_known= $current;
83
    $last_known_sep=$v->{version};
84
}
85
# add the last DB rev number, we don't want to end with "..."
86
if ($dbrev_applied =~ /\.$/) {
87
    $dbrev_applied .= "...".$last_known_sep;
88
}
89
51
my $osVersion     = `uname -a`;
90
my $osVersion     = `uname -a`;
52
my $perl_path = $^X;
91
my $perl_path = $^X;
53
if ($^O ne 'VMS') {
92
if ($^O ne 'VMS') {
Lines 74-79 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode(); Link Here
74
113
75
$template->param(
114
$template->param(
76
    kohaVersion   => $kohaVersion,
115
    kohaVersion   => $kohaVersion,
116
    dbrev_applied => $dbrev_applied,
77
    osVersion     => $osVersion,
117
    osVersion     => $osVersion,
78
    perlPath      => $perl_path,
118
    perlPath      => $perl_path,
79
    perlVersion   => $perlVersion,
119
    perlVersion   => $perlVersion,
(-)a/admin/ajax-updatedb-getinfos.pl (+61 lines)
Line 0 Link Here
1
#!/usr/bin/perl
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
20
=head1 NAME
21
22
ajax-updatedb-getinfos.pl
23
24
=head1 DESCRIPTION
25
this script returns comments for a updatedatabase version
26
27
=back
28
29
=cut
30
31
use Modern::Perl;
32
use CGI;
33
use C4::Update::Database;
34
35
my $input = new CGI;
36
my $version = $input->param('version');
37
38
binmode STDOUT, ":utf8";
39
print $input->header(-type => 'text/plain', -charset => 'UTF-8');
40
my $filepath;
41
my $queries;
42
eval {
43
    $filepath = C4::Update::Database::get_filepath( $version );
44
    $queries = C4::Update::Database::get_queries( $filepath );
45
};
46
if ( $@ ){
47
    print $@;
48
    exit;
49
}
50
51
if ( @{ $$queries{comments} } ) {
52
    print "Comments : <br/>" . join ( "<br/>", @{ $$queries{comments} } );
53
} else {
54
    print "No comment <br/>";
55
}
56
57
if ( @{ $$queries{queries} } ) {
58
    print "<br/><br/>Queries : <br/>" . join ( "<br/>", @{ $$queries{queries} } );
59
} else {
60
    print "<br/>No queries";
61
}
(-)a/admin/updatedatabase.pl (+103 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 2 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
use strict;
20
use CGI;
21
use C4::Auth;
22
use C4::Output;
23
use C4::Update::Database;
24
25
my $query = new CGI;
26
my $op = $query->param('op') || 'list';
27
28
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
29
    {   template_name   => "admin/updatedatabase.tmpl",
30
        query           => $query,
31
        type            => "intranet",
32
        authnotrequired => 0,
33
        flagsrequired   => { parameters => 1 },
34
    }
35
);
36
37
if ( $op eq 'update' ) {
38
    my @versions = $query->param('version');
39
    @versions = sort {
40
        C4::Update::Database::TransformToNum( $a ) <=> C4::Update::Database::TransformToNum( $b )
41
    } @versions;
42
43
    my @reports;
44
    for my $version ( @versions ) {
45
        push @reports, C4::Update::Database::execute_version $version;
46
    }
47
48
    my @report_loop = map {
49
        my ( $v, $r ) = each %$_;
50
        my @errors = ref ( $r ) eq 'ARRAY'
51
            ?
52
                map {
53
                    { error => $_ }
54
                } @$r
55
            :
56
                { error => $r };
57
        {
58
            version => $v,
59
            report  => \@errors,
60
            coherency => ( ref ( $r ) eq 'ARRAY'
61
                ? @$r[0] =~ /COHERENCY/ ? 1 : 0
62
                : $r =~ /COHERENCY/ ? 1 : 0 )
63
        }
64
    } @reports;
65
    $template->param( report_loop => \@report_loop );
66
67
    $op = 'list';
68
}
69
70
if ( $op eq 'mark_as_ok' ) {
71
    my @versions = $query->param('version');
72
    C4::Update::Database::mark_as_ok $_ for @versions;
73
    $op = 'list';
74
}
75
76
if ( $op eq 'list' ) {
77
    my $versions_availables = C4::Update::Database::list_versions_availables;
78
    my $versions = C4::Update::Database::list_versions_already_knows;
79
80
    for my $v ( @$versions_availables ) {
81
        if ( not grep { $v eq $$_{version} } @$versions ) {
82
            push @$versions, {
83
                version => $v,
84
                available => 1
85
            };
86
        }
87
    }
88
    my @sorted = sort {
89
        C4::Update::Database::TransformToNum( $$a{version} ) <=> C4::Update::Database::TransformToNum( $$b{version} )
90
    } @$versions;
91
92
    my @availables = grep { defined $$_{available} and $$_{available} == 1 } @sorted;
93
    my @v_availables = map { {version => $$_{version}} } @availables;
94
95
    $template->param(
96
        dev_mode => $ENV{DEBUG},
97
        versions => \@sorted,
98
        nb_availables => scalar @availables,
99
        availables => [ map { {version => $$_{version}} } @availables ],
100
    );
101
}
102
103
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/installer/data/mysql/kohastructure.sql (+21 lines)
Lines 2054-2059 CREATE TABLE `tags_index` ( -- a weighted list of all tags and where they are us Link Here
2054
        REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2054
        REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
2055
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2055
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2056
2056
2057
2058
--
2059
-- Table structure for database updates
2060
--
2061
CREATE TABLE`updatedb_error` (
2062
    `version` varchar(32) DEFAULT NULL,
2063
    `error` text
2064
) ENGINE=InnoDB CHARSET=utf8;
2065
2066
CREATE TABLE `updatedb_query` (
2067
    `version` varchar(32) DEFAULT NULL,
2068
    `query` text
2069
) ENGINE=InnoDB CHARSET=utf8;
2070
2071
CREATE TABLE `updatedb_report` (
2072
    `version` text,
2073
    `md5` varchar(50) DEFAULT NULL,
2074
    `comment` text,
2075
    `status` int(1) DEFAULT NULL
2076
) ENGINE=InnoDB CHARSET=utf8;
2077
2057
--
2078
--
2058
-- Table structure for table `userflags`
2079
-- Table structure for table `userflags`
2059
--
2080
--
(-)a/installer/data/mysql/update.pl (+86 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use C4::Context;
6
use C4::Update::Database;
7
use Getopt::Long;
8
9
my $help;
10
my $version;
11
my $list;
12
my $all;
13
my $min;
14
15
GetOptions(
16
    'h|help|?'     => \$help,
17
    'm:s'   => \$version,
18
    'l|list'     => \$list,
19
    'a|all'   => \$all,
20
    'min:s' => \$min,
21
);
22
23
if ( $help or not ($version or $list or $all) ) {
24
    usage();
25
    exit;
26
}
27
28
my @reports;
29
if ( $version ) {
30
    my $report = C4::Update::Database::execute_version($version);
31
    push @reports, $report;
32
}
33
34
if ( $list ) {
35
    my $versions = C4::Update::Database::list_versions_availables();
36
    say "Versions availables:";
37
    say "\t- $_" for @$versions;
38
    $versions = C4::Update::Database::list_versions_already_knows();
39
    say "Versions already knows:";
40
    say "\t- $$_{version}" for @$versions;
41
42
}
43
44
if ( $all ) {
45
    my $versions_availables = C4::Update::Database::list_versions_availables();
46
    my $versions = C4::Update::Database::list_versions_already_knows;
47
    my $min_version = $min
48
        ? $min =~ m/\d\.\d{2}\.\d{2}\.\d{3}/
49
            ? C4::Update::Database::TransformToNum( $min )
50
            : $min
51
        : 0;
52
53
    for my $v ( @$versions_availables ) {
54
        if ( not grep { $v eq $$_{version} } @$versions
55
             and $v=~/^\d+\.\d+/
56
             and C4::Update::Database::TransformToNum( $v ) >= $min_version
57
        ) {
58
            my $report = C4::Update::Database::execute_version $v;
59
            push @reports, $report;
60
        }
61
    }
62
}
63
64
if ( $version or $all ) {
65
    say @reports? "Report:": "Nothing to report";
66
    for my $report ( @reports ) {
67
        my ( $v, $r ) = each %$report;
68
        if ( ref( $r ) eq 'HASH' ) {
69
            say "\t$v => $r->{error}";
70
        } else {
71
            say "\t$v => $r";
72
        }
73
    }
74
}
75
76
sub usage {
77
    say "update.pl";
78
    say "This script updates your database for you";
79
    say "Usage:";
80
    say "\t-h\tShow this help message";
81
    say "\t-m\tExecute a given version";
82
    say "\t-l\tList all the versions";
83
    say "\t-all\tExecute all available versions";
84
    say "\t-min\tWith -all, Execute all available versions since a given version";
85
    say "\t\tCan be X.XX.XX.XXX or X.XXXXXXX";
86
}
(-)a/installer/data/mysql/versions/3.09/newupdate.sql (+1 lines)
Line 0 Link Here
1
# dbrev new update mechanism
(-)a/installer/install.pl (-12 / +28 lines)
Lines 321-339 elsif ( $step && $step == 3 ) { Link Here
321
        warn "# plack? inserted PERL5LIB $ENV{PERL5LIB}\n";
321
        warn "# plack? inserted PERL5LIB $ENV{PERL5LIB}\n";
322
    }
322
    }
323
323
324
        my $cmd = C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/updatedatabase.pl";
324
        my $koha39 = "3.0900026";
325
        my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) = IPC::Cmd::run(command => $cmd, verbose => 0);
325
        my $cmd;
326
326
        # Old updatedatabase method
327
        if (@$stdout_buf) {
327
        my $current_version = C4::Context->preference('Version');
328
            $template->param(update_report => [ map { { line => $_ } } split(/\n/, join('', @$stdout_buf)) ] );
328
        if ( $current_version < $koha39 ) {
329
            $template->param(has_update_succeeds => 1);
329
            $cmd = C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/updatedatabase.pl";
330
        }
330
            my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) = IPC::Cmd::run(command => $cmd, verbose => 0);
331
        if (@$stderr_buf) {
331
            print_std( "updatedatabase.pl", $stdout_buf, $stderr_buf );
332
            $template->param(update_errors => [ map { { line => $_ } } split(/\n/, join('', @$stderr_buf)) ] );
332
            $current_version= $koha39;
333
            $template->param(has_update_errors => 1);
334
            warn "The following errors were returned while attempting to run the updatedatabase.pl script:\n";
335
            foreach my $line (@$stderr_buf) {warn "$line\n";}
336
        }
333
        }
334
        $cmd = C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/update.pl -all -min=$current_version";
335
        my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) = IPC::Cmd::run(command => $cmd, verbose => 0);
336
        print_std( "update.pl", $stdout_buf, $stderr_buf );
337
337
338
        $template->param( $op => 1 );
338
        $template->param( $op => 1 );
339
    }
339
    }
Lines 406-409 else { Link Here
406
        }
406
        }
407
    }
407
    }
408
}
408
}
409
410
sub print_std {
411
    my ( $script, $stdout_buf, $stderr_buf ) = @_;
412
    if (@$stdout_buf) {
413
        $template->param(update_report => [ map { { line => $_ } } split(/\n/, join('', @$stdout_buf)) ] );
414
        $template->param(has_update_succeeds => 1);
415
    }
416
    if (@$stderr_buf) {
417
        $template->param(update_errors => [ map { { line => $_ } } split(/\n/, join('', @$stderr_buf)) ] );
418
        $template->param(has_update_errors => 1);
419
        warn "The following errors were returned while attempting to run the $script script:\n";
420
        foreach my $line (@$stderr_buf) {warn "$line\n";}
421
    }
422
}
423
424
409
output_html_with_http_headers $query, $cookie, $template->output;
425
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css (+7 lines)
Lines 2133-2138 a.localimage img { Link Here
2133
}
2133
}
2134
div.pager p {
2134
div.pager p {
2135
	margin: 0;
2135
	margin: 0;
2136
2137
tr.dragClass td {
2138
    background-color: grey;
2139
    color: yellow;
2140
}
2141
.underline {
2142
    text-decoration : underline;
2136
}
2143
}
2137
2144
2138
div#acqui_order_supplierlist > div.supplier {
2145
div#acqui_order_supplierlist > div.supplier {
(-)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 %]</td></tr>
40
            <tr><th scope="row">Koha version: </th><td>[% kohaVersion |html %] with the following database revisionapplied: [% 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/admin-home.tt (+7 lines)
Lines 106-111 Link Here
106
    <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 client targets</a></dt>
106
    <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 client targets</a></dt>
107
	<dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
107
	<dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
108
</dl>
108
</dl>
109
110
<h3>Update Database</h3>
111
<dl>
112
    <dt><a href="/cgi-bin/koha/admin/updatedatabase.pl">Check your updates</a></dt>
113
    <dd>Verify your database versions and execute new updates</dd>
114
</dl>
115
109
</div>
116
</div>
110
117
111
</div>
118
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt (+191 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration &rsaquo; Update Database</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
5
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
6
[% INCLUDE 'datatables-strings.inc' %]
7
<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
8
9
<script type="text/javascript">
10
 //<![CDATA[
11
    $(document).ready(function() {
12
        $("#versionst").dataTable($.extend(true, {}, dataTablesDefaults, {
13
            "aaSorting" : [[0, "asc"]],
14
            "sPaginationType": "four_button",
15
        }));
16
    } );
17
    function see_details(a){
18
        var div = $(a).siblings('div');
19
        $(div).slideToggle("fast", function() {
20
            var isVisible = $(div).is(":visible");
21
            if ( isVisible ){$(a).text("Hide details");}else{$(a).text("Show details");}
22
        } );
23
    }
24
    function get_infos(version, node){
25
        $.ajax({
26
            url: "/cgi-bin/koha/admin/ajax-updatedb-getinfos.pl",
27
            data: {
28
                version: version
29
            },
30
            success: function(data){
31
                $(node).replaceWith(data);
32
            },
33
        });
34
    }
35
//]]>
36
</script>
37
</head>
38
<body>
39
[% INCLUDE 'header.inc' %]
40
[% INCLUDE 'cat-search.inc' %]
41
42
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Database update</div>
43
44
<div id="doc3" class="yui-t2">
45
46
   <div id="bd">
47
    <div id="yui-main">
48
    <div class="yui-b">
49
50
    <h2>Database update</h2>
51
    [% IF report_loop %]
52
    <div class="report" style="display:block; margin:1em;">
53
        Report :
54
        <ul>
55
        [% FOREACH report_loo IN report_loop %]
56
            <li>
57
                [% report_loo.version %] --
58
                [% FOREACH r IN report_loo.report %]
59
                    [% IF r.error.error == "ALREADY_EXISTS" %]
60
                        This file ( [% r.error.filepath %] ) still already execute in version [% r.error.old_version %] : same md5 ([% r.error.md5 %])
61
                        [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% report_loo.version %]">Mark as OK</a>]
62
                    [% ELSIF r.error.error == "LOAD_FUNCTIONS_FAILED" %]
63
                        Load functions in [% r.error.filename %] failed
64
                    [% ELSIF r.error.error == "BAD_EXTENSION" %]
65
                        This extension ([% r.error.extension %]) is not take into account (only .pl or .sql)";
66
                    [% ELSE %]
67
                        [% r.error %];
68
                    [% END %]
69
                [% END %]
70
                [% IF report_loo.coherency %]
71
                    [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% report_loo.version %]">Mark as OK</a>]
72
                [% END %]
73
            </li>
74
        [% END %]
75
        </ul>
76
    </div>
77
    [% END %]
78
    <span class="infos" style="display:block; margin:1em;">
79
        [% IF nb_availables %]
80
            Your datebase is not up to date.<br/>
81
            [% IF nb_availables == 1 %]
82
                1 update available [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% availables.first.version %]">UPDATE [% availables.first.version %]</a>]
83
            [% ELSE %]
84
                [% 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>]:
85
                [% IF ( dev_mode ) %]
86
                  <ul>
87
                    [% FOREACH av IN availables %]
88
                      <li>[% av.version %] [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% av.version %]">UPDATE</a>]</li>
89
                    [% END %]
90
                  </ul>
91
                [% END %]
92
            [% END %]
93
        [% ELSE %]
94
            Your database is up to date
95
        [% END %]
96
    </span>
97
98
    <table id="versionst">
99
        <thead>
100
            <tr>
101
                <th>DB revision</th>
102
                <th>Comments</th>
103
                <th>Status</th>
104
                <th>Availability</th>
105
                <th>Details</th>
106
            </tr>
107
        </thead>
108
        <tbody>
109
        [% FOREACH v IN versions %]
110
            <tr>
111
                <td>[% v.version %]</td>
112
                <td>
113
                    [% FOREACH c IN v.comments %]
114
                        [% c.comment %]
115
                    [% END %]
116
                </td>
117
                <td>
118
                    [% IF v.available %]
119
                        Unknown
120
                    [% ELSE %]
121
                        [% IF v.status %]
122
                            <span style="color:green;">OK</span>
123
                            [% IF v.status == 2 %]
124
                                [FORCED]
125
                            [% END %]
126
                        [% ELSE %]
127
                            <span style="color:red;">Failed</span>
128
                        [% END %]
129
                    [% END %]
130
                </td>
131
                <td>
132
                    [% IF v.available %]
133
                        Available
134
                        [% IF (dev_mode) %]
135
                            [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% v.version %]">Execute</a>]
136
                        [% END %]
137
                    [% ELSE %]
138
                        Already executed
139
                    [% END %]
140
                </td>
141
                <td width="50%">
142
                    <div class="details" style="display:none;">
143
                        [% IF v.available %]
144
                            Unknown
145
                            <span style="display:block;"><a href="#" onclick="get_infos('[% v.version %]', this); return false;">Get comments</a></span>
146
                        [% ELSE %]
147
                            <div class="queries" style="display:block;">
148
                                <span class="underline">Queries</span> :
149
                                [% FOREACH q IN v.queries %]
150
                                    [% q.query %]<br/>
151
                                [% END %]
152
                            </div>
153
                            [% IF v.status == 1 %]
154
                                <div class="status" style="display:block;">
155
                                    <span class="underline">Status</span> :
156
                                    <span style="color:green;">OK</span>
157
                                </div>
158
                            [% ELSE %]
159
                                <div class="status" style="display:block;">
160
                                    <span class="underline">Status</span> :
161
                                    [% IF v.status == 2 %]
162
                                        <span style="color:green;">OK</span>
163
                                        [FORCED]
164
                                    [% ELSE %]
165
                                        <span style="color:red;">Failed</span>
166
                                        [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% v.version %]">Mark as OK</a>]
167
                                    [% END %]
168
                                </div>
169
                                <div class="errors" style="display:block;">
170
                                    <span class="underline">Errors</span> :
171
                                    <span class="errors">
172
                                    [% FOREACH e IN v.errors %]
173
                                        <span>[% e.error %]</span>
174
                                    [% END %]
175
                                    </span>
176
                                </div>
177
                            [% END %]
178
                        [% END %]
179
                    </div>
180
                    <a href="#" onclick="see_details(this);return false;">Show details</a>
181
                </td>
182
            </tr>
183
        [% END %]
184
        </tbody>
185
    </table>
186
187
    </div>
188
    </div>
189
    </div>
190
    </div>
191
    </div>
(-)a/mainpage.pl (-1 / +3 lines)
Lines 28-33 use C4::NewsChannels; Link Here
28
use C4::Review qw/numberofreviews/;
28
use C4::Review qw/numberofreviews/;
29
use C4::Suggestions qw/CountSuggestion/;
29
use C4::Suggestions qw/CountSuggestion/;
30
use C4::Tags qw/get_count_by_tag_status/;
30
use C4::Tags qw/get_count_by_tag_status/;
31
31
my $query     = new CGI;
32
my $query     = new CGI;
32
33
33
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 42-47 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
42
    }
43
    }
43
);
44
);
44
45
46
C4::Auth::version_check($query, 'intranet', $cookie);
47
45
my $all_koha_news   = &GetNewsToDisplay("koha");
48
my $all_koha_news   = &GetNewsToDisplay("koha");
46
my $koha_news_count = scalar @$all_koha_news;
49
my $koha_news_count = scalar @$all_koha_news;
47
50
48
- 

Return to bug 7167