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';
16 my $dbh = DBI->connect($dbi,"","") || die $DBI::errstr;
17 my $riak = Net::Riak->new(host => $riak_url );
19 my $xml_bucket = $riak->bucket( 'koha.marcxml' );
20 $xml_bucket->set_properties({
21 precommit => [ { mod => 'riak_search_kv_hook', fun => 'precommit' } ],
25 foreach my $table ( @tables ) {
27 my $sth = $dbh->prepare(qq{ select * from $table $limit}) || die $dbh->errstr();
28 $sth->execute || die $sth->errstr();
29 my @pk = $dbh->primary_key( undef, undef, $table );
31 print "import ", $sth->rows, " rows from $table pk:",dump( @pk ),"...\n";
33 my $bucket = $riak->bucket( 'koha.' . $table );
34 $bucket->set_properties({
35 precommit => [ { mod => 'riak_search_kv_hook', fun => 'precommit' } ],
38 while (my $row = $sth->fetchrow_hashref() ) {
40 my $key = join('_', map { $row->{$_} } @pk);
42 if ( my $marcxml = delete $row->{marcxml} ) {
43 my $request = $riak->client->new_request(
44 'PUT', [ 'riak', "koha.marcxml/$key" ]
46 $request->header('Content-Type' => 'text/xml');
47 $request->content($marcxml);
48 my $response = $riak->client->send_request($request);
50 warn "$riak_url/riak/koha.marcxml/$key ", length($marcxml), " bytes\n";
52 unless ($response->is_success) {
53 die "Error put marcxml:", dump( $response );
57 warn "# $key ",dump($row);
58 $bucket->new_object( $key => $row )->store;
59 warn "$riak_url/riak/koha.$table/$key\n";