import cover images from filesystem and create biblio and items
[koha_gimpoz] / misc / gimpoz / import-images.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use autodie;
5 use Data::Dump qw(dump);
6
7 use MARC::Record;
8
9 $|=1;
10 use lib '/srv/koha_gimpoz/';
11
12 BEGIN {
13         $ENV{KOHA_CONF} = '/etc/koha/sites/gimpoz/koha-conf.xml';
14 }
15 use C4::Images;
16 use C4::Biblio;
17 use C4::Items;
18
19 my $source_dir = '/data/gimpoz/dvd1';
20 my $replace = 1;
21 my $frameworkcode = '';
22
23 sub marc {
24         my $marc = {@_};
25         print "MARC ",dump($marc),$/;
26 }
27
28 my $biblionumber;
29
30 open(my $find, '-|', qq{find $source_dir -iname "*.jpg" | sort});
31 while(<$find>) {
32         chomp;
33         my $path = $_;
34         warn "# path $path\n";
35         s{^\Q$source_dir\E/*}{};
36         my $student = $1 if s{^(.+?)/}{};
37         $student =~ s/^(\d+).*/$1/;
38         my $lokacija = $1 if s{^(.+?)/}{};
39
40         my $inventarni_broj = $_;
41         $inventarni_broj =~ s/\.jpg$//i;
42
43         if ( $inventarni_broj =~ m/\s*-\s*([a-k])\s*$/i ) {
44                 warn "# $biblionumber dio $1\n";
45         } else {
46                 my $record = MARC::Record->new;
47                 $record->add_fields(
48                         [ 245, " ", " ", a => $inventarni_broj ],
49                         [ 952, " ", " ", t => $inventarni_broj ],
50                 );
51
52                 my $biblioitemnumber;
53                 ($biblionumber,$biblioitemnumber) = AddBiblio($record,$frameworkcode);
54                 warn "# AddBiblio $biblionumber $biblioitemnumber [$inventarni_broj]\n";
55
56                 my ($biblionumber, $biblioitemnumber, $itemnumber)
57                         = AddItemFromMarc($record, $biblionumber);
58
59                 warn "# AddItemFromMarc $biblionumber $biblioitemnumber $itemnumber\n";
60
61         }
62
63         my $image = GD::Image->new($path);
64         PutImage($biblionumber, $image, $replace);
65
66         print dump( $biblionumber, $student, $lokacija, $inventarni_broj ),$/;
67 }
68