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 = "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 => { precommit => [ { mod => 'riak_search_kv_hook', fun => 'precommit' } ] } });
28 riak_search_kv_hook '/koha.marcxml';
30 foreach my $table ( @tables ) {
32 my $sth = $dbh->prepare(qq{ select * from $table $limit}) || die $dbh->errstr();
33 $sth->execute || die $sth->errstr();
34 my @pk = $dbh->primary_key( undef, undef, $table );
36 print "import ", $sth->rows, " rows from $table pk:",dump( @pk ),"...\n";
38 riak_search_kv_hook "koha.$table";
40 while (my $row = $sth->fetchrow_hashref() ) {
42 my $key = join('_', map { $row->{$_} } @pk);
44 if ( my $marcxml = delete $row->{marcxml} ) {
45 $riak->request( 'PUT' => "/koha.marcxml/$key", $marcxml, {
46 'Content-Type' => 'text/xml',
50 # warn "## $key ",dump($row);
53 if ( my $biblionumber = $row->{biblionumber} ) {
54 $headers->{Link} = qq|</riak/koha.biblio/$biblionumber>; riaktag="biblio"| unless $key =~ m/biblionumber/;
56 $riak->request( 'PUT' => "/koha.$table/$key", $row, $headers );