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);
26 my $institution = 'Grafički fakultet';
28 my $ep = EPrints->new();
29 my $repo = $ep->repository( 'grf' );
30 $repo->{config}->{enable_file_imports} = 1;
31 $repo->{config}->{enable_web_imports} = 1;
33 my $dataset = $repo->dataset( 'eprint' );
34 my $list = $dataset->search;
35 my $count = $list->count;
36 warn "# found [$count] eprints\n";
38 my $eprint = $dataset->dataobj( 21 );
39 warn dump( $eprint->get_value('institution'), $institution );
43 if ( $eprint->get_value( 'institution' ) ne $institution ) {
44 $eprint->set_value( 'institution' => $institution );
45 $eprint->save_revision();
57 my $mkp_path = "/mnt/share/MKP/ELEKTRONIČKI DOKUMENTI/EL.DOKUMENTI PO BIBLIOBROJU/";
58 my $koha_path = "/tmp/koha_ffzg";
60 open(my $fh, '-|:encoding(UTF-8)', 'find "' . $mkp_path . '" -iname "*.pdf"');
61 while(my $full_path = <$fh>) {
64 my $file = $1 if $full_path =~ m{/([^/]+)\.pdf}i;
67 if ( $file =~ m/(\d+)/ ) {
73 warn "# $file_id\t$full_path\n";
74 $files->{ $file_id } = $full_path;
78 warn "# got ", scalar keys %$files, " files\n";
80 store $files, "$koha_path.biblionumber.file";
84 open(my $tsv_fh, '<:encoding(UTF-8)', "$koha_path.tsv");
85 open(my $marc_fh, '<', "$koha_path.marc");
86 open(my $import_fh, '>', "$koha_path.import.marc");
93 $line =~ s/[\n\r]+$//;
95 if ( ! @cols && $line =~ m/#(.+)/ ) {
96 @cols = split(/\t/, $1);
100 my @v = split(/\t/, $_, $#cols + 1);
103 warn "## row = ",dump( \%row );
105 my $offset = $row{offset} // die "no offset";
106 my $biblionumber = $row{biblionumber} || die "no biblionumber";
108 warn "# ", join(' ', map { $row{$_} } qw(offset biblionumber title)), "\n";
110 exit if $ENV{LAST} && $eprintid >= $ENV{LAST};
112 if ( delete $files->{$biblionumber} ) {
115 seek $marc_fh, $last_offset, 0;
116 read $marc_fh, my $marc, $offset - $last_offset;
117 print $import_fh $marc;
118 warn "# marc $biblionumber\n";
124 $last_offset = $offset;
128 warn "# files left ", dump($files);
130 foreach my $biblionumber ( keys %$files ) {
131 if ( my $marc = get("https://koha.ffzg.hr/cgi-bin/koha/opac-export.pl?op=export&bib=$biblionumber&format=utf8") ) {
132 print $import_fh $marc;
133 warn "## marc $biblionumber from koha!";
135 warn "ERROR: can't fetch $biblionumber from koha";
139 warn "# stat ", dump($stat);