Bugzilla – Attachment 13523 Details for
Bug 7167
updatedatabase improvements
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7167: FIX typos & moving a script to a proper place
Bug-7167-FIX-typos--moving-a-script-to-a-proper-pl.patch (text/plain), 16.15 KB, created by
Chris Nighswonger
on 2012-11-19 15:46:06 UTC
(
hide
)
Description:
Bug 7167: FIX typos & moving a script to a proper place
Filename:
MIME Type:
Creator:
Chris Nighswonger
Created:
2012-11-19 15:46:06 UTC
Size:
16.15 KB
patch
obsolete
>From 0011843d0c72732687abbb6fbeb0eb158916de11 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 31 Jul 2012 15:42:57 +0200 >Subject: [PATCH] Bug 7167: FIX typos & moving a script to a proper place >Content-Type: text/plain; charset="utf-8" > >* renamed availables to available >* renamed already_knows to already_applied >* fixed FSF & copyright headers >* removing a "use strict" because we already had use Modern::Perl >* fixed a tiny typo in about.tt > >* moving update.pl to misc/bin because it's a CLI script > >Signed-off-by: Paul Poulain <paul.poulain@biblibre.com> >Signed-off-by: Chris Nighswonger <cnighswonger@foundations.edu> >--- > C4/Installer.pm | 2 +- > C4/Update/Database.pm | 21 ++-- > about.pl | 4 +- > admin/ajax-updatedb-getinfos.pl | 2 +- > admin/updatedatabase.pl | 17 +-- > installer/data/mysql/update.pl | 85 --------------- > koha-tmpl/intranet-tmpl/prog/en/modules/about.tt | 2 +- > .../prog/en/modules/admin/updatedatabase.tt | 15 +-- > misc/bin/updatedb.pl | 112 ++++++++++++++++++++ > 9 files changed, 145 insertions(+), 115 deletions(-) > delete mode 100644 installer/data/mysql/update.pl > create mode 100644 misc/bin/updatedb.pl > >diff --git a/C4/Installer.pm b/C4/Installer.pm >index 4b86f1c..759a6be 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -468,7 +468,7 @@ Koha software version. > sub set_version_syspref { > my $self = shift; > # get all updatedatabase, and mark them as passed, as it's a fresh install >- my $versions = C4::Update::Database::list_versions_availables(); >+ my $versions = C4::Update::Database::list_versions_available(); > for my $v ( @$versions ) { > my $queries; > $queries->{queries} = ["initial setup"]; >diff --git a/C4/Update/Database.pm b/C4/Update/Database.pm >index b7106b3..c9c180e 100644 >--- a/C4/Update/Database.pm >+++ b/C4/Update/Database.pm >@@ -1,6 +1,6 @@ > package C4::Update::Database; > >-# Copyright 2011 BibLibre >+# Copyright Biblibre 2012 > # > # This file is part of Koha. > # >@@ -158,15 +158,14 @@ sub execute_version { > return $report; > } > >-=head2 list_versions_availables >+=head2 list_versions_available > >- my @versions = list_versions_availables; >+ my @versions = list_versions_available; > return an array with all version available >- This list is retrieved from the directory defined in the etc/update/database/config.yaml, versions_dir parameter > > =cut > >-sub list_versions_availables { >+sub list_versions_available { > my @versions; > > my @files = File::Find::Rule->file->name( "*.sql", "*.pl" ) ->in( ( $VERSIONS_PATH ) ); >@@ -179,15 +178,15 @@ sub list_versions_availables { > return \@versions; > } > >-=head2 list_versions_already_knows >+=head2 list_versions_already_applied > >- my @versions = list_versions_availables; >+ my @versions = list_versions_available; > return an array with all version that have already been applied > This sub check first that the updatedb tables exist and create them if needed > > =cut > >-sub list_versions_already_knows { >+sub list_versions_already_applied { > # 1st check if tables exist, otherwise create them > $dbh->do(qq{ > CREATE TABLE IF NOT EXISTS `updatedb_error` ( `version` varchar(32) DEFAULT NULL, `error` text ) ENGINE=InnoDB CHARSET=utf8; >@@ -489,9 +488,9 @@ sub mark_as_ok { > The database is up to date if all versions are excecuted. > =cut > sub is_uptodate { >- my $versions_availables = C4::Update::Database::list_versions_availables; >- my $versions = C4::Update::Database::list_versions_already_knows; >- for my $v ( @$versions_availables ) { >+ my $versions_available = C4::Update::Database::list_versions_available; >+ my $versions = C4::Update::Database::list_versions_already_applied; >+ for my $v ( @$versions_available ) { > if ( not grep { $v eq $$_{version} } @$versions ) { > return 0; > } >diff --git a/about.pl b/about.pl >index de949cb..f00129b 100755 >--- a/about.pl >+++ b/about.pl >@@ -58,12 +58,12 @@ my $dbrev_applied=""; # the list of database revisions > > # the $kohaVersion is duplicated since 3.7: the 3.6 (that uses the old mechanism) and the 3.7 (new mechanism). > # Both versions reflects how the database has been upgraded >-my $already_knows = C4::Update::Database::list_versions_already_knows(); >+my $already_applied = C4::Update::Database::list_versions_already_applied(); > # $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 > my $last_known=0; > # $last_known_sep contains the previous DBrev applied with the separator (used for display) > my $last_known_sep=""; >-for my $v ( @$already_knows ) { >+for my $v ( @$already_applied ) { > my $current = $v->{version}; > $current =~s/\.//g; > # if the current number is the previous one +1, then just add a ., for a better display N.........N+10, for example >diff --git a/admin/ajax-updatedb-getinfos.pl b/admin/ajax-updatedb-getinfos.pl >index fb91613..fe733a8 100755 >--- a/admin/ajax-updatedb-getinfos.pl >+++ b/admin/ajax-updatedb-getinfos.pl >@@ -1,6 +1,6 @@ > #!/usr/bin/perl > >-# Copyright 2011 BibLibre >+# Copyright BibLibre 2012 > # > # This file is part of Koha. > # >diff --git a/admin/updatedatabase.pl b/admin/updatedatabase.pl >index 3b660ac..013414d 100755 >--- a/admin/updatedatabase.pl >+++ b/admin/updatedatabase.pl >@@ -1,5 +1,7 @@ > #!/usr/bin/perl > >+# Copyright Biblibre 2012 >+# > # This file is part of Koha. > # > # Koha is free software; you can redistribute it and/or modify it under the >@@ -16,7 +18,6 @@ > # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > > use Modern::Perl; >-use strict; > use CGI; > use C4::Auth; > use C4::Output; >@@ -71,10 +72,10 @@ if ( $op eq 'mark_as_ok' ) { > } > > if ( $op eq 'list' ) { >- my $versions_availables = C4::Update::Database::list_versions_availables; >- my $versions = C4::Update::Database::list_versions_already_knows; >+ my $versions_available = C4::Update::Database::list_versions_available; >+ my $versions = C4::Update::Database::list_versions_already_applied; > >- for my $v ( @$versions_availables ) { >+ for my $v ( @$versions_available ) { > if ( not grep { $v eq $$_{version} } @$versions ) { > push @$versions, { > version => $v, >@@ -86,14 +87,14 @@ if ( $op eq 'list' ) { > C4::Update::Database::TransformToNum( $$a{version} ) <=> C4::Update::Database::TransformToNum( $$b{version} ) > } @$versions; > >- my @availables = grep { defined $$_{available} and $$_{available} == 1 } @sorted; >- my @v_availables = map { {version => $$_{version}} } @availables; >+ my @available = grep { defined $$_{available} and $$_{available} == 1 } @sorted; >+ my @v_available = map { {version => $$_{version}} } @available; > > $template->param( > dev_mode => $ENV{DEBUG}, > versions => \@sorted, >- nb_availables => scalar @availables, >- availables => [ map { {version => $$_{version}} } @availables ], >+ nb_available => scalar @available, >+ available => [ map { {version => $$_{version}} } @available ], > ); > } > >diff --git a/installer/data/mysql/update.pl b/installer/data/mysql/update.pl >deleted file mode 100644 >index 33e123f..0000000 >--- a/installer/data/mysql/update.pl >+++ /dev/null >@@ -1,85 +0,0 @@ >-use Modern::Perl; >- >-use C4::Context; >-use C4::Update::Database; >-use Getopt::Long; >- >-my $help; >-my $version; >-my $list; >-my $all; >-my $min; >- >-GetOptions( >- 'h|help|?' => \$help, >- 'm:s' => \$version, >- 'l|list' => \$list, >- 'a|all' => \$all, >- 'min:s' => \$min, >-); >- >-if ( $help or not ($version or $list or $all) ) { >- usage(); >- exit; >-} >- >-my @reports; >-if ( $version ) { >- my $report = C4::Update::Database::execute_version($version); >- push @reports, $report; >-} >- >-if ( $list ) { >- my $versions = C4::Update::Database::list_versions_availables(); >- say "Versions availables:"; >- say "\t- $_" for @$versions; >- $versions = C4::Update::Database::list_versions_already_knows(); >- say "Versions already knows:"; >- say "\t- $$_{version}" for @$versions; >- >-} >- >-if ( $all ) { >- my $versions_availables = C4::Update::Database::list_versions_availables(); >- my $versions = C4::Update::Database::list_versions_already_knows; >- my $min_version = $min >- ? $min =~ m/\d\.\d{2}\.\d{2}\.\d{3}/ >- ? C4::Update::Database::TransformToNum( $min ) >- : $min >- : 0; >- >- for my $v ( @$versions_availables ) { >- if ( not grep { $v eq $$_{version} } @$versions >- and C4::Update::Database::TransformToNum( $v ) >= $min_version >- ) { >- my $report = C4::Update::Database::execute_version $v; >- push @reports, $report; >- } >- } >-} >- >-if ( $version or $all ) { >- say @reports ? "Report:": "Nothing to report"; >- for my $report ( @reports ) { >- 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"; >- } >- } >-} >- >-sub usage { >- say "update.pl"; >- say "This script updates your database for you"; >- say "Usage:"; >- say "\t-h\tShow this help message"; >- say "\t-m\tExecute a given version"; >- say "\t-l\tList all the versions"; >- say "\t-all\tExecute all available versions"; >- say "\t-min\tWith -all, Execute all available versions since a given version"; >- say "\t\tCan be X.XX.XX.XXX or X.XXXXXXX"; >-} >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt >index 385f392..02d0d26 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt >@@ -37,7 +37,7 @@ > > <table> > <caption>Server information</caption> >- <tr><th scope="row">Koha version: </th><td>[% kohaVersion |html %] with the following database revisionapplied: [% dbrev_applied|html %]</td></tr> >+ <tr><th scope="row">Koha version: </th><td>[% kohaVersion |html %] with the following database revisions applied: [% dbrev_applied|html %]</td></tr> > <tr><th scope="row">OS version ('uname -a'): </th><td>[% osVersion |html %]</td></tr> > <tr><th scope="row">Perl interpreter: </th><td>[% perlPath |html %]</td></tr> > <tr><th scope="row">Perl version: </th><td>[% perlVersion |html %]</td></tr> >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 2c68f91..e0f9ceb 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/updatedatabase.tt >@@ -104,15 +104,15 @@ > </div> > [% END %] > <span class="infos" style="display:block; margin:1em;"> >- [% IF nb_availables %] >+ [% IF nb_available %] > Your datebase is not up to date.<br/> >- [% IF nb_availables == 1 %] >- 1 update available [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% availables.first.version %]">UPDATE [% availables.first.version %]</a>] >+ [% IF nb_available == 1 %] >+ 1 update available [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% available.first.version %]">UPDATE [% available.first.version %]</a>] > [% ELSE %] >- [% 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>]: >+ [% nb_available %] updates available [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update[% FOREACH av IN available %]&version=[% av.version %][% END %]">UPDATE ALL</a>]: > [% IF ( dev_mode ) %] > <ul> >- [% FOREACH av IN availables %] >+ [% FOREACH av IN available %] > <li>[% av.version %] [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=update&version=[% av.version %]">UPDATE</a>]</li> > [% END %] > </ul> >@@ -145,7 +145,10 @@ > [% ELSE %] > [% SWITCH v.status %] > [% CASE 0 %] >- <span style="color:red;">Applied and failed</span> >+ <span style="color:red;"> >+ Applied and failed >+ [<a href="/cgi-bin/koha/admin/updatedatabase.pl?op=mark_as_ok&version=[% v.version %]">Mark as OK</a>] >+ </span> > [% CASE 1 %] > <span style="color:green;">Applied and OK</span> > [% CASE 2 %] >diff --git a/misc/bin/updatedb.pl b/misc/bin/updatedb.pl >new file mode 100644 >index 0000000..b79d1b4 >--- /dev/null >+++ b/misc/bin/updatedb.pl >@@ -0,0 +1,112 @@ >+#!/usr/bin/perl >+ >+# Copyright Biblibre 2012 >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 2 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use C4::Context; >+use C4::Update::Database; >+use Getopt::Long; >+ >+my $help; >+my $version; >+my $list; >+my $all; >+my $min; >+ >+GetOptions( >+ 'h|help|?' => \$help, >+ 'm:s' => \$version, >+ 'l|list' => \$list, >+ 'a|all' => \$all, >+ 'min:s' => \$min, >+); >+ >+if ( $help or not( $version or $list or $all ) ) { >+ usage(); >+ exit; >+} >+ >+my @reports; >+if ($version) { >+ my $report = C4::Update::Database::execute_version($version); >+ push @reports, $report; >+} >+ >+if ($list) { >+ my $available = C4::Update::Database::list_versions_available(); >+ my $already_applied = C4::Update::Database::list_versions_already_applied(); >+ say "Versions available:"; >+ for my $v (@$available) { >+ if ( not grep { $v eq $_->{version} } @$already_applied ) { >+ say "\t- $_" for $v; >+ } >+ } >+ say "Versions already applied:"; >+ say "\t- $_->{version}" for @$already_applied; >+ >+} >+ >+if ($all) { >+ my $versions_available = C4::Update::Database::list_versions_available(); >+ my $versions = C4::Update::Database::list_versions_already_applied; >+ my $min_version = >+ $min >+ ? $min =~ m/\d\.\d{2}\.\d{2}\.\d{3}/ >+ ? C4::Update::Database::TransformToNum($min) >+ : $min >+ : 0; >+ >+ for my $v (@$versions_available) { >+ if ( not grep { $v eq $_->{version} } @$versions >+ and C4::Update::Database::TransformToNum($v) >= $min_version ) >+ { >+ my $report = C4::Update::Database::execute_version $v; >+ push @reports, $report; >+ } >+ } >+} >+ >+if ( $version or $all ) { >+ say @reports ? "Report:" : "Nothing to report"; >+ for my $report (@reports) { >+ 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"; >+ } >+ } >+} >+ >+sub usage { >+ say "update.pl"; >+ say "This script updates your database for you"; >+ say "Usage:"; >+ say "\t-h\tShow this help message"; >+ say "\t-m\tExecute a given version"; >+ say "\t-l\tList all the versions"; >+ say "\t-all\tExecute all available versions"; >+ say >+ "\t-min\tWith -all, Execute all available versions since a given version"; >+ say "\t\tCan be X.XX.XX.XXX or X.XXXXXXX"; >+} >-- >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