1 #!/usr/bin/perl -I /usr/share/eprints3/perl_lib
7 # export single record to get structure:
8 # sudo -u eprints /usr/share/eprints3/bin/export snz archive XMLFiles 20 > /tmp/20.xml
13 # sudo -u eprints /usr/share/eprints3/bin/import --verbose --migration --enable-file-imports --update --enable-import-fields grf eprint XML /tmp/xml
15 # 4. re-run view generation
16 # sudo -u eprints /usr/share/eprints3/bin/generate_views grf --verbose
19 use Data::Dump qw(dump);
25 my $ep = EPrints->new();
26 my $repo = $ep->repository( 'snz' );
27 #$repo->{config}->{enable_file_imports} = 1;
28 #$repo->{config}->{enable_web_imports} = 1;
29 my $dataset = $repo->dataset( 'eprint' );
30 my $list = $dataset->search;
31 my $count = $list->count;
32 warn "# found [$count] eprints\n";
36 #warn "# ids = ",dump( $list->ids );
38 my $info = { count => 0 };
40 my( $session, $dataset, $eprint, $info ) = @_;
42 my $biblionumber = $eprint->get_value('biblionumber');
44 $info->{biblionumber}->{$biblionumber}++;
52 #my $eprint = $dataset->dataobj( 21 );
53 #warn dump( $eprint->get_value('institution'), $institution );
57 if ( $eprint->get_value( 'institution' ) ne $institution ) {
58 $eprint->set_value( 'institution' => $institution );
59 $eprint->save_revision();
69 my $mkp_path = "/mnt/share/MKP/ELEKTRONIÄŒKI DOKUMENTI/EL.DOKUMENTI PO BIBLIOBROJU/";
70 my $koha_path = "/tmp/koha_ffzg";
72 open(my $fh, '-|:encoding(UTF-8)', 'find "' . $mkp_path . '" -iname "*.pdf"');
73 while(my $full_path = <$fh>) {
76 my $file = $1 if $full_path =~ m{/([^/]+)\.pdf}i;
79 if ( $file =~ m/(\d+)/ ) {
85 warn "# $file_id\t$full_path\n";
86 $files->{ $file_id } = $full_path;
90 warn "# got ", scalar keys %$files, " files\n";
92 store $files, "$koha_path.biblionumber.file";
96 open(my $tsv_fh, '<:encoding(UTF-8)', "$koha_path.tsv");
97 open(my $marc_fh, '<', "$koha_path.marc");
98 open(my $import_fh, '>', "$koha_path.import.marc");
106 $line =~ s/[\n\r]+$//;
108 if ( ! @cols && $line =~ m/#(.+)/ ) {
109 @cols = split(/\t/, $1);
113 my @v = split(/\t/, $line, $#cols + 1);
116 #warn "## row = ",dump( \%row );
118 my $offset = $row{offset} // die "no offset";
119 my $biblionumber = $row{biblionumber} || die "no biblionumber";
121 # warn "# ", join(' ', map { $row{$_} } qw(biblionumber title)), "\n";
123 if ( delete $files->{$biblionumber} ) {
126 if ( $info->{biblionumber}->{$biblionumber} ) {
128 warn "EXISTING $biblionumber found in eprints\n";
133 seek $marc_fh, $last_offset, 0;
134 read $marc_fh, my $marc, $offset - $last_offset;
135 print $import_fh $marc;
136 warn "# NEW ", join(' ', map { $row{$_} } qw(biblionumber title)), "\n";
137 # warn "# NEW $biblionumber\n";
145 $last_offset = $offset;
149 warn "# files left ", dump($files);
151 foreach my $biblionumber ( keys %$files ) {
153 if ( $info->{biblionumber}->{$biblionumber} ) {
155 warn "EXISTING $biblionumber found in eprints\n";
159 if ( my $marc = get("https://koha.ffzg.hr/cgi-bin/koha/opac-export.pl?op=export&bib=$biblionumber&format=utf8") ) {
160 print $import_fh $marc;
161 warn "## marc $biblionumber from koha!";
164 warn "ERROR: can't fetch $biblionumber from koha";
168 warn "# stat ", dump($stat);