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