Koha/t/db_dependent/Holds/HoldFulfillmentPolicy.t
Jonathan Druart c6e488f4af Bug 17196: Move marcxml out of the biblioitems table
Two discussions on koha-devel lead to the same conclusion:
biblioitems.marcxml should be moved out this table
- biblio and biblioitems
http://lists.koha-community.org/pipermail/koha-devel/2013-April/039239.html
- biblioitems.marcxml & biblioitems.marc / HUGE performance issue !
http://lists.koha-community.org/pipermail/koha-devel/2016-July/042821.html

There are several goals to do it:
- Performance
As Paul Poulain wrote, a simple query like
  SELECT publicationyear, count(publicationyear) FROM biblioitems GROUP BY publicationyear;
takes more than 10min on a DB with more than 1M bibliographic records
but only 3sec (!) on the same DB without the biblioitems.marcxml field
Note that priori to this patch set, the biblioitems.marcxml was not
retrieved systematically, but was, at least, in
C4::Acquisition::GetOrdersByBiblionumber and C4::Acquisition::GetOrders
- Flexibility
Storing the marcxml in a specific table would allow use to store several
kind of metadata (USMARC, MARCXML, MIJ, etc.) and different formats (marcflavour)
- Clean code
It would be a first step toward Koha::MetadataRecord for bibliographic
records (not done in this patch set).

Test plan:
- Update the DBIC Schema
- Add / Edit / Delete / Import / Export bibliographic records
- Add items
- Reindex records using ES
- Confirm that the following scripts still work:
    * misc/cronjobs/delete_records_via_leader.pl
    * misc/migration_tools/build_oai_sets.pl
- Look at the reading history at the OPAC (opac-readingrecord.pl)
- At the OPAC, click on a tag, you must see the result

Note: Changes in Koha/OAI/Server/ListRecords.pm is planned on bug 15108.

Signed-off-by: Mason James <mtj@kohaaloha.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Zeno Tajoli <z.tajoli@cineca.it>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
2017-01-13 13:49:26 +00:00

139 lines
5.5 KiB
Perl
Executable file

#!/usr/bin/perl
use Modern::Perl;
use C4::Context;
use Test::More tests => 10;
use t::lib::TestBuilder;
BEGIN {
use_ok('C4::Reserves');
}
my $schema = Koha::Database->schema;
$schema->storage->txn_begin;
my $dbh = C4::Context->dbh;
my $builder = t::lib::TestBuilder->new;
my $library1 = $builder->build({
source => 'Branch',
});
my $library2 = $builder->build({
source => 'Branch',
});
my $library3 = $builder->build({
source => 'Branch',
});
my $bib_title = "Test Title";
my $borrower = $builder->build({
source => 'Borrower',
value => {
categorycode => 'S',
branchcode => $library1->{branchcode},
}
});
# Test hold_fulfillment_policy
my ( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") };
my $borrowernumber = $borrower->{borrowernumber};
my $library_A = $library1->{branchcode};
my $library_B = $library2->{branchcode};
my $library_C = $library3->{branchcode};
$dbh->do("DELETE FROM transport_cost");
$dbh->do("DELETE FROM tmp_holdsqueue");
$dbh->do("DELETE FROM hold_fill_targets");
$dbh->do("DELETE FROM default_branch_circ_rules");
$dbh->do("DELETE FROM default_branch_item_rules");
$dbh->do("DELETE FROM default_circ_rules");
$dbh->do("DELETE FROM branch_item_rules");
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$bib_title', '2011-02-01')");
my $biblionumber = $dbh->selectrow_array("SELECT biblionumber FROM biblio WHERE title = '$bib_title'")
or BAIL_OUT("Cannot find newly created biblio record");
$dbh->do("INSERT INTO biblioitems (biblionumber, itemtype) VALUES ($biblionumber, '$itemtype')");
my $biblioitemnumber =
$dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber")
or BAIL_OUT("Cannot find newly created biblioitems record");
$dbh->do("
INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_B', 0, 0, 0, 0, NULL, '$itemtype')
");
my $itemnumber =
$dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber")
or BAIL_OUT("Cannot find newly created item");
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch
$dbh->do("DELETE FROM default_circ_rules");
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'homebranch' )");
# Home branch matches pickup branch
my $reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
my ( $status ) = CheckReserves($itemnumber);
is( $status, 'Reserved', "Hold where pickup branch matches home branch targeted" );
CancelReserve( { reserve_id => $reserve_id } );
# Holding branch matches pickup branch
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
( $status ) = CheckReserves($itemnumber);
is($status, q{}, "Hold where pickup ne home, pickup eq home not targeted" );
CancelReserve( { reserve_id => $reserve_id } );
# Neither branch matches pickup branch
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
( $status ) = CheckReserves($itemnumber);
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
CancelReserve( { reserve_id => $reserve_id } );
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch
$dbh->do("DELETE FROM default_circ_rules");
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'holdingbranch' )");
# Home branch matches pickup branch
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
( $status ) = CheckReserves($itemnumber);
is( $status, q{}, "Hold where pickup eq home, pickup ne holding not targeted" );
CancelReserve( { reserve_id => $reserve_id } );
# Holding branch matches pickup branch
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
( $status ) = CheckReserves($itemnumber);
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
CancelReserve( { reserve_id => $reserve_id } );
# Neither branch matches pickup branch
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
( $status ) = CheckReserves($itemnumber);
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
CancelReserve( { reserve_id => $reserve_id } );
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch
$dbh->do("DELETE FROM default_circ_rules");
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'any' )");
# Home branch matches pickup branch
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
( $status ) = CheckReserves($itemnumber);
is( $status, 'Reserved', "Hold where pickup eq home, pickup ne holding targeted" );
CancelReserve( { reserve_id => $reserve_id } );
# Holding branch matches pickup branch
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
( $status ) = CheckReserves($itemnumber);
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
CancelReserve( { reserve_id => $reserve_id } );
# Neither branch matches pickup branch
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
( $status ) = CheckReserves($itemnumber);
is( $status, 'Reserved', "Hold where pickup ne home, pickup ne holding targeted" );
CancelReserve( { reserve_id => $reserve_id } );