6 use Data::Dump qw/dump/;
9 my $riak_url = 'http://10.60.0.92:8098';
10 my $dbi = 'DBI:mysql:dbname=koha;host=10.60.0.10;port=3306';
17 $limit = $ENV{LIMIT} if $ENV{LIMIT};
19 my $dbh = DBI->connect($dbi,"","") || die $DBI::errstr;
20 my $riak = RiakSearch->new( $riak_url );
22 warn $riak->request( 'GET' => '/koha.marcxml' );
24 sub riak_search_kv_hook {
25 $riak->request( 'PUT' => shift, { props => {
26 precommit => [ { mod => 'riak_search_kv_hook', fun => 'precommit' } ],
28 # last_write_wins => 'true',
33 riak_search_kv_hook 'koha.marcxml';
35 foreach my $table ( @tables ) {
37 my $sth = $dbh->prepare(qq{ select * from $table $limit}) || die $dbh->errstr();
38 $sth->execute || die $sth->errstr();
39 my @pk = $dbh->primary_key( undef, undef, $table );
41 print "import ", $sth->rows, " rows from $table pk:",dump( @pk ),"...\n";
43 riak_search_kv_hook "koha.$table";
45 while (my $row = $sth->fetchrow_hashref() ) {
47 my $key = join('_', map { $row->{$_} } @pk);
48 my $biblionumber = $row->{biblionumber};
50 if ( my $marcxml = delete $row->{marcxml} ) {
51 $riak->request( 'PUT' => "/koha.marcxml/$key", $marcxml, {
52 'Content-Type' => 'text/xml',
53 'Link' => qq|</riak/koha.$table/$biblionumber>; riaktag="biblio"|,
57 # warn "## $key ",dump($row);
60 $headers->{Link} = qq|</riak/koha.biblio/$biblionumber>; riaktag="biblio"|
61 if $biblionumber && $key !~ m/biblionumber/;
63 $riak->request( 'PUT' => "/koha.$table/$key", $row, $headers );