From 26897109c99f8c93155f53d3d0a243015283eef6 Mon Sep 17 00:00:00 2001 From: Kyle M Hall 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 Signed-off-by: Katrin Fischer Signed-off-by: Mason James --- Koha/Schema/Result/Item.pm | 6 +++--- t/db_dependent/Items.t | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index fd50d1569f..656de69512 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -624,11 +624,11 @@ __PACKAGE__->belongs_to( { biblioitemnumber => "biblioitemnumber" }, ); -sub effective_itemtype { +use C4::Context; +sub itemtype { my ( $self ) = @_; - my $pref = $self->result_source->schema->resultset('Systempreference')->find('item-level_itypes'); - if ( $pref->value() ) { + if ( C4::Context->preference('item-level_itypes') ) { return $self->itype(); } else { return $self->biblioitem()->itemtype(); diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 6867f83a00..6b56fa9b1e 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -169,11 +169,11 @@ subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub { my $biblioitem = $biblio->biblioitem(); my ( $item ) = $biblioitem->items(); - $schema->resultset('Systempreference')->update_or_create({ variable => 'item-level_itypes', value => 0 }); - ok( $item->effective_itemtype() eq 'BIB_LEVEL', '$item->itemtype() returns biblioitem.itemtype when item-level_itypes is disabled' ); + 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' ); - $schema->resultset('Systempreference')->update_or_create({ variable => 'item-level_itypes', value => 1 }); - ok( $item->effective_itemtype() eq 'ITEM_LEVEL', '$item->itemtype() returns items.itype 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; -- 2.39.5