[Koha-bugs] [Bug 17944] Remove the sql code from itemtypes.pl administrative perl script

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Thu May 4 17:29:10 CEST 2017


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=17944

--- Comment #42 from Jonathan Druart <jonathan.druart at bugs.koha-community.org> ---
Alex,
Some additional remarks (we are aiming the perfect patch, right? :))

1. The POD of the new method is incorrect, please adapt it.
Note that a line should not be longer than 80 chars

2. The method can_be_deleted should be something like:

sub can_be_deleted {
    my ($self) = @_; 
    my $nb_items = Koha::Items->search( { itype => $self->itemtype } )->count;
    my $nb_biblioitems = Koha::Biblioitems->search( { itemtype =>
$self->itemtype } )->count;
    return $nb_items + $nb_biblioitems == 0;
}

$self is the current object, from this object you know the itemtype (code), so
you so not need to pass it as an argument.

3. The tests are wrong:
I have a biblio with biblionumber=1, so they fail (Duplicate entry '1' for key
'PRIMARY'). You need to use our TestBuilder module to generate random data.
What you want is:
a) Generate the $builder object:
  my $builder = t::lib::TestBuilder->new;

b) create an item type:
  my $item_type = $builder->build_object({ class => 'Koha::ItemTypes' });

c) you want to test if an item type, not used, can be removed. It's time!
  is( $item_type->can_be_deleted, 1, 'An item type that is not used can be
deleted' );

d) create an item using this item type:
  my $item = $builder->build_object({ class => 'Koha::Items', value => { itype
=> $item_type->itemtype });

e) Then you want to know if the item type can be removed
  is( $item_type->can_be_deleted, 0, 'An item type that is used by an item
cannot be deleted );

Then you can continue with a biblioitem object.

Please resubmit a patch without the delete method, just can_be_deleted
step-by-step :)

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list