Bugzilla – Attachment 40928 Details for
Bug 12965
can create an item type that already exists
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12965: Prevent to erase an existing item type
Bug-12965-Prevent-to-erase-an-existing-item-type.patch (text/plain), 5.36 KB, created by
Jonathan Druart
on 2015-07-10 15:14:50 UTC
(
hide
)
Description:
Bug 12965: Prevent to erase an existing item type
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-07-10 15:14:50 UTC
Size:
5.36 KB
patch
obsolete
>From 0c81911b29739d9b81b0f9c2d5d77e8bb5249b59 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 10 Jul 2015 16:11:48 +0100 >Subject: [PATCH] Bug 12965: Prevent to erase an existing item type > >On creating an item type, if it already exists, it will replace the >existing one. >This patch prevent that and display a message to the interface. > >Note: The fields are lost. > >Test plan: >1/ Create an item type 'AAA', description 'AAA' >2/ Edit it, update the description with 'BBB' >3/ Create an item type 'AAA' with a description 'CCC' => you should get >a warning "already exists". >--- > admin/itemtypes.pl | 38 +++++++++++++--------- > .../prog/en/modules/admin/itemtypes.tt | 16 +++++++++ > 2 files changed, 38 insertions(+), 16 deletions(-) > >diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl >index 9effa7e..3aa9c1d 100755 >--- a/admin/itemtypes.pl >+++ b/admin/itemtypes.pl >@@ -69,7 +69,8 @@ my $input = new CGI; > my $searchfield = $input->param('description'); > my $script_name = "/cgi-bin/koha/admin/itemtypes.pl"; > my $itemtype = $input->param('itemtype'); >-my $op = $input->param('op'); >+my $op = $input->param('op') // 'list'; >+my @messages; > $searchfield =~ s/\,//g; > my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > { >@@ -85,8 +86,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > $template->param(script_name => $script_name); > if ($op) { > $template->param($op => 1); # we show only the TMPL_VAR names $op >-} else { >- $template->param(else => 1); > } > > my $dbh = C4::Context->dbh; >@@ -132,14 +131,13 @@ if ( $op eq 'add_form' ) { > # called by add_form, used to insert/modify data in DB > } > elsif ( $op eq 'add_validate' ) { >- my $query = " >+ my $is_a_modif = $input->param('is_a_modif'); >+ my ( $already_exists ) = $dbh->selectrow_array(q| > SELECT itemtype > FROM itemtypes > WHERE itemtype = ? >- "; >- my $sth = $dbh->prepare($query); >- $sth->execute($itemtype); >- if ( $sth->fetchrow ) { # it's a modification >+ |, undef, $itemtype ); >+ if ( $already_exists and $is_a_modif ) { # it's a modification > my $query2 = ' > UPDATE itemtypes > SET description = ? >@@ -152,7 +150,7 @@ elsif ( $op eq 'add_validate' ) { > , sip_media_type = ? > WHERE itemtype = ? > '; >- $sth = $dbh->prepare($query2); >+ my $sth = $dbh->prepare($query2); > $sth->execute( > $input->param('description'), > $input->param('rentalcharge'), >@@ -171,7 +169,7 @@ elsif ( $op eq 'add_validate' ) { > $input->param('itemtype') > ); > } >- else { # add a new itemtype & not modif an old >+ elsif ( not $already_exists and not $is_a_modif ) { > my $query = " > INSERT INTO itemtypes > (itemtype,description,rentalcharge, notforloan, imageurl, summary, checkinmsg, checkinmsgtype, sip_media_type) >@@ -194,10 +192,15 @@ elsif ( $op eq 'add_validate' ) { > $sip_media_type, > ); > } >+ else { >+ push @messages, { >+ type => 'error', >+ code => 'already_exists', >+ }; >+ } > >- print $input->redirect('itemtypes.pl'); >- exit; >- >+ $searchfield = ''; >+ $op = 'list'; > # END $OP eq ADD_VALIDATE > ################## DELETE_CONFIRM ################################## > # called by default form, used to confirm deletion of data in DB >@@ -244,7 +247,8 @@ elsif ( $op eq 'delete_confirmed' ) { > # END $OP eq DELETE_CONFIRMED > ################## DEFAULT ################################## > } >-else { # DEFAULT >+ >+if ( $op eq 'list' ) { > my ($results) = StringSearch( $searchfield, 'web' ); > my @loop; > foreach my $itemtype ( @{$results} ) { >@@ -254,8 +258,10 @@ else { # DEFAULT > } > > $template->param( >- loop => \@loop, >+ loop => \@loop, >+ else => 1, >+ messages => \@messages, > ); >-} #---- END $OP eq DEFAULT >+} > > output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt >index 2e61a16..a3d8af4 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt >@@ -85,6 +85,21 @@ Item types administration > <a class="btn btn-small" id="newitemtype" href="/cgi-bin/koha/admin/itemtypes.pl?op=add_form"><i class="icon-plus"></i> New item type</a> > </div>[% END %] > >+[% FOREACH message IN messages %] >+ [% IF message.type == 'success' %] >+ <div class="dialog message"> >+ [% ELSIF message.type == 'warning' %] >+ <div class="dialog alert"> >+ [% ELSIF message.type == 'error' %] >+ <div class="dialog error" style="margin:auto;"> >+ [% END %] >+ [% IF message.code == 'already_exists' %] >+ This item type already exists. >+ [% END %] >+ </div> >+[% END %] >+ >+ > [% IF ( add_form ) %] > [% IF ( itemtype ) %] > <h3>Modify item type</h3> >@@ -99,6 +114,7 @@ Item types administration > <ol> > [% IF ( itemtype ) %] > <li> >+ <input type="hidden" name="is_a_modif" value="1" /> > <span class="label">Item type: </span> <input type="hidden" name="itemtype" value="[% itemtype %]" /> > [% itemtype %] > </li> >-- >2.1.0
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 12965
:
40928
|
40942
|
41456
|
42181