Bugzilla – Attachment 11242 Details for
Bug 7167
updatedatabase improvements
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7167: Improve display + factorize get_queries
Bug-7167-Improve-display--factorize-getqueries.patch (text/plain), 17.18 KB, created by
Paul Poulain
on 2012-08-01 09:42:58 UTC
(
hide
)
Description:
Bug 7167: Improve display + factorize get_queries
Filename:
MIME Type:
Creator:
Paul Poulain
Created:
2012-08-01 09:42:58 UTC
Size:
17.18 KB
patch
obsolete
>From 63de7b04630f73aea880d126301ba3b72365b5af Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 31 Jul 2012 14:18:22 +0200 >Subject: [PATCH] Bug 7167: Improve display + factorize get_queries > >Despite it's size, this patch is dealing with display questions only: > * The text "comments" and "queries" was hardcoded in ajax-updatedb-getinfo.pl script. It has been replaced by a JSON call, returning 2 separate values, "comments:" and "queries:" is now in the template, making it translatable > * Some minor tweak in the display (like putting things in bold, displaying OK in green, warnings in yellow and KO in red) > * Reordering the column headers for more readability: > * Status column is merged with availability, column is after status > * Status/availability terms more clear: "Not applied" instead of "unknown", "Applied and OK", "Applied and failed", "Applied and forced" are the 3 other statuses > * Removed one click to display comments on DBREv not yet applied: before the patch, one had to click "Show details", then "Get comments", now, "Get comments" is enough > >Signed-off-by: Paul Poulain <paul.poulain@biblibre.com> >--- > C4/Update/Database.pm | 75 +++++---- > admin/ajax-updatedb-getinfos.pl | 29 ++-- > installer/data/mysql/update.pl | 2 + > .../prog/en/modules/admin/updatedatabase.tt | 172 +++++++++++--------- > 4 files changed, 160 insertions(+), 118 deletions(-) > >diff --git a/C4/Update/Database.pm b/C4/Update/Database.pm >index ac62209..b7106b3 100644 >--- a/C4/Update/Database.pm >+++ b/C4/Update/Database.pm >@@ -130,14 +130,14 @@ sub execute_version { > $queries = get_queries ( $filepath ); > } > when ( /.pl/ ) { >- my $versions_dir = C4::Context->intranetdir . '/installer/data/mysql/versions/'; >- my $version_file = $versions_dir . $filename; >- if ( do $version_file ) { >- $queries = _get_queries(); >- } else { >+ eval { >+ $queries = get_queries ( $filepath ); >+ }; >+ if ($@) { > $report->{$version} = { > error => "LOAD_FUNCTIONS_FAILED", > filename => $filename, >+ error_str => $@, > }; > } > } >@@ -364,38 +364,51 @@ sub get_queries { > open my $fh, "<", $filepath; > my @queries; > my @comments; >- my $old_delimiter = $/; >- while ( <$fh> ) { >- my $line = $_; >- chomp $line; >- $line =~ s/^\s*//; >- if ( $line =~ s/^--(.*)$// ) { >- my @l = split $old_delimiter; >- if ( @l > 1 ) { >- my $tmp_query; >- for my $l ( @l ) { >- if ( $l =~ m/^--/ ) { >- push @comments, $l; >- next; >+ if ( $filepath =~ /\.pl$/ ) { >+ if ( do $filepath ) { >+ my $infos = _get_queries(); >+ @queries = @{ $infos->{queries} } if exists $infos->{queries}; >+ @comments = @{ $infos->{comments} } if exists $infos->{comments}; >+ } >+ if ( $@ ) { >+ die "I can't load $filepath. Please check the execute flag and if this file is a valid perl script ($@)"; >+ } >+ } else { >+ my $old_delimiter = $/; >+ while ( <$fh> ) { >+ my $line = $_; >+ chomp $line; >+ $line =~ s/^\s*//; >+ if ( $line =~ /^--/ ) { >+ my @l = split $old_delimiter, $line; >+ if ( @l > 1 ) { >+ my $tmp_query; >+ for my $l ( @l ) { >+ if ( $l =~ /^--/ ) { >+ $l =~ s/^--\s*//; >+ push @comments, $l; >+ next; >+ } >+ $tmp_query .= $l . $old_delimiter; > } >- $tmp_query .= $l . $old_delimiter; >+ push @queries, $tmp_query if $tmp_query; >+ next; > } >- push @queries, $tmp_query if $tmp_query; >+ >+ $line =~ s/^--\s*//; >+ push @comments, $line; > next; > } >- >- push @comments, $1; >- next; >- } >- if ( $line =~ /^delimiter (.*)$/i ) { >- $/ = $1; >- next; >+ if ( $line =~ /^delimiter (.*)$/i ) { >+ $/ = $1; >+ next; >+ } >+ $line =~ s#$/##; >+ push @queries, $line if not $line =~ /^\s*$/; # Push if query is not empty > } >- $line =~ s#$/##; >- push @queries, $line if not $line =~ /^\s*$/; # Push if query is not empty >+ $/ = $old_delimiter; >+ close $fh; > } >- $/ = $old_delimiter; >- close $fh; > > return { queries => \@queries, comments => \@comments }; > } >diff --git a/admin/ajax-updatedb-getinfos.pl b/admin/ajax-updatedb-getinfos.pl >index 25ceda5..fb91613 100755 >--- a/admin/ajax-updatedb-getinfos.pl >+++ b/admin/ajax-updatedb-getinfos.pl >@@ -30,32 +30,33 @@ this script returns comments for a updatedatabase version > > use Modern::Perl; > use CGI; >+use JSON; > use C4::Update::Database; >+use C4::Output; > > my $input = new CGI; > my $version = $input->param('version'); > >-binmode STDOUT, ":utf8"; >-print $input->header(-type => 'text/plain', -charset => 'UTF-8'); > my $filepath; > my $queries; > eval { > $filepath = C4::Update::Database::get_filepath( $version ); > $queries = C4::Update::Database::get_queries( $filepath ); > }; >-if ( $@ ){ >- print $@; >- exit; >-} > >-if ( @{ $$queries{comments} } ) { >- print "Comments : <br/>" . join ( "<br/>", @{ $$queries{comments} } ); >+my $param = {comments => "", queries => ""}; >+if ( $@ ){ >+ $param->{errors} = $@; > } else { >- print "No comment <br/>"; >-} >+ if ( exists $queries->{comments} and @{ $queries->{comments} } ) { >+ $param->{comments} = join ( "<br/>", @{ $queries->{comments} } ); >+ } > >-if ( @{ $$queries{queries} } ) { >- print "<br/><br/>Queries : <br/>" . join ( "<br/>", @{ $$queries{queries} } ); >-} else { >- print "<br/>No queries"; >+ if ( exists $queries->{queries} and @{ $queries->{queries} } ) { >+ $param->{queries} = join ( "<br/>", @{ $queries->{queries} } ); >+ } > } >+ >+my $json_text = to_json( $param, { utf8 => 1 } ); >+ >+output_with_http_headers $input, undef, $json_text, 'json'; >diff --git a/installer/data/mysql/update.pl b/installer/data/mysql/update.pl >index 605fe6c..33e123f 100644 >--- a/installer/data/mysql/update.pl >+++ b/installer/data/mysql/update.pl >@@ -64,6 +64,8 @@ if ( $version or $all ) { > my ( $v, $r ) = each %$report; > if ( ref( $r ) eq 'HASH' ) { > say "\t$v => $r->{error}"; >+ } elsif ( ref ( $r ) eq 'ARRAY' ) { >+ say "\t$_" for @$r; > } else { > say "\t$v => $r"; > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt >index 706dbf7..2c68f91 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt >@@ -22,15 +22,32 @@ > } ); > } > function get_infos(version, node){ >- $.ajax({ >- url: "/cgi-bin/koha/admin/ajax-updatedb-getinfos.pl", >- data: { >- version: version >- }, >- success: function(data){ >- $(node).replaceWith(data); >- }, >- }); >+ $.getJSON('/cgi-bin/koha/admin/ajax-updatedb-getinfos.pl', >+ { version: version }, >+ function(param) { >+ if ( param['errors'] ) { >+ $(node).replaceWith(_("Errors occured: ") + param['errors']); >+ } >+ var s; >+ s = "<b>" + _("Comments:") + "</b>"; >+ s += '<br/>'; >+ if ( param['comments'] ) { >+ s += param['comments']; >+ } else { >+ s += _("No comments"); >+ } >+ s += '<br/><br/>'; >+ >+ s += "<b>" + _("Queries:") + "</b>"; >+ s += '<br/>'; >+ if ( param['queries'] ) { >+ s += param['queries']; >+ } else { >+ s += _("No queries"); >+ } >+ $(node).replaceWith(s); >+ } >+ ); > } > //]]> > </script> >@@ -56,16 +73,30 @@ > <li> > [% report_loo.version %] -- > [% FOREACH r IN report_loo.report %] >- [% IF r.error.error == "ALREADY_EXISTS" %] >- This file ( [% r.error.filepath %] ) still already execute in version [% r.error.old_version %] : same md5 ([% r.error.md5 %]) >- [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% report_loo.version %]">Mark as OK</a>] >- [% ELSIF r.error.error == "LOAD_FUNCTIONS_FAILED" %] >- Load functions in [% r.error.filename %] failed >- [% ELSIF r.error.error == "BAD_EXTENSION" %] >- This extension ([% r.error.extension %]) is not take into account (only .pl or .sql)"; >+ [% IF r.error.error == "ALREADY_EXISTS" %] >+ <span style="color:orange;"> >+ [% r.error.filepath %] already executed in version [% r.error.old_version %] : same md5 ([% r.error.md5 %]) >+ [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% report_loo.version %]">Mark as OK</a>] >+ </span> >+ [% ELSIF r.error.error == "LOAD_FUNCTIONS_FAILED" %] >+ <span style="color:red;"> >+ Load functions in [% r.error.filename %] failed ([% r.error.error_str %]) >+ </span> >+ [% ELSIF r.error.error == "BAD_EXTENSION" %] >+ <span style="color:red;"> >+ This extension ([% r.error.extension %]) is not take into account (only .pl or .sql)"; >+ </span> >+ [% ELSE %] >+ [% IF r.error == "OK" %] >+ <span style="color:green;"> >+ [% r.error %]; >+ </span> > [% ELSE %] >+ <span style="color:red;"> > [% r.error %]; >+ </span> > [% END %] >+ [% END %] > [% END %] > </li> > [% END %] >@@ -96,9 +127,8 @@ > <thead> > <tr> > <th>DB revision</th> >- <th>Comments</th> > <th>Status</th> >- <th>Availability</th> >+ <th>Comments</th> > <th>Details</th> > </tr> > </thead> >@@ -107,74 +137,70 @@ > <tr> > <td>[% v.version %]</td> > <td> >- [% FOREACH c IN v.comments %] >- [% c.comment %] >- [% END %] >- </td> >- <td> > [% IF v.available %] >- Unknown >+ Not applied >+ [% IF (dev_mode) %] >+ [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% v.version %]">Execute</a>] >+ [% END %] > [% ELSE %] >- [% IF v.status %] >- <span style="color:green;">OK</span> >- [% IF v.status == 2 %] >- [FORCED] >- [% END %] >- [% ELSE %] >- <span style="color:red;">Failed</span> >+ [% SWITCH v.status %] >+ [% CASE 0 %] >+ <span style="color:red;">Applied and failed</span> >+ [% CASE 1 %] >+ <span style="color:green;">Applied and OK</span> >+ [% CASE 2 %] >+ <span style="color:green;">Applied and Forced</span> >+ [% CASE %] >+ <span style="color:red;">Status does not exist !</span> > [% END %] > [% END %] > </td> > <td> >- [% IF v.available %] >- Available >- [% IF (dev_mode) %] >- [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% v.version %]">Execute</a>] >- [% END %] >- [% ELSE %] >- Already executed >+ [% FOREACH c IN v.comments %] >+ [% c.comment %]<br/> > [% END %] > </td> > <td width="50%"> >+ [% IF v.available %] >+ <span style="display:block;"><a href="#" onclick="get_infos('[% v.version %]', this); return false;">Get comments</a></span> >+ [% ELSE %] > <div class="details" style="display:none;"> >- [% IF v.available %] >- Unknown >- <span style="display:block;"><a href="#" onclick="get_infos('[% v.version %]', this); return false;">Get comments</a></span> >- [% ELSE %] >- <div class="queries" style="display:block;"> >- <span class="underline">Queries</span> : >- [% FOREACH q IN v.queries %] >- [% q.query %]<br/> >- [% END %] >- </div> >- [% IF v.status == 1 %] >- <div class="status" style="display:block;"> >- <span class="underline">Status</span> : >- <span style="color:green;">OK</span> >- </div> >- [% ELSE %] >- <div class="status" style="display:block;"> >- <span class="underline">Status</span> : >- [% IF v.status == 2 %] >- <span style="color:green;">OK</span> >- [FORCED] >- [% ELSE %] >- <span style="color:red;">Failed</span> >- [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% v.version %]">Mark as OK</a>] >- [% END %] >- </div> >- <div class="errors" style="display:block;"> >- <span class="underline">Errors</span> : >- <span class="errors"> >- [% FOREACH e IN v.errors %] >- <span>[% e.error %]</span> >- [% END %] >- </span> >- </div> >+ <div class="queries" style="display:block;"> >+ <b>Queries</b> : >+ <ul> >+ [% FOREACH q IN v.queries %] >+ <li>[% q.query %]<br/></li> >+ [% END %] >+ </ul> >+ </div> >+ [% IF v.status == 1 %] >+ <div class="status" style="display:block;"> >+ <b>Status</b> : >+ <span style="color:green;">OK</span> >+ </div> >+ [% ELSE %] >+ <div class="status" style="display:block;"> >+ <b>Status</b> : >+ [% IF v.status == 2 %] >+ <span style="color:green;">OK</span> >+ [FORCED] >+ [% ELSE %] >+ <span style="color:red;">Failed</span> >+ [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% v.version %]">Mark as OK</a>] >+ [% END %] >+ </div> >+ <div class="errors" style="display:block;"> >+ <b>Errors</b> : >+ <ul> >+ [% FOREACH e IN v.errors %] >+ <li><span>[% e.error %]</span></li> > [% END %] >- [% END %] >+ </ul> >+ </div> >+ [% END %] > </div> > <a href="#" onclick="see_details(this);return false;">Show details</a> >+ [% END %] > </td> > </tr> > [% END %] >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7167
:
6377
|
6378
|
6379
|
6381
|
6414
|
6415
|
6416
|
6476
|
6477
|
6478
|
6479
|
6722
|
6832
|
7903
|
8178
|
9859
|
9860
|
9861
|
9862
|
10033
|
10034
|
10549
|
10666
|
10667
|
10668
|
10825
|
11129
|
11222
|
11223
|
11224
|
11225
|
11226
|
11227
|
11228
|
11229
|
11230
|
11231
|
11232
|
11235
|
11236
|
11237
|
11238
|
11239
|
11240
|
11241
|
11242
|
11243
|
11244
|
11245
|
11246
|
11571
|
13423
|
13424
|
13425
|
13426
|
13427
|
13428
|
13429
|
13430
|
13431
|
13432
|
13433
|
13434
|
13435
|
13436
|
13437
|
13456
|
13457
|
13509
|
13516
|
13517
|
13518
|
13519
|
13520
|
13521
|
13522
|
13523
|
13524
|
13525
|
13526
|
13527
|
13528
|
13529
|
13733
|
13734
|
13842
|
13845
|
13848
|
13851
|
13852
|
13853
|
13854
|
14310
|
16113
|
16114
|
16115
|
16116
|
16117
|
16596