3 # Copyright 2017 Rijksmuseum
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 # This script walks through your authority marc records and tells you
22 # which hidden fields in the framework still contain data.
29 use Koha
::Authorities
;
30 use Koha
::Authority
::Subfields
;
31 use Koha
::MetadataRecord
::Authority
;
33 my ( $max, $help, $confirm );
34 GetOptions
( 'confirm' => \
$confirm, 'help' => \
$help, 'max' => \
$max );
35 if ( !$confirm || $help ) {
36 pod2usage
( -verbose
=> 2 );
40 our $hidden_fields = Koha
::Authority
::Subfields
->search(
41 { hidden
=> { '!=' => 0 }},
45 my $auths = Koha
::Authorities
->search( {}, { order_by
=> 'authid' } );
47 while( my $record = $auths->next ) {
48 last if $max && $count >= $max;
49 scan_record
( $record );
56 my $id = $record->authid;
57 my $type = $record->authtypecode;
58 my $marc = Koha
::MetadataRecord
::Authority
->get_from_authid($id)->record;
59 foreach my $fld ( $marc->fields ) { # does not include leader
60 my @subfields = $fld->is_control_field
62 : map { $_->[0] } $fld->subfields;
63 foreach my $sub ( @subfields ) {
64 next if $results->{ $type } && $results->{ $type }->{ $fld->tag } && $results->{ $type }->{ $fld->tag }->{ $sub };
65 if( $hidden_fields->find($type, $fld->tag, $sub) ) {
66 $results->{ $type }->{ $fld->tag }->{ $sub } = 1;
70 # To be overcomplete, check the leader too :)
72 if( $hidden_fields->find($type, '000', '@') ) {
73 $results->{ $type }->{ '000' }->{ '@' } = 1;
80 foreach my $fw ( sort keys %$results ) {
81 foreach my $tag ( sort keys %{$results->{$fw}} ) {
82 foreach my $sub ( sort keys %{$results->{$fw}->{$tag}} ) {
83 print "\nFramework ".($fw||'Default').", $tag, $sub contains data but is hidden";
89 print "\n\nNOTE: You should consider removing the hidden attribute of these framework fields in order to not lose data in those fields when editing authority records.\n";
91 print "\nNo hidden (sub)fields containing data were found!\n";
97 auth_show_hidden_data.pl
101 auth_show_hidden_data.pl -c -max 1000
105 This script tells you if you have authority data in hidden (sub)fields. That
106 data will be lost when editing such authority records.
112 Confirm flag. Required to start checking authority records.
120 This optional parameter tells the script to stop after the specified number of