Bug 26194: Add link to cash register management from message about missing registers
[koha.git] / misc / maintenance / auth_show_hidden_data.pl
blob91006d17617313688477d5fc7481b93b3535d22d
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::Script;
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 );
37 exit;
40 our $hidden_fields = Koha::Authority::Subfields->search(
41 { hidden => { '!=' => 0 }},
43 our $results = {};
45 my $auths = Koha::Authorities->search( {}, { order_by => 'authid' } );
46 my $count = 0;
47 while( my $record = $auths->next ) {
48 last if $max && $count >= $max;
49 scan_record( $record );
50 $count++;
52 report_results();
54 sub scan_record {
55 my ( $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
61 ? '@'
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 :)
71 if( $marc->leader ) {
72 if( $hidden_fields->find($type, '000', '@') ) {
73 $results->{ $type }->{ '000' }->{ '@' } = 1;
78 sub report_results {
79 my $cnt = 0;
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";
84 $cnt++;
88 if( $cnt ) {
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";
90 } else {
91 print "\nNo hidden (sub)fields containing data were found!\n";
95 =head1 NAME
97 auth_show_hidden_data.pl
99 =head1 SYNOPSIS
101 auth_show_hidden_data.pl -c -max 1000
103 =head1 DESCRIPTION
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.
108 =over 8
110 =item B<-confirm>
112 Confirm flag. Required to start checking authority records.
114 =item B<-help>
116 Usage statement
118 =item B<-max>
120 This optional parameter tells the script to stop after the specified number of
121 records.
123 =back
125 =cut