Bugzilla – Attachment 59656 Details for
Bug 17944
Remove the sql code from itemtypes.pl administrative perl script
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 17944 - Removed the sql code from Itemtypes.pm
SIGNED-OFF-Bug-17944---Removed-the-sql-code-from-I.patch (text/plain), 3.47 KB, created by
Owen Leonard
on 2017-01-30 16:08:06 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 17944 - Removed the sql code from Itemtypes.pm
Filename:
MIME Type:
Creator:
Owen Leonard
Created:
2017-01-30 16:08:06 UTC
Size:
3.47 KB
patch
obsolete
>From 8d77b091e58bfd76986fa594582b554ec0c5f41b Mon Sep 17 00:00:00 2001 >From: Alex Buckley <alexbuckley@catalyst.net.nz> >Date: Thu, 26 Jan 2017 14:40:12 +1300 >Subject: [PATCH] [SIGNED-OFF] Bug 17944 - Removed the sql code from > Itemtypes.pm > >Removed the sql code from Itemtypes.pm and replaced it with DBIx >database query in the itemtypes.pl administrative script > >Test plan: >1. In the staff interface, stage and manage MARC records for import > >2. Try to delete an itemtype. If there are items of that itemtype in the > database then a message telling you the number of items of that > itemtype there are will be displayed. > >3. Record that number > >4. View the admin/itemtpes.pl script and confirm that there is sql code > written in this file. > >5. Apply this patch > >6. View the admin/itemtypes.pl script and observe that there is no sql > in this file. There is however DBIx code, for example > $schema->resultset('Item')->search({ 'itype' => $itemtype_code} ); > which is searching for items with the itype value matching > $itemtype_code value. > >7. In the staff interface try to delete the same itemtype > >8. Record the number of items there are with that itemtype in the > resulting message > >9. The numbers recorded in steps 3 and 8 should match showing that the > DBIx code is working as intended > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> >--- > Koha/ItemTypes.pm | 17 ----------------- > admin/itemtypes.pl | 17 +++++++++++++---- > 2 files changed, 13 insertions(+), 21 deletions(-) > >diff --git a/Koha/ItemTypes.pm b/Koha/ItemTypes.pm >index 9eb26df..92fea9c 100644 >--- a/Koha/ItemTypes.pm >+++ b/Koha/ItemTypes.pm >@@ -39,23 +39,6 @@ Koha::ItemTypes - Koha ItemType Object set class > > =cut > >-sub check_items_and_biblioitems { >- my ($itemtype_code) = @_; >- >- my $dbh = C4::Context->dbh; >- >- # Check both items and biblioitems >- my ($total) = $dbh->selectrow_array( ' >- SELECT COUNT(*) AS total FROM ( >- SELECT itemtype AS t FROM biblioitems >- UNION ALL >- SELECT itype AS t FROM items >- ) AS tmp >- WHERE tmp.t=? >- ', {}, $itemtype_code ); >- return $total; >-} >- > sub _type { > return 'Itemtype'; > } >diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl >index 81bb391..fd2bded 100755 >--- a/admin/itemtypes.pl >+++ b/admin/itemtypes.pl >@@ -137,12 +137,20 @@ if ( $op eq 'add_form' ) { > > $searchfield = ''; > $op = 'list'; >-} elsif ( $op eq 'delete_confirm' ) { > >- my $total = Koha::ItemTypes->check_items_and_biblioitems($itemtype_code); >+ } elsif ( $op eq 'delete_confirm' ) { > >- if ($total) { >- push @messages, { type => 'error', code => 'cannot_be_deleted', total => $total }; >+ my $context = C4::Context->new; >+ my $schema = Koha::Database->new()->schema(); >+ my $itemtotal = $schema->resultset('Item')->search({ 'itype' => $itemtype_code} ); >+ my $bibliototal = $schema->resultset('Biblioitem')->search({ 'itemtype' => $itemtype_code} ); >+ >+ $itemtotal->count; >+ $bibliototal->count; >+ my $overalltotal = $itemtotal + $bibliototal; >+ >+ if ($overalltotal) { >+ push @messages, { type => 'error', code => 'cannot_be_deleted', total => $overalltotal }; > $op = 'list'; > } else { > my $itemtype = Koha::ItemTypes->find($itemtype_code); >@@ -150,6 +158,7 @@ if ( $op eq 'add_form' ) { > } > > } elsif ( $op eq 'delete_confirmed' ) { >+ > my $itemtype = Koha::ItemTypes->find($itemtype_code); > my $deleted = eval { $itemtype->delete }; > if ( $@ or not $deleted ) { >-- >2.1.4
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 17944
:
59391
|
59564
|
59565
|
59655
|
59656
|
59657
|
59715
|
59716
|
59717
|
59718
|
59953
|
59954
|
62499
|
62500
|
62501
|
62502
|
62503
|
62504
|
62505
|
63045
|
63152
|
63220
|
63259
|
63307
|
63308
|
63309
|
63310
|
63924
|
63925