C4 and misc: permissions fixes
[koha.git] / misc / migration_tools / 22_to_30 / export_Authorities_xml.pl
1 #!/usr/bin/perl
2 use C4::Context;
3 use MARC::File::XML(BinaryEncoding=>"utf8");
4 use MARC::Record;
5 use C4::AuthoritiesMarc;
6 use POSIX;
7 MARC::File::XML::default_record_format("UNIMARCAUTH");
8 my $dbh = C4::Context->dbh;
9 my $rq= $dbh->prepare(qq|
10   SELECT authid
11   FROM auth_header
12   |);
13 my $filename= shift @ARGV;
14 $rq->execute;
15 #ATTENTION : Mettre la base en utf8 auparavant.
16 #BEWARE : Set database into utf8 before.
17 while (my ($authid)=$rq->fetchrow){
18 open FILEOUTPUT,">:utf8", "./$filename/$authid.xml" or die "unable to open $filename";
19   my $record=AUTHgetauthority($dbh,$authid);
20   if (! utf8::is_utf8($record)) {
21     utf8::decode($record);
22   }
23                         
24 #  if (C4::Context->preference('marcflavour') eq "UNIMARC"){
25         $record->leader('     nac  22     1u 4500');
26     my $string=$1 if $time=~m/([0-9\-]+)/;
27     $string=~s/\-//g;
28      $string = sprintf("%-*s",26, $string);
29      substr($string,9,6,"frey50");
30      unless ($record->subfield(100,"a")){
31        $record->insert_fields_ordered(MARC::Field->new(100,"","","a"=>$string));
32      }
33      unless ($record->subfield('001')){
34        $record->insert_fields_ordered(MARC::Field->new('001',$authid));
35      }
36      # } else {
37 #    $record->encoding( 'UTF-8' );
38 #  }
39   print FILEOUTPUT $record->as_xml();
40 close FILEOUPUT;
41
42 }