6 use Data::Dump qw/dump/;
10 my $debug = @ARGV ? 1 : 0;
12 my $database = 'reblog';
14 my $dbi = "DBI:mysql:database=$database";
15 $dbi .= ";host=127.0.0.1;port=13306"; # XXX over ssh
17 my $dbh = DBI->connect($dbi,"","",{ RaiseError => 1 });
31 items_userdata.item_id,
35 join published_items p
36 on items_userdata.item_id = p.item_id and label='tags'
38 items_userdata.item_id > ?
39 order by items_userdata.item_id asc
42 my $conn = MongoDB::Connection->new;
43 my $db = $conn->get_database( $database );
45 my $items = $db->get_collection( 'items' );
47 $items->ensure_index( { id => 1 } );
49 # > db.items.find().sort({item_id:-1}).limit(1);
50 my $last = $items->query()->sort({ 'id' => -1 })->limit(1)->next;
52 my $last_item_id = $last->{id} || 0;
54 print "Fetching items from $dbi id > $last_item_id\n";
56 my $sth = $dbh->prepare($sql);
57 $sth->execute( $last_item_id );
59 warn dump( $sth->{NAME} );
61 print "found ",$sth->rows," items to process...\n";
63 while (my $row = $sth->fetchrow_hashref() ) {
65 map { $row->{$_} * 1 } grep { m/id/ && $row->{$_} =~ /^\d+$/ } keys %$row;
66 $items->insert( $row );
71 my $sth_tags = $dbh->prepare($sql_tags);
72 $sth_tags->execute( $last_item_id );
73 print "found ",$sth_tags->rows, " tags found...\n";
77 my $row_tags = $sth_tags->fetchrow_hashref();
79 my @join = ( 'id' => 'item_id' );