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

(-)a/C4/Update/Database.pm (+357 lines)
Line 0 Link Here
1
package C4::Update::Database;
2
3
use Modern::Perl;
4
5
use C4::Context;
6
use C4::Config::File::YAML;
7
8
use File::Basename;
9
use Digest::MD5;
10
use List::MoreUtils qw/uniq/;
11
12
my $config = C4::Config::File::YAML->new( C4::Context->config("installdir") . qq{/etc/update/database/config.yaml} );
13
my $VERSIONS_PATH = C4::Context->config('intranetdir') . '/' . $config->{versions_dir};
14
15
my $version;
16
my $list;
17
18
my $dbh = C4::Context->dbh;
19
20
sub get_filepath {
21
    my ( $version ) = @_;
22
    my @files = <$VERSIONS_PATH/$version*>;
23
    if ( scalar @files != 1 ) {
24
        die "This version ($version) returned more than one file (or any) corresponding!";
25
    }
26
27
    return $files[0];
28
}
29
30
sub get_md5 {
31
    my ( $filepath ) = @_;
32
    open(FILE, $filepath);
33
34
    my $ctx = Digest::MD5->new;
35
    $ctx->addfile(*FILE);
36
    my $md5 = $ctx->hexdigest;
37
    close(FILE);
38
    return $md5;
39
}
40
41
sub execute_version {
42
    my ( $version ) = @_;
43
    my $report;
44
45
    my $filepath;
46
    eval {
47
        $filepath = get_filepath $version;
48
    };
49
    if ( $@ ) {
50
        return { $version => $@ };
51
    }
52
53
    my @file_infos = fileparse( $filepath, qr/\.[^.]*/ );
54
    my $extension = $file_infos[2];
55
    my $filename = $version . $extension;
56
57
    my $md5 = get_md5 $filepath;
58
    my $r = md5_already_exists( $md5 );
59
    if ( scalar @$r ) {
60
        my $p = @$r[0];
61
        $$report{$version} = "This file ( $filepath ) still already execute in version " . @$r[0]->{version} . " : same md5 (" . @$r[0]->{md5} . ")";
62
        return $report;
63
    }
64
65
    my $queries;
66
    given ( $extension ) {
67
        when ( /.sql/ ) {
68
            $queries = get_queries ( $filepath );
69
        }
70
        when ( /.pl/ ) {
71
            my $versions_dir = C4::Context->intranetdir . '/installer/data/mysql/versions/';
72
            my $version_file = $versions_dir . $filename;
73
            if ( do $version_file ) {
74
                $queries = _get_queries();
75
            } else {
76
                $$report{$version} = "Load functions in $filename failed";
77
            }
78
        }
79
        default {
80
            $$report{$version} = "This extension ($extension) is not take into account (only .pl or .sql)";
81
        }
82
    }
83
84
    return $report
85
        if ( defined $$report{$version} );
86
87
    my $errors;
88
    for my $query ( @{$$queries{queries}} ) {
89
        eval {
90
            check_coherency( $query );
91
        };
92
        if ( $@ ) {
93
            push @$errors, $@
94
        }
95
    }
96
97
    if ( $errors ) {
98
        $_ =~ s/at [^ ]* line \d*\.$// for @$errors;
99
        $$report{$version} = $errors;
100
        return $report;
101
    }
102
103
    $errors = execute ( $queries );
104
    $$report{$version} = scalar( @$errors ) ? $errors : "OK";
105
    set_infos ( $version, $queries, $errors, $md5 );
106
107
    return $report;
108
}
109
110
sub list_versions_availables {
111
    my @versions;
112
    opendir DH, $VERSIONS_PATH or die "Cannot open directory ($!)";
113
    my @files = grep { !/^\.\.?$/ and /^.*\.(sql|pl)$/ and !/^skeleton/ } readdir DH;
114
    for my $f ( @files ) {
115
        my @file_infos = fileparse( $f, qr/\.[^.]*/ );
116
        push @versions, $file_infos[0];
117
    }
118
    @versions = uniq @versions;
119
    closedir DH;
120
    return \@versions;
121
}
122
123
sub list_versions_already_knows {
124
    my $query = qq/ SELECT version, comment, status FROM updatedb_report /;
125
    my $sth = $dbh->prepare( $query );
126
    $sth->execute;
127
    my $versions = $sth->fetchall_arrayref( {} );
128
    map {
129
        my $version = $_;
130
        my @comments = defined $$_{comment} ? split '\\\n', $$_{comment} : "";
131
        push @{ $$version{comments} }, { comment => $_ } for @comments;
132
        delete $$version{comment};
133
    } @$versions;
134
    $sth->finish;
135
    for my $version ( @$versions ) {
136
        $query = qq/ SELECT query FROM updatedb_query WHERE version = ? /;
137
        $sth = $dbh->prepare( $query );
138
        $sth->execute( $$version{version} );
139
        $$version{queries} = $sth->fetchall_arrayref( {} );
140
        $sth->finish;
141
        $query = qq/ SELECT error FROM updatedb_error WHERE version = ? /;
142
        $sth = $dbh->prepare( $query );
143
        $sth->execute( $$version{version} );
144
        $$version{errors} = $sth->fetchall_arrayref( {} );
145
        $sth->finish;
146
    }
147
    return $versions;
148
}
149
150
sub execute {
151
    my ( $queries ) = @_;
152
    my @errors;
153
    for my $query ( @{$$queries{queries}} ) {
154
        eval {
155
            $dbh->do( $query );
156
        };
157
        push @errors, get_error();
158
    }
159
    return \@errors;
160
}
161
162
sub get_tables_name {
163
    my $sth = $dbh->prepare("SHOW TABLES");
164
    $sth->execute();
165
    my @tables;
166
    while ( my ( $table ) = $sth->fetchrow_array ) {
167
        push @tables, $table;
168
    }
169
    return \@tables;
170
}
171
my $tables;
172
sub check_coherency {
173
    my ( $query ) = @_;
174
    $tables = get_tables_name() if not $tables;
175
176
    given ( $query ) {
177
        when ( /CREATE TABLE(?:.*?)? `?(\w+)`?/ ) {
178
            my $table_name = $1;
179
            if ( grep { /$table_name/ } @$tables ) {
180
                die "COHERENCY: Table $table_name already exists";
181
            }
182
        }
183
184
        when ( /ALTER TABLE *`?(\w+)`? *ADD *(?:COLUMN)? `?(\w+)`?/ ) {
185
            my $table_name = $1;
186
            my $column_name = $2;
187
            next if $column_name =~ /(UNIQUE|CONSTRAINT|INDEX|KEY|FOREIGN)/;
188
            if ( not grep { /$table_name/ } @$tables ) {
189
                return "COHERENCY: Table $table_name does not exist";
190
            } else {
191
                my $sth = $dbh->prepare( "DESC $table_name $column_name" );
192
                my $rv = $sth->execute;
193
                if ( $rv > 0 ) {
194
                    die "COHERENCY: Field $table_name.$column_name already exists";
195
                }
196
            }
197
        }
198
199
        when ( /INSERT INTO `?(\w+)`?.*?VALUES *\((.*?)\)/ ) {
200
            my $table_name = $1;
201
            my @values = split /,/, $2;
202
            s/^ *'// foreach @values;
203
            s/' *$// foreach @values;
204
            given ( $table_name ) {
205
                when ( /systempreferences/ ) {
206
                    my $syspref = $values[0];
207
                    my $sth = $dbh->prepare( "SELECT COUNT(*) FROM systempreferences WHERE variable = ?" );
208
                    $sth->execute( $syspref );
209
                    if ( ( my $count = $sth->fetchrow_array ) > 0 ) {
210
                        die "COHERENCY: Syspref $syspref already exists";
211
                    }
212
                }
213
214
                when ( /permissions/){
215
                    my $module_bit = $values[0];
216
                    my $code = $values[1];
217
                    my $sth = $dbh->prepare( "SELECT COUNT(*) FROM permissions WHERE module_bit = ? AND code = ?" );
218
                    $sth->execute($module_bit, $code);
219
                    if ( ( my $count = $sth->fetchrow_array ) > 0 ) {
220
                        die "COHERENCY: Permission $code already exists";
221
                    }
222
                }
223
            }
224
        }
225
    }
226
    return 1;
227
}
228
229
sub get_error {
230
    my @errors = $dbh->selectrow_array(qq{SHOW ERRORS}); # Get errors
231
    my @warnings = $dbh->selectrow_array(qq{SHOW WARNINGS}); # Get warnings
232
    if ( @errors ) { # Catch specifics errors
233
        return qq{$errors[0] : $errors[1] => $errors[2]};
234
    } elsif ( @warnings ) {
235
        return qq{$warnings[0] : $warnings[1] => $warnings[2]}
236
            if $warnings[0] ne 'Note';
237
    }
238
    return;
239
}
240
241
sub get_queries {
242
    my ( $filepath ) = @_;
243
    open my $fh, "<", $filepath;
244
    my @queries;
245
    my @comments;
246
    my $old_delimiter = $/;
247
    while ( <$fh> ) {
248
        my $line = $_;
249
        chomp $line;
250
        $line =~ s/^\s*//;
251
        if ( $line =~ s/^--(.*)$// ) {
252
            push @comments, $1;
253
            next;
254
        }
255
        if ( $line =~ /^delimiter (.*)$/i ) {
256
            $/ = $1;
257
            next;
258
        }
259
        $line =~ s#$/##;
260
        push @queries, $line if not $line =~ /^\s*$/; # Push if query is not empty
261
    }
262
    $/ = $old_delimiter;
263
    close $fh;
264
265
    return { queries => \@queries, comments => \@comments };
266
}
267
268
sub md5_already_exists {
269
    my ( $md5 ) = @_;
270
    my $query = qq/SELECT version, md5 FROM updatedb_report WHERE md5 = ?/;
271
    my $sth = $dbh->prepare( $query );
272
    $sth->execute( $md5 );
273
    my @r;
274
    while ( my ( $version, $md5 ) = $sth->fetchrow ) {
275
        push @r, { version => $version, md5 => $md5 };
276
    }
277
    $sth->finish;
278
    return \@r;
279
}
280
281
sub set_infos {
282
    my ( $version, $queries, $errors, $md5 ) = @_;
283
    #SetVersion($DBversion) if not -s $errors;
284
    for my $query ( @{ $$queries{queries} } ) {
285
        my $sth = $dbh->prepare("INSERT INTO updatedb_query(version, query) VALUES (?, ?)");
286
        $sth->execute( $version, $query );
287
        $sth->finish;
288
    }
289
    for my $error ( @$errors ) {
290
        my $sth = $dbh->prepare("INSERT INTO updatedb_error(version, error) VALUES (?, ?)");
291
        $sth->execute( $version, $error );
292
    }
293
    my $sth = $dbh->prepare("INSERT INTO updatedb_report(version, md5, comment, status) VALUES (?, ?, ?, ?)");
294
    $sth->execute(
295
        $version,
296
        $md5,
297
        join ('\n', @{ $$queries{comments} }),
298
        ( @$errors > 0 ) ? 0 : 1
299
    );
300
}
301
302
sub mark_as_ok {
303
    my ( $version ) = @_;
304
    my $sth = $dbh->prepare( "UPDATE updatedb_report SET status = 2 WHERE version=?" );
305
    my $affected = $sth->execute( $version );
306
    if ( $affected < 1 ) {
307
        # For "Coherency"
308
        my $filepath = get_filepath $version;
309
        my $queries = get_queries $filepath;
310
        my $errors;
311
        for my $query ( @{$$queries{queries}} ) {
312
            eval {
313
                check_coherency( $query );
314
            };
315
            if ( $@ ) {
316
                push @$errors, $@
317
            }
318
        }
319
320
        $_ =~ s/at [^ ]* line \d*\.$// for @$errors;
321
        my $md5 = get_md5 $filepath;
322
        set_infos $version, $queries, $errors, $md5;
323
324
        $sth->execute( $version );
325
    }
326
    $sth->finish;
327
}
328
329
=item TransformToNum
330
331
  Transform the Koha version from a 4 parts string
332
  to a number, with just 1 .
333
334
=cut
335
336
sub TransformToNum {
337
    my $version = shift;
338
339
    # remove the 3 last . to have a Perl number
340
    $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
341
    return $version;
342
}
343
344
sub SetVersion {
345
    my $kohaversion = TransformToNum(shift);
346
    if ( C4::Context->preference('Version') ) {
347
        my $finish = $dbh->prepare("UPDATE systempreferences SET value=? WHERE variable='Version'");
348
        $finish->execute($kohaversion);
349
    } else {
350
        my $finish = $dbh->prepare(
351
"INSERT IGNORE INTO systempreferences (variable,value,explanation) values ('Version',?,'The Koha database version. WARNING: Do not change this value manually, it is maintained by the webinstaller')"
352
        );
353
        $finish->execute($kohaversion);
354
    }
355
}
356
357
1;
(-)a/admin/ajax-updatedb-getinfos.pl (+62 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
}
62
(-)a/admin/updatedatabase.pl (+101 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 CGI;
20
use C4::Auth;
21
use C4::Output;
22
use C4::Update::Database;
23
24
my $query = new CGI;
25
my $op = $query->param('op') || 'list';
26
27
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
28
    {   template_name   => "admin/updatedatabase.tmpl",
29
        query           => $query,
30
        type            => "intranet",
31
        authnotrequired => 0,
32
        flagsrequired   => { parameters => 1 }, # FIXME Add a new flag
33
    }
34
);
35
36
if ( $op eq 'update' ) {
37
    my @versions = $query->param('version');
38
    @versions = sort {
39
        C4::Update::Database::TransformToNum( $a ) <=> C4::Update::Database::TransformToNum( $b )
40
    } @versions;
41
42
    my @reports;
43
    for my $version ( @versions ) {
44
        push @reports, C4::Update::Database::execute_version $version;
45
    }
46
47
    my @report_loop = map {
48
        my ( $v, $r ) = each %$_;
49
        my @errors = ref ( $r ) eq 'ARRAY'
50
            ?
51
                map {
52
                    { error => $_ }
53
                } @$r
54
            :
55
                { error => $r };
56
        {
57
            version => $v,
58
            report  => \@errors,
59
            coherency => ( ref ( $r ) eq 'ARRAY'
60
                ? @$r[0] =~ /COHERENCY/ ? 1 : 0
61
                : $r =~ /COHERENCY/ ? 1 : 0 )
62
        }
63
    } @reports;
64
    $template->param( report_loop => \@report_loop );
65
66
    $op = 'list';
67
}
68
69
if ( $op eq 'mark_as_ok' ) {
70
    my @versions = $query->param('version');
71
    C4::Update::Database::mark_as_ok $_ for @versions;
72
    $op = 'list';
73
}
74
75
if ( $op eq 'list' ) {
76
    my $versions_availables = C4::Update::Database::list_versions_availables;
77
    my $versions = C4::Update::Database::list_versions_already_knows;
78
79
    for my $v ( @$versions_availables ) {
80
        if ( not grep { $v eq $$_{version} } @$versions ) {
81
            push @$versions, {
82
                version => $v,
83
                available => 1
84
            };
85
        }
86
    }
87
    my @sorted = sort {
88
        C4::Update::Database::TransformToNum( $$a{version} ) <=> C4::Update::Database::TransformToNum( $$b{version} )
89
    } @$versions;
90
91
    my @availables = grep { defined $$_{available} and $$_{available} == 1 } @sorted;
92
    my @v_availables = map { {version => $$_{version}} } @availables;
93
94
    $template->param(
95
        versions => \@sorted,
96
        nb_availables => scalar @availables,
97
        availables => [ map { {version => $$_{version}} } @availables ],
98
    );
99
}
100
101
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/etc/update/database/config.yaml (+1 lines)
Line 0 Link Here
1
versions_dir: installer/data/mysql/versions
(-)a/installer/data/mysql/update.pl (+28 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
use C4::Context;
4
use C4::Update::Database;
5
use Getopt::Long;
6
7
8
my $version;
9
my $list;
10
11
GetOptions( 
12
    'm:s' => \$version,
13
    'l'   => \$list,
14
);
15
16
if ( $version ) {
17
    my $report = C4::Update::Database::execute_version($version);
18
}
19
20
if ( $list ) {
21
    my $versions = C4::Update::Database::list_versions_availables();
22
    say "Versions availables:";
23
    say "\t- $_" for @$versions;
24
    $versions = C4::Update::Database::list_versions_already_knows();
25
    say "Versions already knows:";
26
    say "\t- $$_{version}" for @$versions;
27
28
}
(-)a/installer/data/mysql/updatedatabase.pl (+15 lines)
Lines 4550-4555 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
4553
=head1 FUNCTIONS
4568
=head1 FUNCTIONS
4554
4569
4555
=head2 DropAllForeignKeys($table)
4570
=head2 DropAllForeignKeys($table)
(-)a/installer/data/mysql/versions/skeleton.pl (+17 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use C4::Update::Database;
5
6
sub _get_queries {
7
    my @queries = (
8
        qq{INSERT INTO foo VALUES ('bar1')},
9
        qq{INSERT INTO foo VALUES ('bar2')},
10
    );
11
    my @comments = (
12
        qq{This is a test},
13
    );
14
    return { queries => \@queries, comments => \@comments };
15
}
16
17
1;
(-)a/installer/data/mysql/versions/skeleton.sql (+3 lines)
Line 0 Link Here
1
-- This is a comment
2
DELIMITER ;
3
INSERT INTO foo values("bar");
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css (-1 / +9 lines)
Lines 2080-2083 div.pager input.pagedisplay { Link Here
2080
	background-color : transparent;
2080
	background-color : transparent;
2081
	font-weight: bold;
2081
	font-weight: bold;
2082
	text-align : center;
2082
	text-align : center;
2083
}
2083
}
2084
2085
tr.dragClass td {
2086
    background-color: grey;
2087
    color: yellow;
2088
}
2089
.underline {
2090
    text-decoration : underline;
2091
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+7 lines)
Lines 98-103 Link Here
98
	<dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 Client Targets</a></dt>
98
	<dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 Client Targets</a></dt>
99
	<dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
99
	<dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
100
</dl>
100
</dl>
101
102
<h3>Update Database</h3>
103
<dl>
104
    <dt><a href="/cgi-bin/koha/admin/updatedatabase.pl">Check your updates</a></dt>
105
    <dd>Verify your database versions and execute new updates</dd>
106
</dl>
107
101
</div>
108
</div>
102
109
103
</div>
110
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt (-1 / +171 lines)
Line 0 Link Here
0
- 
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration &rsaquo; Update Database</title>
3
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
4
[% INCLUDE 'doc-head-close.inc' %]
5
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
6
<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
7
<script type="text/javascript">
8
 //<![CDATA[
9
    $(document).ready(function() {
10
        $("#versionst").dataTable({
11
            'bAutoWidth': false,
12
            'sPaginationType': 'full_numbers'
13
        } );
14
    } );
15
    function see_details(a){
16
        var div = $(a).siblings('div');
17
        $(div).slideToggle("fast", function() { 
18
            var isVisible = $(div).is(":visible");
19
            if ( isVisible ){$(a).text("Hide details");}else{$(a).text("Show details");}
20
        } );
21
    }
22
    function get_infos(version, node){
23
        $.ajax({
24
            url: "/cgi-bin/koha/admin/ajax-updatedb-getinfos.pl",
25
            data: {
26
                version: version
27
            },
28
            success: function(data){
29
                $(node).replaceWith(data);
30
            },
31
        });
32
    }
33
//]]>
34
</script>
35
</head>
36
<body>
37
[% INCLUDE 'header.inc' %]
38
[% INCLUDE 'cat-search.inc' %]
39
40
<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; Update Database</div>
41
42
<div id="doc3" class="yui-t2">
43
44
   <div id="bd">
45
    <div id="yui-main">
46
    <div class="yui-b">
47
48
    <h2>Update Database</h2>
49
    [% IF report_loop %]
50
    <div class="report" style="display:block; margin:1em;">
51
        Report :
52
        <ul>
53
        [% FOREACH report_loo IN report_loop %]
54
            <li>
55
                [% report_loo.version %] --
56
                [% FOREACH r IN report_loo.report %]
57
                    [% r.error %];
58
                [% END %]
59
                [% IF report_loo.coherency %]
60
                    [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% version %]">Mark as OK</a>]
61
                [% END %]
62
            </li>
63
        [% END %]
64
        </ul>
65
    </div>
66
    [% END %]
67
    <span class="infos" style="display:block; margin:1em;">
68
        [% IF nb_availables %]
69
            [% nb_availables %] versions are availables [ <a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update[% FOREACH av IN availables %]&version=[% av.version %][% END %]">UPDATE</a> ]
70
        [% ELSE %]
71
            Your database is up to date
72
        [% END %]
73
    </span>
74
75
    <table id="versionst">
76
        <thead>
77
            <tr>
78
                <th>Version</th>
79
                <th>Comments</th>
80
                <th>Status</th>
81
                <th>Launch</th>
82
                <th>Details</th>
83
            </tr>
84
        </thead>
85
        <tbody>
86
        [% FOREACH v IN versions %]
87
            <tr>
88
                <td>[% v.version %]</td>
89
                <td>
90
                    <ul class="comments">
91
                    [% FOREACH c IN comments %]
92
                        <li>[% c.comment %]</li>
93
                    [% END %]
94
                    </ul>
95
                </td>
96
                <td>
97
                    [% IF v.available %]
98
                        Unknown
99
                    [% ELSE %]
100
                        [% IF v.status %]
101
                            <span style="color:green;">OK</span>
102
                            [% IF v.status == 2 %]
103
                                [FORCED]
104
                            [% END %]
105
                        [% ELSE %]
106
                            <span style="color:red;">Failed</span>
107
                        [% END %]
108
                    [% END %]
109
                </td>
110
                <td>
111
                    [% IF v.available %]
112
                        Available
113
                        [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% v.version %]">Execute</a>]
114
                    [% ELSE %]
115
                        Already executed
116
                    [% END %]
117
                </td>
118
                <td>
119
                    <div class="details" style="display:none;">
120
                        [% IF v.available %]
121
                            Unknown
122
                            <span style="display:block;"><a href="#" onclick="get_infos('[% v.version %]', this); return false;">Get comments</a></span>
123
                        [% ELSE %]
124
                            <div class="queries" style="display:block;">
125
                                <span class="underline">Queries</span> :
126
                                <ul>
127
                                [% FOREACH q IN v.queries %]
128
                                    <li>[% q.query %]</li>
129
                                [% END %]
130
                                </ul>
131
                            </div>
132
                            [% IF v.status == 1 %]
133
                                <div class="status" style="display:block;">
134
                                    <span class="underline">Status</span> :
135
                                    <span style="color:green;">OK</span>
136
                                </div>
137
                            [% ELSE %]
138
                                <div class="status" style="display:block;">
139
                                    <span class="underline">Status</span> :
140
                                    [% IF v.status == 2 %]
141
                                        <span style="color:green;">OK</span>
142
                                        [FORCED]
143
                                    [% ELSE %]
144
                                        <span style="color:red;">Failed</span>
145
                                        [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% v.version %]">Mark as OK</a>]
146
                                    [% END %]
147
                                </div>
148
                                <div class="errors" style="display:block;">
149
                                    <span class="underline">Errors</span> :
150
                                    <ul class="errors">
151
                                    [% FOREACH e IN v.errors %]
152
                                        <li>[% e.error %]</li>
153
                                    [% END %]
154
                                    </ul>
155
                                </div>
156
                            [% END %]
157
                        [% END %]
158
                    </div>
159
                    <a href="#" onclick="see_details(this);return false;">Show details</a>
160
                </td>
161
            </tr>
162
        [% END %]
163
        </tbody>
164
    </table>
165
166
    </div>
167
    </div>
168
    </div>
169
    </div>
170
    </div>
171

Return to bug 7167