export MARC records from Koha database
[koha-eprints] / koha-marc-export.pl
diff --git a/koha-marc-export.pl b/koha-marc-export.pl
new file mode 100755 (executable)
index 0000000..b635ccb
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/perl -w
+
+use strict;
+use DBI;
+use Data::Dump qw/dump/;
+use autodie;
+#use Text::Unaccent;
+use XML::Simple;
+
+my $koha_conf = XMLin('/etc/koha/sites/ffzg/koha-conf.xml');
+my $file = 'koha-darhiv';
+my $sql = qq{
+select * from biblioitems where url is not null and url like 'http://darhiv.ffzg.hr%' limit 10 -- koha-darhiv
+};
+
+$file = $1 if $sql =~ m/--\s*(\S+)/;
+
+#my $c = DBI->connect("dbi:CSV:","","", { RaiseError => 1, f_ext => '.csv', f_encoding => 'utf-8', csv_sep_char => ';' }) || die $dbi::errstr;
+my $k = DBI->connect("dbi:mysql:database=" . $koha_conf->{config}->{database}, $koha_conf->{config}->{user}, $koha_conf->{config}->{pass},
+ { RaiseError => 1, AutoCommit => 0, mysql_enable_utf8 => 1 }) || die $DBI::errstr;
+
+my $s = $k->prepare($sql);
+$s->execute;
+
+my $stat;
+
+open(my $marc_fh, '>', "export/$file.marc");
+
+while( my $row = $s->fetchrow_hashref ) {
+
+       warn "# row = ",dump($row),$/;
+
+       print $marc_fh $row->{marc};
+
+}
+
+#$k->commit;
+
+close($marc_fh);
+
+warn "# stat ", dump( $stat ),$/;