Bug 14651: Koha::Item->effective_itemtype fallback to bib-level
authorTomas Cohen Arazi <tomascohen@unc.edu.ar>
Tue, 18 Aug 2015 19:37:27 +0000 (16:37 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 7 Sep 2015 14:14:19 +0000 (11:14 -0300)
In some situations (bad migrations, old bugs that introduced bad data,
people having bib-level itypes for ages and switching to item level...)
the user ends with undex itype values for items.

The current code, if the user has item_level-itype set, just returns
undef. It should fallback to bib-level. In order to avoid hiding the problem
a warning is raised.

To test:
- Run the regression tets:
  $ prove t/db_dependent/Items.t
=> FAIL: tests fail.
- Apply the patch
- Run the tests again
=> SUCCESS: The tests now pass.
- Sign off :-D

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/Schema/Result/Item.pm

index 0650c4f..c342f46 100644 (file)
@@ -623,9 +623,11 @@ sub effective_itemtype {
     my ( $self ) = @_;
 
     my $pref = $self->result_source->schema->resultset('Systempreference')->find('item-level_itypes');
-    if ( $pref->value() ) {
+    if ( $pref->value() && $self->itype() ) {
         return $self->itype();
     } else {
+        warn "item-level_itypes set but no itemtype set for item ($self->itemnumber)"
+          if $pref->value();
         return $self->biblioitemnumber()->itemtype();
     }
 }