From 77fafed47cb58cf6b03f7dc7630ee9638d547902 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 23 Oct 2013 14:27:45 +0200 Subject: [PATCH] Bug 7372: Move road types from the roadtype table to the ROADTYPE AV Currently road types are stored in a specific table in DB. Moreover, an admin page is present in order to manage them. This patch proposes to remove this table and this page in favour of a new authorised value category 'ROADTYPE'. This patch: - adds a new AV category 'ROADTYPE' (created from the roadtype table content). - remove the roadtype table. - remove the .pl and .tt file admin/roadtype - remove the 2 routines C4::Members::GetRoadTypes and C4::Members::GetRoadTypeDetails Test plan: 1/ Execute the updatedatabase entry and verify existing roadtypes are now stored in the AV 'ROADTYPE'. 2/ Verify you can add/update a streettype for patrons. 3/ Verify on following pages the streettype is displayed in patron information (top left): circ/circulation.pl members/memberentry.pl members/moremember.pl members/routing-lists.pl Signed-off-by: Sophie Meynieux --- C4/Members.pm | 67 --------- admin/roadtype.pl | 129 ----------------- circ/circulation.pl | 2 +- installer/data/mysql/updatedatabase.pl | 31 +++++ .../intranet-tmpl/prog/en/includes/admin-menu.inc | 1 - .../prog/en/modules/admin/admin-home.tt | 3 - .../prog/en/modules/admin/roadtype.tt | 147 -------------------- .../prog/en/modules/members/memberentrygen.tt | 14 +- .../prog/en/modules/members/moremember.tt | 4 +- members/memberentry.pl | 15 +- members/moremember.pl | 4 +- members/routing-lists.pl | 4 +- 12 files changed, 50 insertions(+), 371 deletions(-) delete mode 100755 admin/roadtype.pl delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/roadtype.tt diff --git a/C4/Members.pm b/C4/Members.pm index 29eda68..a0769ca 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -71,8 +71,6 @@ BEGIN { &GetAge &GetCities - &GetRoadTypes - &GetRoadTypeDetails &GetSortDetails &GetTitles @@ -1860,48 +1858,6 @@ EOF return 0; } -=head2 GetRoadTypes (OUEST-PROVENCE) - - ($idroadtypearrayref, $roadttype_hashref) = &GetRoadTypes(); - -Looks up the different road type . Returns two -elements: a reference-to-array, which lists the id_roadtype -codes, and a reference-to-hash, which maps the road type of the road . - -=cut - -sub GetRoadTypes { - my $dbh = C4::Context->dbh; - my $query = qq| -SELECT roadtypeid,road_type -FROM roadtype -ORDER BY road_type|; - my $sth = $dbh->prepare($query); - $sth->execute(); - my %roadtype; - my @id; - - # insert empty value to create a empty choice in cgi popup - - while ( my $data = $sth->fetchrow_hashref ) { - - push @id, $data->{'roadtypeid'}; - $roadtype{ $data->{'roadtypeid'} } = $data->{'road_type'}; - } - -#test to know if the table contain some records if no the function return nothing - my $id = @id; - if ( $id eq 0 ) { - return (); - } - else { - unshift( @id, "" ); - return ( \@id, \%roadtype ); - } -} - - - =head2 GetTitles (OUEST-PROVENCE) ($borrowertitle)= &GetTitles(); @@ -2001,29 +1957,6 @@ sub GetHideLostItemsPreference { return $hidelostitems; } -=head2 GetRoadTypeDetails (OUEST-PROVENCE) - - ($roadtype) = &GetRoadTypeDetails($roadtypeid); - -Returns the description of roadtype -C<&$roadtype>return description of road type -C<&$roadtypeid>this is the value of roadtype s - -=cut - -sub GetRoadTypeDetails { - my ($roadtypeid) = @_; - my $dbh = C4::Context->dbh; - my $query = qq| -SELECT road_type -FROM roadtype -WHERE roadtypeid=?|; - my $sth = $dbh->prepare($query); - $sth->execute($roadtypeid); - my $roadtype = $sth->fetchrow; - return ($roadtype); -} - =head2 GetBorrowersToExpunge $borrowers = &GetBorrowersToExpunge( diff --git a/admin/roadtype.pl b/admin/roadtype.pl deleted file mode 100755 index 6dd4a16..0000000 --- a/admin/roadtype.pl +++ /dev/null @@ -1,129 +0,0 @@ -#! /usr/bin/perl - -# Copyright 2006 SAN OUEST-PROVENCE et Paul POULAIN -# -# 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 strict; -use warnings; - -use CGI; -use C4::Context; -use C4::Output; -use C4::Auth; - - -sub StringSearch { - my $sth = C4::Context->dbh->prepare("Select * from roadtype where (road_type like ?) ORDER BY road_type"); - $sth->execute((shift || '') . '%'); - return $sth->fetchall_arrayref({}); -} - -my $input = new CGI; -my $searchfield=$input->param('road_type'); -my $script_name="/cgi-bin/koha/admin/roadtype.pl"; -my $roadtypeid=$input->param('roadtypeid'); -my $op = $input->param('op') || ''; - -my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "admin/roadtype.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => {parameters => 'parameters_remaining_permissions'}, - debug => 1, - }); - - -$template->param( script_name => $script_name, - roadtypeid => $roadtypeid , - searchfield => $searchfield); - - -################## ADD_FORM ################################## -# called by default. Used to create form to add or modify a record -if ($op eq 'add_form') { - $template->param(add_form => 1); - - #---- if primkey exists, it's a modify action, so read values to modify... - my $data; - if ($roadtypeid) { - my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select roadtypeid,road_type from roadtype where roadtypeid=?"); - $sth->execute($roadtypeid); - $data=$sth->fetchrow_hashref; - $sth->finish; - } - - $template->param( - road_type => $data->{'road_type'}, - ); -##############ICI##################### -# END $OP eq ADD_FORM -################## ADD_VALIDATE ################################# -# called by add_form, used to insert/modify data in DB -} elsif ($op eq 'add_validate') { - my $dbh = C4::Context->dbh; - my $sth; - - if ($input->param('roadtypeid') ){ - $sth=$dbh->prepare("UPDATE roadtype SET road_type=? WHERE roadtypeid=?"); - $sth->execute($input->param('road_type'),$input->param('roadtypeid')); - - } - else{ - $sth=$dbh->prepare("INSERT INTO roadtype (road_type) VALUES (?)"); - $sth->execute($input->param('road_type')); - } - $sth->finish; - print $input->redirect("/cgi-bin/koha/admin/roadtype.pl"); - exit; - -# END $OP eq ADD_VALIDATE -################## DELETE_CONFIRM ################################## -# called by default form, used to confirm deletion of data in DB -} elsif ($op eq 'delete_confirm') { - $template->param(delete_confirm => 1); - my $dbh = C4::Context->dbh; - my $sth2=$dbh->prepare("select roadtypeid,road_type from roadtype where roadtypeid=?"); - $sth2->execute($roadtypeid); - my $data=$sth2->fetchrow_hashref; - $sth2->finish; - - $template->param( - road_type => ( $data->{'road_type'}), - ); - - - # END $OP eq DELETE_CONFIRM -################## DELETE_CONFIRMED ################################## -# called by delete_confirm, used to effectively confirm deletion of data in DB -} elsif ($op eq 'delete_confirmed') { - my $dbh = C4::Context->dbh; - my $categorycode=uc($input->param('roadtypeid')); - my $sth=$dbh->prepare("delete from roadtype where roadtypeid=?"); - $sth->execute($roadtypeid); - $sth->finish; - print "Content-Type: text/html\n\n"; - exit; - # END $OP eq DELETE_CONFIRMED -} else { # DEFAULT - $template->param(else => 1); - $template->param(loop => StringSearch($searchfield)); - - -} #---- END $OP eq DEFAULT -output_html_with_http_headers $input, $cookie, $template->output; diff --git a/circ/circulation.pl b/circ/circulation.pl index 7d214ea..509cd1d 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -686,7 +686,7 @@ if($bor_messages_loop){ $template->param(flagged => 1 ); } # Computes full borrower address my @fulladdress; push @fulladdress, $borrower->{'streetnumber'} if ( $borrower->{'streetnumber'} ); -push @fulladdress, &GetRoadTypeDetails( $borrower->{'streettype'} ) if ( $borrower->{'streettype'} ); +push @fulladdress, C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $borrower->{'streettype'} ) if ( $borrower->{'streettype'} ); push @fulladdress, $borrower->{'address'} if ( $borrower->{'address'} ); my $fast_cataloging = 0; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index f043d0b..a96419d 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7953,6 +7953,37 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->{AutoCommit} = 0; + $dbh->{RaiseError} = 1; + + my $av_added = $dbh->do(q| + INSERT INTO authorised_values(category, authorised_value, lib, lib_opac) + SELECT 'ROADTYPE', roadtypeid, road_type, road_type + FROM roadtype; + |); + + my $rt_deleted = $dbh->do(q| + DELETE FROM roadtype + |); + + if ( $av_added == $rt_deleted or $rt_deleted eq "0E0" ) { + $dbh->do(q| + DROP TABLE roadtype; + |); + $dbh->commit; + print "Upgrade to $DBversion done (Bug 7372: Move road types from the roadtype table to the ROADTYPE authorised values)\n"; + SetVersion($DBversion); + } else { + print "Upgrade to $DBversion failed (Bug 7372: Move road types from the roadtype table to the ROADTYPE authorised values.\nTransaction aborted because $@\n)"; + $dbh->rollback; + } + + $dbh->{AutoCommit} = 1; + $dbh->{RaiseError} = 0; +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc index 91878bf..ebd345c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc @@ -33,7 +33,6 @@
  • Transport cost matrix
  • Item circulation alerts
  • Cities and towns
  • -
  • Road types
  • Catalog
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt index 46a3b3a..217b069 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt @@ -56,9 +56,6 @@
    Define rules for check-in and checkout notifications for combinations of libraries, patron categories, and item types
    Cities and towns
    Define cities and towns that your patrons live in.
    -
    Road types -
    -
    Define road types (street, avenue, way, etc.). Road types display as authorized values when adding/editing patrons and can be used in geographic statistics.
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/roadtype.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/roadtype.tt deleted file mode 100644 index ad491fd..0000000 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/roadtype.tt +++ /dev/null @@ -1,147 +0,0 @@ -[% INCLUDE 'doc-head-open.inc' %] -Koha › Administration › [% IF ( add_form ) %]Road types › [% IF ( roadtypeid ) %] Modify road type[% ELSE %] New road type[% END %][% ELSE %][% IF ( delete_confirm ) %]Road types › Confirm deletion of road type[% ELSE %] Road type[% END %][% END %] -[% INCLUDE 'doc-head-close.inc' %] - - - -[% INCLUDE 'header.inc' %] -[% INCLUDE 'roadtype-admin-search.inc' %] - - -
    - -
    -
    -
    - -[% IF ( add_form ) %] - [% IF ( roadtypeid ) %] -

    Modify road type

    - [% ELSE %] -

    New road type

    - [% END %] - -
    - - - - -
      -[% IF ( roadtypeid ) %] -
    1. - Road type: [% roadtypeid %] -
    2. -[% END %] -
    3. - - -
    - -
    - Cancel -
    -
    -[% END %] - -[% IF ( delete_confirm ) %] -

    Delete road type "[% road_type %]?"

    - - - - - - - -
    Road type id: [% roadtypeid %]
    Road type: [% road_type %] -
    - -
    -
    -[% END %] - -[% IF ( else ) %] - - - -

    Road type

    - [% IF ( searchfield ) %] - Search on [% searchfield %] - [% END %] - -[% IF ( loop ) %] - - - - - [% FOREACH loo IN loop %] - [% UNLESS ( loop.odd ) %] - - [% ELSE %] - - [% END %] - - - - - [% END %] -
    Road type 
    [% loo.road_type %]EditDelete
    [% END %] -[% END %] - -
    -
    -
    -[% INCLUDE 'admin-menu.inc' %] -
    -
    -[% INCLUDE 'intranet-bottom.inc' %] - - diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 05b5b4e..469bbbd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -218,7 +218,6 @@ - @@ -456,7 +455,7 @@ [% END %] [% UNLESS nostreettype %] - [% IF ( road_cgipopup ) %] + [% IF roadtypes %]
  • [% IF ( mandatorystreettype ) %]
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index 79d319e..cd2b0be 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -211,9 +211,7 @@ function validate1(date) { [% UNLESS ( I ) %][% IF ( othernames ) %]“[% othernames %]”[% END %]

    [% streetnumber %] - [% IF ( roaddetails ) %] - [% roaddetails %] - [% END %] + [% IF roadtype %][% roadtype %][% END %] [% address %]
    [% IF ( address2 ) %][% address2 %]
    [% END %] [% IF ( city ) %][% city %][% END %] diff --git a/members/memberentry.pl b/members/memberentry.pl index 3d68e49..429768a 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -204,7 +204,6 @@ if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) qr/^nodouble$/, qr/^op$/, qr/^save$/, - qr/^select_roadtype$/, qr/^updtype$/, qr/^SMSnumber$/, qr/^setting_extended_patron_attributes$/, @@ -549,17 +548,8 @@ if (@{$city_arrayref} ) { } } -my $default_roadtype; -$default_roadtype=$data{'streettype'} ; -my($roadtypeid,$road_type)=GetRoadTypes(); - $template->param( road_cgipopup => 1) if ($roadtypeid ); -my $roadpopup = CGI::popup_menu(-name=>'streettype', - -id => 'streettype', - -values=>$roadtypeid, - -labels=>$road_type, - -override => 1, - -default=>$default_roadtype - ); +my $roadtypes = C4::Koha::GetAuthorisedValues( 'ROADTYPE', $data{streettype} ); +$template->param( roadtypes => $roadtypes); my $default_borrowertitle = ''; unless ( $op eq 'duplicate' ) { $default_borrowertitle=$data{'title'} } @@ -731,7 +721,6 @@ $template->param( ethcatpopup => $ethcatpopup, relshiploop => \@relshipdata, city_loop => $city_arrayref, - roadpopup => $roadpopup, borrotitlepopup => $borrotitlepopup, guarantorinfo => $guarantorinfo, flagloop => \@flagdata, diff --git a/members/moremember.pl b/members/moremember.pl index adce9d2..e794efa 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -246,7 +246,7 @@ my $relissue = []; if ( @borrowernumbers ) { $relissue = GetPendingIssues(@borrowernumbers); } -my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} ); +my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $data->{streettype} ); my $today = DateTime->now( time_zone => C4::Context->tz); $today->truncate(to => 'day'); my @borrowers_with_issues; @@ -412,7 +412,7 @@ $template->param( detailview => 1, AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"), CANDELETEUSER => $candeleteuser, - roaddetails => $roaddetails, + roadtype => $roadtype, borrowernumber => $borrowernumber, othernames => $data->{'othernames'}, categoryname => $data->{'description'}, diff --git a/members/routing-lists.pl b/members/routing-lists.pl index 70165f7..6331d07 100755 --- a/members/routing-lists.pl +++ b/members/routing-lists.pl @@ -101,8 +101,8 @@ if ($borrowernumber) { # Computes full borrower address -my (undef, $roadttype_hashref) = &GetRoadTypes(); -my $address = $borrower->{'streetnumber'}.' '.$roadttype_hashref->{$borrower->{'streettype'}}.' '.$borrower->{'address'}; +my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $borrower->{streettype} ); +my $address = $borrower->{'streetnumber'} . " $roadtype " . $borrower->{'address'}; $template->param( -- 1.7.10.4