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);
14 my $dbh = C4::Context->dbh;
16 $ENV{REQUEST_URI} =~ s{/intranet/}{/cgi-bin/koha/}; # fix plack rewrite
19 $q->header( -charset => 'utf-8' ),
20 , $q->start_html( -title => 'DLA RFID tag import from share' )
24 my ($status, $cookie, $sessionId) = C4::Auth::check_api_auth($q, { tools => 'inventory' });
25 if ($status ne "ok") {
26 print "This requres tools - inventory permission";
30 if ( $q->param('scan') ) {
34 my $sth = $dbh->prepare(qq{
35 select date_scanned,source_id,count(*) from ffzg_inventura group by date_scanned,source_id order by date_scanned desc;
39 my $sth_insert = $dbh->prepare(qq{
40 insert ignore into ffzg_inventura (date_scanned,source_id,barcode) values (?,?,?)
44 my $date_scanned_source_id;
45 while ( my $row = $sth->fetchrow_arrayref ) {
47 $date_scanned_source_id->{ $row->[0] }->{ $row->[1] } = $row->[2];
51 open(my $find, '-|', qq{find /mnt/share/DLA/ . -name '*.pdX'});
54 if ( m{/(\w+)/(\w+)/(20\d\d-\d\d-\d\d)/upload/inv/.*pdX$} ) {
55 my ($path, $dir , $source_id, $date_scanned ) = ( $_, $1, $2, $3 );
57 if ( my $count = $date_scanned_source_id->{ $date_scanned }->{ $source_id } ) {
58 print "$date_scanned $source_id [$count] $path\n";
62 my $cache_path = "/tmp/dla.$date_scanned.$source_id";
63 if ( -e $cache_path ) {
64 print "$date_scanned $source_id NOT-IN-DATABASE $path $cache_path size ",-s $cache_path, "\n";
68 print "CONVERT $path -> $source_id $date_scanned $cache_path\n";
69 open(my $cache, '>', $cache_path);
71 open(my $string, '-|', qq{strings $path | sort -u});
73 while ( s/^.*?(130\d{7})//g ) {
75 warn "## barcode: $barcode";
76 $sth_insert->execute( $date_scanned, $source_id, $barcode );
77 print "++ $date_scanned $source_id ++ $barcode ++\n";
78 print $cache "$barcode\n";
83 print "# created $cache_path ", -s $cache_path, " bytes\n";
85 my $sth_update = $dbh->prepare(qq{
88 select ffzg_inventura.barcode,items.datelastseen,max(ffzg_inventura.date_scanned) as date_scanned
90 join items on items.barcode = ffzg_inventura.barcode
91 where date_scanned = ? and source_id = ?
92 group by ffzg_inventura.barcode
93 having datelastseen < max(date_scanned)
95 on a.barcode = b.barcode
96 set a.datelastseen = b.date_scanned, a.itemlost = 0 ;
99 $sth_update->execute( $date_scanned, $source_id );
101 last; # FIXME import just one on one page load
110 my $sth = $dbh->prepare($_);
112 while ( my $row = $sth->fetchrow_arrayref ) {
113 print qq{<tr><td>}, join(qq{</td><td>}, @$row), qq{</td></tr>\n};
115 print qq{</table>\n};
123 print $q->start_form, $q->submit(-name => 'scan'), $q->end_form;
129 -- total scanned by date ranges and source_id
130 select min(date_scanned),max(date_scanned),source_id,count(*) from ffzg_inventura group by source_id;