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