convert koha marcxml to riak bin koha.marcxml
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 13 Nov 2010 17:47:05 +0000 (18:47 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 13 Nov 2010 17:47:05 +0000 (18:47 +0100)
koha/koha2riak-search.pl [new file with mode: 0755]

diff --git a/koha/koha2riak-search.pl b/koha/koha2riak-search.pl
new file mode 100755 (executable)
index 0000000..8035135
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/perl -w
+
+use strict;
+use DBI;
+use Net::Riak;
+use Data::Dump qw/dump/;
+
+my $limit = "limit 3";
+my $riak_url = 'http://10.60.0.92:8098';
+my $dbi = 'DBI:mysql:dbname=koha;host=10.60.0.10;port=3306';
+my @tables = qw(
+biblioitems
+biblio
+);
+
+my $dbh = DBI->connect($dbi,"","") || die $DBI::errstr;
+my $riak = Net::Riak->new(host => $riak_url );
+
+#my $marcxml_bucket = $riak->bucket( 'koha.marcxml' );
+
+foreach my $table ( @tables ) {
+
+    my $sth = $dbh->prepare(qq{ select * from $table $limit}) || die $dbh->errstr();
+    $sth->execute || die $sth->errstr();
+    my @pk = $dbh->primary_key( undef, undef, $table );
+
+    print "import ", $sth->rows, " rows from $table pk:",dump( @pk ),"...\n";
+
+    my $bucket = $riak->bucket( 'koha.' . $table );
+
+    while (my $row = $sth->fetchrow_hashref() ) {
+
+        my $key = join('_', map { $row->{$_} } @pk);
+
+        if ( my $marcxml = delete $row->{marcxml} ) {
+            my $request = $riak->client->new_request(
+                'PUT', [ 'riak', "koha.marcxml/$key" ]
+            );
+            $request->header('Content-Type' => 'text/xml');
+            $request->content($marcxml);
+            my $response = $riak->client->send_request($request);
+
+            warn "$riak_url/riak/koha.marcxml/$key ", length($marcxml), " bytes\n";
+
+            unless ($response->is_success) {
+                die "Error put marcxml:", dump( $response );
+            }
+        }
+
+        warn "# $key ",dump($row);
+    }
+
+}