Bugzilla – Attachment 47997 Details for
Bug 11592
opac detail scripts do not respect MARC tag visibility
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11592 - Old Filtery stuff
Bug-11592---Old-Filtery-stuff.patch (text/plain), 10.86 KB, created by
Mark Tompsett
on 2016-02-12 15:55:15 UTC
(
hide
)
Description:
Bug 11592 - Old Filtery stuff
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2016-02-12 15:55:15 UTC
Size:
10.86 KB
patch
obsolete
>From 93d9a19093322e31cd0db66d1c361f8947cf2164 Mon Sep 17 00:00:00 2001 >From: Mark Tompsett <mtompset@hotmail.com> >Date: Mon, 13 Jul 2015 14:34:01 -0400 >Subject: [PATCH] Bug 11592 - Old Filtery stuff > >--- > Koha/Filter/MARC/ViewPolicy.pm | 252 ++++++++++++++++++++++++++++ > t/RecordProcessor.t | 3 + > t/db_dependent/RecordProcessor_ViewPolicy.t | 66 ++++++++ > 3 files changed, 321 insertions(+) > create mode 100644 Koha/Filter/MARC/ViewPolicy.pm > create mode 100755 t/db_dependent/RecordProcessor_ViewPolicy.t > >diff --git a/Koha/Filter/MARC/ViewPolicy.pm b/Koha/Filter/MARC/ViewPolicy.pm >new file mode 100644 >index 0000000..16062e1 >--- /dev/null >+++ b/Koha/Filter/MARC/ViewPolicy.pm >@@ -0,0 +1,252 @@ >+package Koha::Filter::MARC::ViewPolicy; >+ >+# Copyright 2015 Mark Tompsett >+# >+# 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>. >+ >+=head1 NAME >+ >+Koha::Filter::MARC::ViewPolicy - this filters a MARC record. >+ >+=head1 VERSION >+ >+version 1.0 >+ >+=head1 SYNOPSIS >+ >+my $processor = Koha::RecordProcessor->new( { filters => ('ViewPolicy') } ); >+ >+=head1 DESCRIPTION >+ >+Filter to remove fields based on the 'Advance constraints' >+settings found when editing a particular subfield definition of >+a MARC bibliographic framework found under the Koha administration >+menu. >+ >+=cut >+ >+use Modern::Perl; >+use Carp; >+use C4::Biblio; >+ >+use base qw(Koha::RecordProcessor::Base); >+our $NAME = 'MARC_ViewPolicy'; >+our $VERSION = '1.0'; >+ >+=head1 SUBROUTINES/METHODS >+ >+=head2 filter >+ >+ my $processor = Koha::RecordProcessor->new( { filters => ('ViewPolicy') } ); >+... >+ my $newrecord = $processor->filter($record); >+ my $newrecords = $processor->filter(\@records); >+ >+This returns a filtered copy of the record based on the Advanced constraints >+visibility settings. >+ >+=cut >+ >+sub filter { >+ my $self = shift; >+ my $precord = shift; >+ my @records; >+ >+ if ( !$precord ) { >+ return $precord; >+ } >+ >+ if ( ref($precord) eq 'ARRAY' ) { >+ @records = @{$precord}; >+ } >+ else { >+ push @records, $precord; >+ } >+ >+ my @results; >+ foreach my $current_record (@records) { >+ my $result = $current_record->clone(); >+ my $interface = $self->{options}->{interface} // 'opac'; >+ my $frameworkcode = $self->{options}->{frameworkcode} // q{}; >+ my $display = _should_display_on_interface(); >+ >+ my $marcsubfieldstructure = GetMarcStructure( 0, $frameworkcode ); >+ >+ #if ($marcsubfieldstructure->{'000'}->{'@'}->{hidden}>0) { >+ # LDR field is excluded from $current_record->fields(). >+ # if we hide it here, the MARCXML->MARC::Record->MARCXML >+ # transformation blows up. >+ #} >+ foreach my $field ( $result->fields() ) { >+ _filter_field( >+ { >+ field => $field, >+ marcsubfieldstructure => $marcsubfieldstructure, >+ display => $display, >+ interface => $interface, >+ result => $result >+ } >+ ); >+ } >+ push @results, $result; >+ } >+ >+ if ( scalar @results == 1 ) { >+ return $results[0]; >+ } >+ else { >+ return \@results; >+ } >+} >+ >+sub _filter_field { >+ my ($parameter) = @_; >+ >+ my $field = $parameter->{field}; >+ my $marcsubfieldstructure = $parameter->{marcsubfieldstructure}; >+ my $display = $parameter->{display}; >+ my $interface = $parameter->{interface}; >+ my $result = $parameter->{result}; >+ >+ my $tag = $field->tag(); >+ if ( $tag >= 10 ) { >+ foreach my $subpairs ( $field->subfields() ) { >+ my ( $subtag, $value ) = @{$subpairs}; >+ >+ # visibility is a "level" (-7 to +7), default to 0 >+ my $visibility = >+ $marcsubfieldstructure->{$tag}->{$subtag}->{hidden}; >+ $visibility //= 0; >+ my $hidden; >+ if ( $display->{$interface}->{$visibility} ) { >+ $hidden = 0; >+ } >+ else { >+ # deleting last subfield doesn't delete field, so >+ # this detects that case to delete the field. >+ if ( scalar $field->subfields() <= 1 ) { >+ $result->delete_fields($field); >+ } >+ else { >+ $field->delete_subfield( code => $subtag ); >+ } >+ } >+ } >+ } >+ >+ # tags less than 10 don't have subfields, use @ trick. >+ else { >+ # visibility is a "level" (-7 to +7), default to 0 >+ my $visibility = $marcsubfieldstructure->{$tag}->{q{@}}->{hidden}; >+ $visibility //= 0; >+ my $hidden; >+ if ( $display->{$interface}->{$visibility} ) { >+ $hidden = 0; >+ } >+ else { >+ $hidden = 1; >+ $result->delete_fields($field); >+ } >+ } >+ return; >+} >+ >+sub initialize { >+ my $self = shift; >+ my $param = shift; >+ >+ my $options = $param->{options}; >+ $self->{options} = $options; >+ $self->Koha::RecordProcessor::Base::initialize($param); >+ return; >+} >+ >+sub _should_display_on_interface { >+ my $display = { >+ opac => { >+ 0 => 1, >+ -1 => 1, >+ -2 => 1, >+ -3 => 1, >+ -4 => 1, >+ -5 => 1, >+ -6 => 1, >+ -7 => 1, >+ }, >+ intranet => { >+ -6 => 1, >+ -5 => 1, >+ -1 => 1, >+ 0 => 1, >+ 1 => 1, >+ 4 => 1, >+ 6 => 1, >+ 7 => 1, >+ }, >+ }; >+ return $display; >+} >+ >+=head1 DIAGNOSTICS >+ >+ $ prove -v t/RecordProcessor.t >+ $ prove -v t/db_dependent/RecordProcessor_ViewPolicy.t >+ >+=head1 CONFIGURATION AND ENVIRONMENT >+ >+Install Koha. This filter will be used appropriately by the OPAC or Staff client. >+ >+=head1 INCOMPATIBILITIES >+ >+This is designed for MARC::Record filtering currently. It will not handle MARC::MARCXML. >+ >+=head1 DEPENDENCIES >+ >+The following Perl libraries are required: Modern::Perl and Carp. >+The following Koha libraries are required: C4::Biblio, Koha::RecordProcessor, and Koha::RecordProcessor::Base. >+These should all be installed if the koha-common package is installed or Koha is otherwise installed. >+ >+=head1 BUGS AND LIMITATIONS >+ >+This is the initial version. Please feel free to report bugs >+at http://bugs.koha-community.org/. >+ >+=head1 AUTHOR >+ >+Mark Tompsett >+ >+=head1 LICENSE AND COPYRIGHT >+ >+Copyright 2015 Mark Tompsett >+ >+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>. >+ >+=cut >+ >+1; >diff --git a/t/RecordProcessor.t b/t/RecordProcessor.t >index ad475d4..e0b077d 100755 >--- a/t/RecordProcessor.t >+++ b/t/RecordProcessor.t >@@ -59,6 +59,9 @@ is($processor->process($marc_record), $marc_record, 'Process record with empty p > $processor = Koha::RecordProcessor->new( { filters => ( 'Null' ) } ); > is(ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Created record processor with implicitly scoped Null filter'); > >+$processor = Koha::RecordProcessor->new( { filters => ( 'ViewPolicy' ), options => { 'test' => 'value1' } } ); >+is($processor->filters->[0]->{options}->{test},'value1','Options set on processor creation'); >+ > $processor = Koha::RecordProcessor->new( { filters => ( 'Koha::Filter::MARC::Null' ) } ); > is(ref($processor->filters->[0]), 'Koha::Filter::MARC::Null', 'Created record processor with explicitly scoped Null filter'); > >diff --git a/t/db_dependent/RecordProcessor_ViewPolicy.t b/t/db_dependent/RecordProcessor_ViewPolicy.t >new file mode 100755 >index 0000000..f4ffe23 >--- /dev/null >+++ b/t/db_dependent/RecordProcessor_ViewPolicy.t >@@ -0,0 +1,66 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Copyright 2015 Mark Tompsett >+# >+# 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 MARC::Record; >+use MARC::Field; >+use Test::More; >+use C4::Context; >+use Koha::Database; >+use Data::Dumper; >+ >+BEGIN { >+ use_ok('Koha::RecordProcessor'); >+} >+ >+my $dbh = C4::Context->dbh; >+ >+my $database = Koha::Database->new(); >+my $schema = $database->schema(); >+$schema->storage->txn_begin(); >+ >+$dbh->{RaiseError} = 1; >+ >+$dbh->do(q{UPDATE marc_subfield_structure SET hidden=2 WHERE tagfield='020';}); >+ >+my $isbn = '0590353403'; >+my $title = 'Foundation'; >+my $marc_record = MARC::Record->new; >+my $field = MARC::Field->new( '020', q{}, q{}, 'a' => $isbn ); >+$marc_record->append_fields($field); >+$field = MARC::Field->new( '245', q{}, q{}, 'a' => $title ); >+$marc_record->append_fields($field); >+ >+my $processor = Koha::RecordProcessor->new( >+ { filters => ('ViewPolicy'), options => { 'test' => 'value1' } } ); >+is( >+ ref( $processor->filters->[0] ), >+ 'Koha::Filter::MARC::ViewPolicy', >+ 'Created record processor with implicitly scoped ViewPolicy filter' >+); >+my $after_record = $processor->process($marc_record); >+my $modified_record = $marc_record->clone; >+my @isbn = $modified_record->field('020'); >+$modified_record->delete_fields(@isbn); >+is_deeply( $modified_record, $after_record, >+ 'Filtered and modified MARC record match' ); >+ >+$schema->storage->txn_rollback(); >+ >+done_testing(); >-- >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 11592
:
24600
|
24601
|
24611
|
24629
|
24654
|
24655
|
24657
|
24658
|
24659
|
24660
|
24661
|
24662
|
24663
|
24664
|
24875
|
24876
|
24952
|
24953
|
28002
|
28003
|
28477
|
28478
|
28479
|
28480
|
28724
|
31356
|
32382
|
32383
|
33356
|
33357
|
33358
|
33689
|
35855
|
35856
|
35857
|
35858
|
47993
|
47996
|
47997
|
48001
|
49288
|
49289
|
49290
|
49291
|
49612
|
49613
|
49614
|
49615
|
50484
|
50485
|
50486
|
50489
|
50542
|
50550
|
50551
|
50552
|
50553
|
50554
|
51313
|
51314
|
51315
|
51316
|
51317
|
51318
|
51326
|
53440
|
53441
|
53442
|
53443
|
53444
|
55040
|
55041
|
55042
|
55043
|
55044
|
55045
|
55046
|
55184
|
55185