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 $institution = 'Grafički fakultet';
27 my $ep = EPrints->new();
28 my $repo = $ep->repository( 'grf' );
29 $repo->{config}->{enable_file_imports} = 1;
30 $repo->{config}->{enable_web_imports} = 1;
32 my $dataset = $repo->dataset( 'eprint' );
33 my $list = $dataset->search;
34 my $count = $list->count;
35 warn "# found [$count] eprints\n";
37 my $eprint = $dataset->dataobj( 21 );
38 warn dump( $eprint->get_value('institution'), $institution );
42 if ( $eprint->get_value( 'institution' ) ne $institution ) {
43 $eprint->set_value( 'institution' => $institution );
44 $eprint->save_revision();
56 my $mkp_path = "/mnt/share/MKP/ELEKTRONIČKI DOKUMENTI/EL.DOKUMENTI PO BIBLIOBROJU/";
57 my $koha_path = "/tmp/koha_ffzg";
59 open(my $fh, '-|:encoding(UTF-8)', 'find "' . $mkp_path . '" -iname "*.pdf"');
60 while(my $full_path = <$fh>) {
63 my $file = $1 if $full_path =~ m{/([^/]+)\.pdf}i;
66 if ( $file =~ m/(\d+)/ ) {
72 warn "# $file_id\t$full_path\n";
73 $files->{ $file_id } = $full_path;
77 warn "# got ", scalar keys %$files, " files\n";
79 store $files, "$koha_path.biblionumber.file";
83 open(my $tsv_fh, '<:encoding(UTF-8)', "$koha_path.tsv");
84 open(my $marc_fh, '<', "$koha_path.marc");
85 open(my $import_fh, '>', "$koha_path.import.marc");
92 $line =~ s/[\n\r]+$//;
94 if ( ! @cols && $line =~ m/#(.+)/ ) {
95 @cols = split(/\t/, $1);
99 my @v = split(/\t/, $_, $#cols + 1);
102 warn "## row = ",dump( \%row );
104 my $offset = $row{offset} // die "no offset";
105 my $biblionumber = $row{biblionumber} || die "no biblionumber";
107 warn "# ", join(' ', map { $row{$_} } qw(offset biblionumber title)), "\n";
109 exit if $ENV{LAST} && $eprintid >= $ENV{LAST};
111 if ( delete $files->{$biblionumber} ) {
114 seek $marc_fh, $last_offset, 0;
115 read $marc_fh, my $marc, $offset - $last_offset;
116 print $import_fh $marc;
117 warn "# marc $biblionumber\n";
123 $last_offset = $offset;
127 warn "# files left ", dump($files);
129 warn "# stat ", dump($stat);