Bugzilla – Attachment 59252 Details for
Bug 15545
Remove remainders of unfinished reqholdnotes functionality
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15545: Add routine IsHoldNoteRequired to Reserves module
Bug-15545-Add-routine-IsHoldNoteRequired-to-Reserv.patch (text/plain), 5.99 KB, created by
Marcel de Rooy
on 2017-01-19 14:19:37 UTC
(
hide
)
Description:
Bug 15545: Add routine IsHoldNoteRequired to Reserves module
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2017-01-19 14:19:37 UTC
Size:
5.99 KB
patch
obsolete
>From 28fc9cf8393ee925be5b85e5fa1feb27b14f55f1 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 26 May 2016 11:38:46 +0200 >Subject: [PATCH] Bug 15545: Add routine IsHoldNoteRequired to Reserves module >Content-Type: text/plain; charset=utf-8 > >This routine will be used to determine if a hold note is required. >In the current approach this is implemented by use of Koha plugins. >A former approach included a syspref. This is no longer needed. This >approach is even more flexible. > >The routine will use all plugins it finds with metadata tag >'implements' set to 'IsHoldNoteRequired'. If one of these plugins has a >check method that returns true, the hold note should be regarded as >required. > >The plugins Rijks_HoldNoteRequired_Extent and _Leader offer an >implementation where the value of the leader or MARC21 300$a determines >if the hold note is required. Similarly, any other field of the >bibliographic record could be used in a new plugin. > >Test plan: >Run unit test t/db_dependent/Reserves/IsHoldNoteRequired.t. > >Signed-off-by: Liz Rea <liz@catalyst.net.nz> >--- > C4/Reserves.pm | 48 +++++++++++++++ > t/db_dependent/Reserves/IsHoldNoteRequired.t | 89 ++++++++++++++++++++++++++++ > 2 files changed, 137 insertions(+) > create mode 100755 t/db_dependent/Reserves/IsHoldNoteRequired.t > >diff --git a/C4/Reserves.pm b/C4/Reserves.pm >index 3f124a6..ed202de 100644 >--- a/C4/Reserves.pm >+++ b/C4/Reserves.pm >@@ -47,6 +47,8 @@ use Koha::IssuingRules; > use Koha::Items; > use Koha::ItemTypes; > use Koha::Patrons; >+use Koha::Plugins; >+use Koha::Plugins::Handler; > > use List::MoreUtils qw( firstidx any ); > use Carp; >@@ -2532,6 +2534,52 @@ sub GetHoldRule { > return $sth->fetchrow_hashref(); > } > >+=head2 IsHoldNoteRequired >+ >+ my $boolean = IsHoldNoteRequired( $biblionumber, $marcrecord ); >+ >+ Returns true if a hold note is required for a given record. >+ Otherwise returns undef. >+ >+ Implemented by use of Koha plugins. >+ The routine will use all plugins it finds with metadata tag >+ 'implements' set to 'IsHoldNoteRequired' and calls the check method. >+ >+ The plugins Rijks_HoldNoteRequired_Leader and _Extent offer an >+ implementation that can serve as an example (see bug 15545). >+ >+=cut >+ >+sub IsHoldNoteRequired { >+ my ( $biblionumber, $marcrecord ) = @_; >+ >+ # plugins enabled? >+ return if !C4::Context->preference('UseKohaPlugins') || >+ !C4::Context->config("enable_plugins"); >+ >+ # look for suitable plugin(s) >+ my $metadata = { implements => 'IsHoldNoteRequired' }; >+ my @plugins = Koha::Plugins->new->GetPlugins({ >+ metadata => $metadata, >+ }); >+ >+ # ask the plugin >+ foreach my $plugin ( @plugins ) { >+ my $retval = Koha::Plugins::Handler->run({ >+ class => ref $plugin, >+ method => 'check', >+ params => { >+ biblionumber => $biblionumber, >+ record => $marcrecord, >+ }, >+ }); >+ return 1 if $retval; >+ } >+ >+ # coming here implies not-required >+ return; >+} >+ > =head1 AUTHOR > > Koha Development Team <http://koha-community.org/> >diff --git a/t/db_dependent/Reserves/IsHoldNoteRequired.t b/t/db_dependent/Reserves/IsHoldNoteRequired.t >new file mode 100755 >index 0000000..8dc1011 >--- /dev/null >+++ b/t/db_dependent/Reserves/IsHoldNoteRequired.t >@@ -0,0 +1,89 @@ >+#!/usr/bin/perl >+ >+# This script tests C4::Reserves::IsHoldNoteRequired. >+ >+# Copyright 2016 Rijksmuseum >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use File::Temp qw/tempdir/; >+use MARC::Record; >+use Test::More tests => 3; >+ >+use t::lib::Mocks; >+use C4::Context; >+use C4::Reserves; >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+# Add a temporary plugin >+C4::Context->set_preference( 'OPACHoldNotes', '1' ); >+t::lib::Mocks::mock_config( 'enable_plugins', 1); >+my $tempdir = tempdir( CLEANUP => 1 ); >+my $org_pluginsdir = C4::Context->config('pluginsdir') // ''; >+t::lib::Mocks::mock_config( 'pluginsdir', $tempdir ); >+add_myplugin( $tempdir ); >+# Adjust searchable module dirs >+@INC = grep { $_ ne $org_pluginsdir } ( @INC, $tempdir ); >+ >+# First test with disabled plugins >+C4::Context->set_preference( 'UseKohaPlugins', '0' ); >+isnt( C4::Reserves::IsHoldNoteRequired(), 1, 'Should be false if plugins are disabled' ); >+ >+# Enable plugin now >+# Note: the plugin actually ignores $marc and returns true for a non-zero bibno >+my $marc = MARC::Record->new; >+C4::Context->set_preference( 'UseKohaPlugins', '1' ); >+is( C4::Reserves::IsHoldNoteRequired( 2, $marc ), 1, 'Should be true for biblionumber 2' ); >+isnt( C4::Reserves::IsHoldNoteRequired( 0, $marc ), 1, 'Should be false for biblionumber 0' ); >+ >+# End >+$schema->storage->txn_rollback; >+ >+sub add_myplugin { >+ my ( $dir ) = @_; >+ system( "mkdir -p $dir/Koha/Plugin" ); >+ open my $fh, '>', $dir.'/Koha/Plugin/Rijks_MyPlugin.pm'; >+ print $fh >+q|package Koha::Plugin::Rijks_MyPlugin; >+use Modern::Perl; >+use base qw(Koha::Plugins::Base); >+ >+our $metadata = { >+ name => 'Rijks_MyPlugin', >+ implements => 'IsHoldNoteRequired', # needed for C4::Reserves >+}; >+ >+sub new { >+ my ( $class, $args ) = @_; >+ $args->{'metadata'} = $metadata; >+ my $self = $class->SUPER::new($args); >+ return $self; >+} >+ >+sub check { >+ my ( $self, $args ) = @_; >+ return $args->{biblionumber}; # unusual return value for testing >+} >+ >+1;|; >+ close $fh; >+} >+ >+1; >-- >2.1.4
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 15545
:
46687
|
46688
|
46689
|
49084
|
49085
|
49086
|
51832
|
51833
|
51834
|
53546
|
53547
|
59252
|
59253
|
139947
|
140960