Bugzilla – Attachment 59564 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]
Bug 17944 - Removed the sql code from Itemtypes.pm and replaced it with DBIx database query in the itemtypes.pl administrative script
Bug-17944---Removed-the-sql-code-from-Itemtypespm-.patch (text/plain), 3.34 KB, created by
Alex Buckley
on 2017-01-26 01:56:39 UTC
(
hide
)
Description:
Bug 17944 - Removed the sql code from Itemtypes.pm and replaced it with DBIx database query in the itemtypes.pl administrative script
Filename:
MIME Type:
Creator:
Alex Buckley
Created:
2017-01-26 01:56:39 UTC
Size:
3.34 KB
patch
obsolete
>From 975bea39cff714eb4d827a5b6f5e03657606eab6 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] Bug 17944 - 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 >--- > 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