Bug 21797: Update two-column templates with Bootstrap grid: Acquisitions part 5
[koha.git] / misc / maintenance / auth_show_hidden_data.pl
blob7f179450d33b5a6b8d83fbe95c186d50e332c10d
1 #!/usr/bin/perl
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.
24 use Modern::Perl;
25 use Getopt::Long;
26 use Pod::Usage;
28 use Koha::Authorities;
29 use Koha::Authority::Subfields;
30 use Koha::MetadataRecord::Authority;
32 my ( $max, $help, $confirm );
33 GetOptions( 'confirm' => \$confirm, 'help' => \$help, 'max' => \$max );
34 if ( !$confirm || $help ) {
35 pod2usage( -verbose => 2 );
36 exit;
39 our $hidden_fields = Koha::Authority::Subfields->search(
40 { hidden => { '!=' => 0 }},
42 our $results = {};
44 my $auths = Koha::Authorities->search( {}, { order_by => 'authid' } );
45 my $count = 0;
46 while( my $record = $auths->next ) {
47 last if $max && $count >= $max;
48 scan_record( $record );
49 $count++;
51 report_results();
53 sub scan_record {
54 my ( $record ) = @_;
55 my $id = $record->authid;
56 my $type = $record->authtypecode;
57 my $marc = Koha::MetadataRecord::Authority->get_from_authid($id)->record;
58 foreach my $fld ( $marc->fields ) { # does not include leader
59 my @subfields = $fld->is_control_field
60 ? '@'
61 : map { $_->[0] } $fld->subfields;
62 foreach my $sub ( @subfields ) {
63 next if $results->{ $type } && $results->{ $type }->{ $fld->tag } && $results->{ $type }->{ $fld->tag }->{ $sub };
64 if( $hidden_fields->find($type, $fld->tag, $sub) ) {
65 $results->{ $type }->{ $fld->tag }->{ $sub } = 1;
69 # To be overcomplete, check the leader too :)
70 if( $marc->leader ) {
71 if( $hidden_fields->find($type, '000', '@') ) {
72 $results->{ $type }->{ '000' }->{ '@' } = 1;
77 sub report_results {
78 my $cnt = 0;
79 foreach my $fw ( sort keys %$results ) {
80 foreach my $tag ( sort keys %{$results->{$fw}} ) {
81 foreach my $sub ( sort keys %{$results->{$fw}->{$tag}} ) {
82 print "\nFramework ".($fw||'Default').", $tag, $sub contains data but is hidden";
83 $cnt++;
87 if( $cnt ) {
88 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";
89 } else {
90 print "\nNo hidden (sub)fields containing data were found!\n";
94 =head1 NAME
96 auth_show_hidden_data.pl
98 =head1 SYNOPSIS
100 auth_show_hidden_data.pl -c -max 1000
102 =head1 DESCRIPTION
104 This script tells you if you have authority data in hidden (sub)fields. That
105 data will be lost when editing such authority records.
107 =over 8
109 =item B<-confirm>
111 Confirm flag. Required to start checking authority records.
113 =item B<-help>
115 Usage statement
117 =item B<-max>
119 This optional parameter tells the script to stop after the specified number of
120 records.
122 =back
124 =cut