Bugzilla – Attachment 24121 Details for
Bug 11518
Add new method to Koha::Schema::Result::Item that will always return the correct itemtype
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11518 - Add new method to Koha::Schema::Result::Item that will always return the correct itemtype
Bug-11518---Add-new-method-to-KohaSchemaResultItem.patch (text/plain), 3.54 KB, created by
Kyle M Hall (khall)
on 2014-01-10 13:07:21 UTC
(
hide
)
Description:
Bug 11518 - Add new method to Koha::Schema::Result::Item that will always return the correct itemtype
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2014-01-10 13:07:21 UTC
Size:
3.54 KB
patch
obsolete
>From 2c1a1b2564197c8d8c9a5f82ceef7dd99bfa8eeb Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Fri, 10 Jan 2014 08:03:59 -0500 >Subject: [PATCH] Bug 11518 - Add new method to Koha::Schema::Result::Item that will always return the correct itemtype > >There are many disparate areas of Koha that deal with item level >itemtypes vs record level itemtypes. We can take advantage of >DBIx::Class to make smarter objects that automatically return the >correct value depending on the system preference. > >Test Plan: >1) Apply this patch >2) Run t/db_dependent/Items.t >--- > Koha/Schema/Result/Biblio.pm | 6 +++++- > Koha/Schema/Result/Item.pm | 17 +++++++++++++++++ > t/db_dependent/Items.t | 37 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 59 insertions(+), 1 deletions(-) > >diff --git a/Koha/Schema/Result/Biblio.pm b/Koha/Schema/Result/Biblio.pm >index 2a8c28e..5f2e399 100644 >--- a/Koha/Schema/Result/Biblio.pm >+++ b/Koha/Schema/Result/Biblio.pm >@@ -331,6 +331,10 @@ __PACKAGE__->many_to_many("sets", "oai_sets_biblios", "set"); > # Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21 > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:0//8OGf7OteNnwT03g4QsA > >+__PACKAGE__->belongs_to( >+ "biblioitem", >+ "Koha::Schema::Result::Biblioitem", >+ { "foreign.biblionumber" => "self.biblionumber" } >+); > >-# You can replace this text with custom content, and it will be preserved on regeneration > 1; >diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm >index 4e46ac7..656de69 100644 >--- a/Koha/Schema/Result/Item.pm >+++ b/Koha/Schema/Result/Item.pm >@@ -618,4 +618,21 @@ __PACKAGE__->belongs_to( > { "foreign.biblionumber" => "self.biblionumber" } > ); > >+__PACKAGE__->belongs_to( >+ "biblioitem", >+ "Koha::Schema::Result::Biblioitem", >+ { biblioitemnumber => "biblioitemnumber" }, >+); >+ >+use C4::Context; >+sub itemtype { >+ my ( $self ) = @_; >+ >+ if ( C4::Context->preference('item-level_itypes') ) { >+ return $self->itype(); >+ } else { >+ return $self->biblioitem()->itemtype(); >+ } >+} >+ > 1; >diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t >index 5ec8d34..a4bdd1c 100755 >--- a/t/db_dependent/Items.t >+++ b/t/db_dependent/Items.t >@@ -20,6 +20,7 @@ use Modern::Perl; > > use MARC::Record; > use C4::Biblio; >+use Koha::Database; > > use Test::More tests => 3; > >@@ -142,6 +143,42 @@ subtest 'GetHiddenItemnumbers tests' => sub { > $dbh->rollback; > }; > >+subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub { >+ >+ plan tests => 2; >+ >+ # Start transaction >+ $dbh->{AutoCommit} = 0; >+ $dbh->{RaiseError} = 1; >+ >+ my $schema = Koha::Database->new()->schema(); >+ >+ my $biblio = >+ $schema->resultset('Biblio')->create( >+ { >+ title => "Test title", >+ biblioitems => [ >+ { >+ itemtype => 'BIB_LEVEL', >+ items => [ { itype => "ITEM_LEVEL" } ] >+ } >+ ] >+ } >+ ); >+ >+ my $biblioitem = $biblio->biblioitem(); >+ my ( $item ) = $biblioitem->items(); >+ >+ C4::Context->set_preference( 'item-level_itypes', 0 ); >+ ok( $item->itemtype() eq 'BIB_LEVEL', '$item->itemtype() returns biblioitem.itemtype when item-level_itypes is disabled' ); >+ >+ C4::Context->set_preference( 'item-level_itypes', 1 ); >+ ok( $item->itemtype() eq 'ITEM_LEVEL', '$item->itemtype() returns items.itype when item-level_itypes is disabled' ); >+ >+ >+ $dbh->rollback; >+}; >+ > # Helper method to set up a Biblio. > sub get_biblio { > my $bib = MARC::Record->new(); >-- >1.7.2.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 11518
:
24121
|
24143
|
25448
|
25510
|
26983
|
26985
|
26987
|
27343
|
27344
|
27345
|
27346
|
27347
|
27348
|
29544
|
31240
|
31241
|
31242