3 # KOHA_CONF=/etc/koha/sites/ffzg/koha-conf.xml perl -I /srv/koha_ffzg dlna.pl scan=1
8 use Data::Dump qw(dump);
13 my $dbh = C4::Context->dbh;
16 $q->header( -charset => 'utf-8' ),
17 , $q->start_html( -title => 'DLA RFID tag import from share' )
23 my $sth = $dbh->prepare($_);
25 while ( my $row = $sth->fetchrow_arrayref ) {
26 print qq{<tr><td>}, join(qq{</td><td>}, @$row), qq{</td></tr>\n};
34 if ( $q->param('scan') ) {
38 my $sth = $dbh->prepare(qq{
39 select date_scanned,source_id,count(*) from ffzg_inventura group by date_scanned,source_id order by date_scanned desc;
43 my $sth_insert = $dbh->prepare(qq{
44 insert ignore into ffzg_inventura (date_scanned,source_id,barcode) values (?,?,?)
48 my $date_scanned_source_id;
49 while ( my $row = $sth->fetchrow_arrayref ) {
51 $date_scanned_source_id->{ $row->[0] }->{ $row->[1] } = $row->[2];
55 open(my $find, '-|', qq{find /mnt/share/DLA/ . -name '*.pdX'});
58 if ( m{/(\w+)/(\w+)/(20\d\d-\d\d-\d\d)/upload/inv/.*pdX$} ) {
59 my ($path, $dir , $source_id, $date_scanned ) = ( $_, $1, $2, $3 );
61 if ( my $count = $date_scanned_source_id->{ $date_scanned }->{ $source_id } ) {
62 print "$date_scanned $source_id [$count] $path\n";
66 my $cache_path = "/tmp/dla.$date_scanned.$source_id";
67 if ( -e $cache_path ) {
68 print "$date_scanned $source_id NOT-IN-DATABASE $path $cache_path size ",-s $cache_path, "\n";
72 print "CONVERT $path -> $source_id $date_scanned $cache_path\n";
73 open(my $cache, '>', $cache_path);
75 open(my $string, '-|', qq{strings $path | sort -u});
77 while ( s/^.*?(130\d{7})//g ) {
79 warn "## barcode: $barcode";
80 $sth_insert->execute( $date_scanned, $source_id, $barcode );
81 print "++ $date_scanned $source_id ++ $barcode ++\n";
82 print $cache "$barcode\n";
87 print "# created $cache_path ", -s $cache_path, " bytes\n";
89 last; # FIXME import just one on one page load
98 -- total scanned by date ranges and source_id
99 select min(date_scanned),max(date_scanned),source_id,count(*) from ffzg_inventura group by source_id;
101 -- date scanned, source_id, tags seen