various bugfixes on parameters modules + adding default NoZebraIndexes systempreferen...
[koha_gimpoz] / misc / migration_tools / 22_to_30 / export_Authorities.pl
1 #!/usr/bin/perl
2 use C4::Context;
3 #use MARC::File::XML(BinaryEncoding=>"utf8");
4 #use MARC::File::USMARC;
5 use MARC::Record;
6 use C4::AuthoritiesMarc;
7 use POSIX;
8 #MARC::File::XML::default_record_format("UNIMARCAUTH");
9 my $dbh = C4::Context->dbh;
10 my $rq= $dbh->prepare(qq|
11   SELECT authid,authtypecode
12   FROM auth_header
13   |);
14 my $filename= shift @ARGV;
15 $rq->execute;
16 #ATTENTION : Mettre la base en utf8 auparavant.
17 #BEWARE : Set database into utf8 before.
18 #open FILEOUTPUT,">:utf8", "$filename" or die "unable to open $filename";
19 while (my ($authid,$authtypecode)=$rq->fetchrow){
20   my $record=AUTHgetauthority($dbh,$authid);
21   if (! utf8::is_utf8($record)) {
22           utf8::decode($record);
23   }
24   
25   if (C4::Context->preference('marcflavour') eq "UNIMARC"){
26         $record->leader('     nac  22     1u 4500');
27     my $string=$1 if $time=~m/([0-9\-]+)/;
28     $string=~s/\-//g;
29      $string = sprintf("%-*s",26, $string);
30      substr($string,9,6,"frey50");
31      unless ($record->subfield('100',"a")){
32        $record->insert_fields_ordered(MARC::Field->new('100',"","","a"=>$string));
33      }
34      if ($record->field('152')){
35        if ($record->subfield('152','b')){
36         } else {
37              $record->field('152')->add_subfields("b"=>$authtypecode);
38         }
39      } else {
40              $record->insert_fields_ordered(MARC::Field->new('152',"","","b"=>$authtypecode));
41      }
42      unless ($record->field('001')){
43        $record->insert_fields_ordered(MARC::Field->new('001',$authid));
44      }
45      
46      AUTHmodauthority($dbh,$authid,$record,1);
47    } else {
48     $record->encoding( 'UTF-8' );
49   }
50 #  warn $record->as_usmarc;
51      # warn $record->as_formatted;
52      #   warn $record->as_usmarc;
53
54   print $record->as_usmarc();
55
56 }
57 close ;