View | Details | Raw Unified | Return to bug 5579
Collapse All | Expand All

(-)a/C4/Biblio.pm (-23 / +1 lines)
Lines 311-339 sub ModBiblio { Link Here
311
        $record->delete_field($field);
311
        $record->delete_field($field);
312
    }
312
    }
313
313
314
    # parse each item, and, for an unknown reason, re-encode each subfield
315
    # if you don't do that, the record will have encoding mixed
316
    # and the biblio will be re-encoded.
317
    # strange, I (Paul P.) searched more than 1 day to understand what happends
318
    # but could only solve the problem this way...
319
    my @fields = $oldRecord->field($itemtag);
320
    foreach my $fielditem (@fields) {
321
        my $field;
322
        foreach ( $fielditem->subfields() ) {
323
            # re-encode the subfield only if it isn't already in utf-8.
324
            my ($tag, $value) = @$_;
325
            $tag = Encode::encode('utf-8', $tag) unless utf8::is_utf8($tag);
326
            $value = Encode::encode('utf-8', $value) unless utf8::is_utf8($value);
327
328
            if ($field) {
329
                $field->add_subfields( $tag => $value );
330
            } else {
331
                $field = MARC::Field->new( "$itemtag", '', '', $tag => $value );
332
            }
333
        }
334
        $record->append_fields($field);
335
    }
336
337
    foreach my $field ($record->fields()) {
314
    foreach my $field ($record->fields()) {
338
        if (! $field->is_control_field()) {
315
        if (! $field->is_control_field()) {
339
            if (scalar($field->subfields()) == 0) {
316
            if (scalar($field->subfields()) == 0) {
Lines 1065-1070 sub GetMarcBiblio { Link Here
1065
    if ($marcxml) {
1042
    if ($marcxml) {
1066
        $record = eval { MARC::Record::new_from_xml( $marcxml, "utf8", C4::Context->preference('marcflavour') ) };
1043
        $record = eval { MARC::Record::new_from_xml( $marcxml, "utf8", C4::Context->preference('marcflavour') ) };
1067
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1044
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1045
        return unless $record;
1068
1046
1069
        #      $record = MARC::Record::new_from_usmarc( $marc) if $marc;
1047
        #      $record = MARC::Record::new_from_usmarc( $marc) if $marc;
1070
        return $record;
1048
        return $record;
(-)a/C4/Items.pm (-18 / +10 lines)
Lines 263-268 sub AddItem { Link Here
263
    # create MARC tag representing item and add to bib
263
    # create MARC tag representing item and add to bib
264
    my $new_item_marc = _marc_from_item_hash($item, $frameworkcode, $unlinked_item_subfields);
264
    my $new_item_marc = _marc_from_item_hash($item, $frameworkcode, $unlinked_item_subfields);
265
    _add_item_field_to_biblio($new_item_marc, $item->{'biblionumber'}, $frameworkcode );
265
    _add_item_field_to_biblio($new_item_marc, $item->{'biblionumber'}, $frameworkcode );
266
    #_add_item_field_to_biblio($new_item_marc, $item->{'biblionumber'}, $frameworkcode );
266
   
267
   
267
    logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
268
    logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
268
    
269
    
Lines 368-374 sub AddItemBatchFromMarc { Link Here
368
    }
369
    }
369
370
370
    # update the MARC biblio
371
    # update the MARC biblio
371
    $biblionumber = ModBiblioMarc( $record, $biblionumber, $frameworkcode );
372
 #   $biblionumber = ModBiblioMarc( $record, $biblionumber, $frameworkcode );
372
373
373
    return (\@itemnumbers, \@errors);
374
    return (\@itemnumbers, \@errors);
374
}
375
}
Lines 513-519 sub ModItem { Link Here
513
    my $new_item_marc = _marc_from_item_hash($whole_item, $frameworkcode, $unlinked_item_subfields) 
514
    my $new_item_marc = _marc_from_item_hash($whole_item, $frameworkcode, $unlinked_item_subfields) 
514
        or die "FAILED _marc_from_item_hash($whole_item, $frameworkcode)";
515
        or die "FAILED _marc_from_item_hash($whole_item, $frameworkcode)";
515
    
516
    
516
    _replace_item_field_in_biblio($new_item_marc, $biblionumber, $itemnumber, $frameworkcode);
517
    #_replace_item_field_in_biblio($new_item_marc, $biblionumber, $itemnumber, $frameworkcode);
517
	($new_item_marc       eq '0') and die "$new_item_marc is '0', not hashref";  # logaction line would crash anyway
518
	($new_item_marc       eq '0') and die "$new_item_marc is '0', not hashref";  # logaction line would crash anyway
518
    logaction("CATALOGUING", "MODIFY", $itemnumber, $new_item_marc->as_formatted) if C4::Context->preference("CataloguingLog");
519
    logaction("CATALOGUING", "MODIFY", $itemnumber, $new_item_marc->as_formatted) if C4::Context->preference("CataloguingLog");
519
}
520
}
Lines 576-598 sub DelItem { Link Here
576
577
577
    # get the MARC record
578
    # get the MARC record
578
    my $record = GetMarcBiblio($biblionumber);
579
    my $record = GetMarcBiblio($biblionumber);
579
    my $frameworkcode = GetFrameworkCode($biblionumber);
580
    ModZebra( $biblionumber, "specialUpdate", "biblioserver", undef, undef );
580
581
581
    # backup the record
582
    # backup the record
582
    my $copy2deleted = $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?");
583
    my $copy2deleted = $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?");
583
    $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
584
    $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
584
585
585
    #search item field code
586
    #search item field code
586
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
587
    my @fields = $record->field($itemtag);
588
589
    # delete the item specified
590
    foreach my $field (@fields) {
591
        if ( $field->subfield($itemsubfield) eq $itemnumber ) {
592
            $record->delete_field($field);
593
        }
594
    }
595
    &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
596
    logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
587
    logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
597
}
588
}
598
589
Lines 2066-2081 sub MoveItemFromBiblio { Link Here
2066
	    }
2057
	    }
2067
2058
2068
	    # Saving the modification
2059
	    # Saving the modification
2069
	    ModBiblioMarc($record, $frombiblio, $frameworkcode);
2060
	    #ModBiblioMarc($record, $frombiblio, $frameworkcode);
2070
2061
2071
	    # Getting the record we want to move the item to
2062
	    # Getting the record we want to move the item to
2072
	    $record = GetMarcBiblio($tobiblio);
2063
	    #$record = GetMarcBiblio($tobiblio);
2073
2064
2074
	    # Inserting the previously saved item
2065
	    # Inserting the previously saved item
2075
	    $record->insert_fields_ordered($item);	
2066
	    #$record->insert_fields_ordered($item);	
2076
2067
2077
	    # Saving the modification
2068
	    # Saving the modification
2078
	    ModBiblioMarc($record, $tobiblio, $frameworkcode);
2069
	    #ModBiblioMarc($record, $tobiblio, $frameworkcode);
2079
2070
2080
	} else {
2071
	} else {
2081
	    return undef;
2072
	    return undef;
Lines 2159-2164 sub _koha_modify_item { Link Here
2159
        $error.="ERROR in _koha_modify_item $query".$dbh->errstr;
2150
        $error.="ERROR in _koha_modify_item $query".$dbh->errstr;
2160
        warn $error;
2151
        warn $error;
2161
    }
2152
    }
2153
    ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
2162
    return ($item->{'itemnumber'},$error);
2154
    return ($item->{'itemnumber'},$error);
2163
}
2155
}
2164
2156
Lines 2302-2308 sub _replace_item_field_in_biblio { Link Here
2302
    }
2294
    }
2303
2295
2304
    # save the record
2296
    # save the record
2305
    ModBiblioMarc($completeRecord, $biblionumber, $frameworkcode);
2297
    #ModBiblioMarc($completeRecord, $biblionumber, $frameworkcode);
2306
}
2298
}
2307
2299
2308
=head2 _repack_item_errors
2300
=head2 _repack_item_errors
(-)a/misc/maintenance/remove_items_from_biblioitems.pl (+50 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use strict;
4
use warnings;
5
6
use C4::Context;
7
use C4::Biblio;
8
use Getopt::Long;
9
10
my ($wherestring,$run,$want_help);
11
my $result           = GetOptions(
12
    'where:s'        => \$wherestring,
13
    '--run'        => \$run,
14
    'help|h'            => \$want_help,
15
);
16
if ( not $result or $want_help ) {
17
    print_usage();
18
    exit 0;
19
}
20
21
22
my $dbh=C4::Context->dbh;
23
my $querysth=qq{SELECT biblionumber from biblioitems };
24
$querysth.=" WHERE $wherestring " if ($wherestring);
25
my $query=$dbh->prepare($querysth);
26
27
$query->execute;
28
while (my $biblionumber=$query->fetchrow){
29
    my $record=GetMarcBiblio($biblionumber);
30
    
31
    if ($record){
32
        ModBiblio($record,$biblionumber,GetFrameworkCode($biblionumber)) ;
33
    }
34
    else {
35
        print "error in $biblionumber : can't parse biblio";
36
    }
37
}
38
sub print_usage {
39
    print <<_USAGE_;
40
$0: removes items from selected biblios
41
42
43
Parameters:
44
    -where                  use this to limit modifications to some biblios
45
    --run                   run the command
46
    --help or -h            show this message.
47
_USAGE_
48
}
49
50
#
(-)a/misc/migration_tools/rebuild_zebra.pl (-5 / +28 lines)
Lines 9-14 use File::Temp qw/ tempdir /; Link Here
9
use File::Path;
9
use File::Path;
10
use C4::Biblio;
10
use C4::Biblio;
11
use C4::AuthoritiesMarc;
11
use C4::AuthoritiesMarc;
12
use C4::Items;
12
13
13
# 
14
# 
14
# script that checks zebradir structure & create directories & mandatory files if needed
15
# script that checks zebradir structure & create directories & mandatory files if needed
Lines 310-315 sub export_marc_records_from_sth { Link Here
310
    my $num_exported = 0;
311
    my $num_exported = 0;
311
    open (OUT, ">:utf8 ", "$directory/exported_records") or die $!;
312
    open (OUT, ">:utf8 ", "$directory/exported_records") or die $!;
312
    my $i = 0;
313
    my $i = 0;
314
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",'');
313
    while (my ($record_number) = $sth->fetchrow_array) {
315
    while (my ($record_number) = $sth->fetchrow_array) {
314
        print "." if ( $verbose_logging );
316
        print "." if ( $verbose_logging );
315
        print "\r$i" unless ($i++ %100 or !$verbose_logging);
317
        print "\r$i" unless ($i++ %100 or !$verbose_logging);
Lines 317-322 sub export_marc_records_from_sth { Link Here
317
            my $marcxml = $record_type eq 'biblio'
319
            my $marcxml = $record_type eq 'biblio'
318
                          ? GetXmlBiblio( $record_number )
320
                          ? GetXmlBiblio( $record_number )
319
                          : GetAuthorityXML( $record_number );
321
                          : GetAuthorityXML( $record_number );
322
            if ($record_type eq 'biblio'){
323
                #CALL  sub ProcessItems
324
                my @items=GetItemsInfo($record_number,'intra',30);
325
                if (@items){
326
                    my $record=MARC::Record->new;
327
                    my @itemsrecord;
328
                    foreach my $item (@items){
329
                        my $record=Item2Marc($item, $record_number);                        
330
                        push @itemsrecord, $record->field($itemtag);
331
                        #if xml then print itemfield as xml
332
                        # and update marcxml
333
                        # else push field
334
                    }
335
                    $record->insert_fields_ordered(@itemsrecord);
336
                    my $itemsxml=$record->as_xml_record();
337
                    my $searchstring='<record>\n';
338
                    my $index=index($itemsxml,'<record>\n',0);
339
                    $itemsxml=substr($itemsxml,$index+length($searchstring));
340
                    $searchstring='</record>';
341
                    $marcxml=substr($marcxml,0,index($marcxml,$searchstring));
342
                    $marcxml.=$itemsxml;
343
                }
344
            }
320
            if ( $marcxml ) {
345
            if ( $marcxml ) {
321
                print OUT $marcxml if $marcxml;
346
                print OUT $marcxml if $marcxml;
322
                $num_exported++;
347
                $num_exported++;
Lines 330-336 sub export_marc_records_from_sth { Link Here
330
            # strung together with no single root element.  zebraidx doesn't seem
355
            # strung together with no single root element.  zebraidx doesn't seem
331
            # to care, though, at least if you're using the GRS-1 filter.  It does
356
            # to care, though, at least if you're using the GRS-1 filter.  It does
332
            # care if you're using the DOM filter, which requires valid XML file(s).
357
            # care if you're using the DOM filter, which requires valid XML file(s).
333
            print OUT ($as_xml) ? $marc->as_xml_record() : $marc->as_usmarc();
358
            print OUT ($as_xml) ? $marc->as_xml_record(C4::Context->preference('marcflavour')) : $marc->as_usmarc();
334
            $num_exported++;
359
            $num_exported++;
335
        }
360
        }
336
    }
361
    }
Lines 358-364 sub export_marc_records_from_list { Link Here
358
            # strung together with no single root element.  zebraidx doesn't seem
383
            # strung together with no single root element.  zebraidx doesn't seem
359
            # to care, though, at least if you're using the GRS-1 filter.  It does
384
            # to care, though, at least if you're using the GRS-1 filter.  It does
360
            # care if you're using the DOM filter, which requires valid XML file(s).
385
            # care if you're using the DOM filter, which requires valid XML file(s).
361
            print OUT ($as_xml) ? $marc->as_xml_record() : $marc->as_usmarc();
386
            print OUT ($as_xml) ? $marc->as_xml_record(C4::Context->preference('marcflavour')) : $marc->as_usmarc();
362
            $num_exported++;
387
            $num_exported++;
363
        }
388
        }
364
    }
389
    }
Lines 387-393 sub generate_deleted_marc_records { Link Here
387
            fix_unimarc_100($marc);
412
            fix_unimarc_100($marc);
388
        }
413
        }
389
414
390
        print OUT ($as_xml) ? $marc->as_xml_record() : $marc->as_usmarc();
415
        print OUT ($as_xml) ? $marc->as_xml_record(C4::Context->preference("marcflavour")) : $marc->as_usmarc();
391
        $num_exported++;
416
        $num_exported++;
392
    }
417
    }
393
    print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
418
    print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
394
- 
395
 the update to run
419
 the update to run
396
--
397
misc/maintenance/remove_items_from_biblioitems.pl |   61 ++++++++++++++-------
420
misc/maintenance/remove_items_from_biblioitems.pl |   61 ++++++++++++++-------
398
1 files changed, 41 insertions(+), 20 deletions(-)
421
1 files changed, 41 insertions(+), 20 deletions(-)
399
mode change 100644 => 100755 misc/maintenance/remove_items_from_biblioitems.pl
422
mode change 100644 => 100755 misc/maintenance/remove_items_from_biblioitems.pl
(-)a/misc/maintenance/remove_items_from_biblioitems.pl (-22 / +41 lines)
Lines 1-5 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright 2010 BibLibre
4
# Copyright 2011 Equinox Software, Inc.
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it under the
9
# terms of the GNU General Public License as published by the Free Software
10
# Foundation; either version 2 of the License, or (at your option) any later
11
# version.
12
#
13
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License along
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
3
use strict;
21
use strict;
4
use warnings;
22
use warnings;
5
23
Lines 7-50 use C4::Context; Link Here
7
use C4::Biblio;
25
use C4::Biblio;
8
use Getopt::Long;
26
use Getopt::Long;
9
27
10
my ($wherestring,$run,$want_help);
28
my ($wherestring, $run, $want_help);
11
my $result           = GetOptions(
29
my $result = GetOptions(
12
    'where:s'        => \$wherestring,
30
    'where:s'      => \$wherestring,
13
    '--run'        => \$run,
31
    '--run'        => \$run,
14
    'help|h'            => \$want_help,
32
    'help|h'       => \$want_help,
15
);
33
);
16
if ( not $result or $want_help ) {
34
35
if ( not $result or not $run or $want_help ) {
17
    print_usage();
36
    print_usage();
18
    exit 0;
37
    exit 0;
19
}
38
}
20
39
21
40
my $dbh = C4::Context->dbh;
22
my $dbh=C4::Context->dbh;
41
my $querysth =  qq{SELECT biblionumber from biblioitems };
23
my $querysth=qq{SELECT biblionumber from biblioitems };
42
$querysth    .= " WHERE $wherestring " if ($wherestring);
24
$querysth.=" WHERE $wherestring " if ($wherestring);
43
my $query = $dbh->prepare($querysth);
25
my $query=$dbh->prepare($querysth);
26
27
$query->execute;
44
$query->execute;
28
while (my $biblionumber=$query->fetchrow){
45
while (my $biblionumber = $query->fetchrow){
29
    my $record=GetMarcBiblio($biblionumber);
46
    my $record = GetMarcBiblio($biblionumber);
30
    
47
    
31
    if ($record){
48
    if ($record) {
32
        ModBiblio($record,$biblionumber,GetFrameworkCode($biblionumber)) ;
49
        ModBiblio($record, $biblionumber, GetFrameworkCode($biblionumber)) ;
33
    }
50
    }
34
    else {
51
    else {
35
        print "error in $biblionumber : can't parse biblio";
52
        print "error in $biblionumber : can't parse biblio";
36
    }
53
    }
37
}
54
}
55
38
sub print_usage {
56
sub print_usage {
39
    print <<_USAGE_;
57
    print <<_USAGE_;
40
$0: removes items from selected biblios
58
$0: removes items from selected biblios
41
59
60
This utility is meant to be run as part of the upgrade to
61
Koha 3.4.  It removes the 9XX fields in the bib records that
62
store a (now) duplicate copy of the item record information.  After
63
running this utility, a full reindexing of the bibliographic records
64
should be run using rebuild_zebra.pl -b -r.
42
65
43
Parameters:
66
Parameters:
44
    -where                  use this to limit modifications to some biblios
67
    -where                  use this to limit modifications to selected biblios
45
    --run                   run the command
68
    --run                   perform the update
46
    --help or -h            show this message.
69
    --help or -h            show this message
47
_USAGE_
70
_USAGE_
48
}
71
}
49
50
#
51
- 
52
--
53
C4/Items.pm |   55 +++++++------------------------------------------------
72
C4/Items.pm |   55 +++++++------------------------------------------------
54
1 files changed, 7 insertions(+), 48 deletions(-)
73
1 files changed, 7 insertions(+), 48 deletions(-)
(-)a/C4/Items.pm (-50 / +7 lines)
Lines 2021-2079 sub MoveItemFromBiblio { Link Here
2021
    $sth = $dbh->prepare("UPDATE items SET biblioitemnumber = ?, biblionumber = ? WHERE itemnumber = ? AND biblionumber = ?");
2021
    $sth = $dbh->prepare("UPDATE items SET biblioitemnumber = ?, biblionumber = ? WHERE itemnumber = ? AND biblionumber = ?");
2022
    my $return = $sth->execute($tobiblioitem, $tobiblio, $itemnumber, $frombiblio);
2022
    my $return = $sth->execute($tobiblioitem, $tobiblio, $itemnumber, $frombiblio);
2023
    if ($return == 1) {
2023
    if ($return == 1) {
2024
2024
        ModZebra( $tobiblio, "specialUpdate", "biblioserver", undef, undef );
2025
	# Getting framework
2025
        ModZebra( $frombiblio, "specialUpdate", "biblioserver", undef, undef );
2026
	my $frameworkcode = GetFrameworkCode($frombiblio);
2027
2028
	# Getting marc field for itemnumber
2029
	my ($itemtag, $itemsubfield) = GetMarcFromKohaField('items.itemnumber', $frameworkcode);
2030
2031
	# Getting the record we want to move the item from
2032
	my $record = GetMarcBiblio($frombiblio);
2033
2034
	# The item we want to move
2035
	my $item;
2036
2037
	# For each item
2038
	foreach my $fielditem ($record->field($itemtag)){
2039
		# If it is the item we want to move
2040
		if ($fielditem->subfield($itemsubfield) == $itemnumber) {
2041
		    # We save it
2042
		    $item = $fielditem;
2043
		    # Then delete it from the record
2044
		    $record->delete_field($fielditem) 
2045
		}
2046
	}
2047
2048
	# If we found an item (should always true, except in case of database-marcxml inconsistency)
2049
	if ($item) {
2050
2051
	    # Checking if the item we want to move is in an order 
2026
	    # Checking if the item we want to move is in an order 
2052
	    my $order = GetOrderFromItemnumber($itemnumber);
2027
        my $order = GetOrderFromItemnumber($itemnumber);
2053
	    if ($order) {
2028
	    if ($order) {
2054
		# Replacing the biblionumber within the order if necessary
2029
		    # Replacing the biblionumber within the order if necessary
2055
		$order->{'biblionumber'} = $tobiblio;
2030
		    $order->{'biblionumber'} = $tobiblio;
2056
	        ModOrder($order);
2031
	        ModOrder($order);
2057
	    }
2032
	    }
2058
2033
        return $tobiblio;
2059
	    # Saving the modification
2060
	    #ModBiblioMarc($record, $frombiblio, $frameworkcode);
2061
2062
	    # Getting the record we want to move the item to
2063
	    #$record = GetMarcBiblio($tobiblio);
2064
2065
	    # Inserting the previously saved item
2066
	    #$record->insert_fields_ordered($item);	
2067
2068
	    # Saving the modification
2069
	    #ModBiblioMarc($record, $tobiblio, $frameworkcode);
2070
2071
	} else {
2072
	    return undef;
2073
	}
2034
	}
2074
    } else {
2035
    return;
2075
	return undef;
2076
    }
2077
}
2036
}
2078
2037
2079
=head2 DelItemCheck
2038
=head2 DelItemCheck
2080
- 
2081
--
2082
C4/Items.pm |    6 +++---
2039
C4/Items.pm |    6 +++---
2083
1 files changed, 3 insertions(+), 3 deletions(-)
2040
1 files changed, 3 insertions(+), 3 deletions(-)
(-)a/C4/Items.pm (-5 / +3 lines)
Lines 261-269 sub AddItem { Link Here
261
    $item->{'itemnumber'} = $itemnumber;
261
    $item->{'itemnumber'} = $itemnumber;
262
262
263
    # create MARC tag representing item and add to bib
263
    # create MARC tag representing item and add to bib
264
    my $new_item_marc = _marc_from_item_hash($item, $frameworkcode, $unlinked_item_subfields);
264
    #my $new_item_marc = _marc_from_item_hash($item, $frameworkcode, $unlinked_item_subfields);
265
    _add_item_field_to_biblio($new_item_marc, $item->{'biblionumber'}, $frameworkcode );
266
    #_add_item_field_to_biblio($new_item_marc, $item->{'biblionumber'}, $frameworkcode );
265
    #_add_item_field_to_biblio($new_item_marc, $item->{'biblionumber'}, $frameworkcode );
266
    ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
267
   
267
   
268
    logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
268
    logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
269
    
269
    
Lines 507-512 sub ModItem { Link Here
507
507
508
    # update biblio MARC XML
508
    # update biblio MARC XML
509
    my $whole_item = GetItem($itemnumber) or die "FAILED GetItem($itemnumber)";
509
    my $whole_item = GetItem($itemnumber) or die "FAILED GetItem($itemnumber)";
510
    ModZebra( $whole_item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
510
511
511
    unless (defined $unlinked_item_subfields) {
512
    unless (defined $unlinked_item_subfields) {
512
        $unlinked_item_subfields = _parse_unlinked_item_subfields_from_xml($whole_item->{'more_subfields_xml'});
513
        $unlinked_item_subfields = _parse_unlinked_item_subfields_from_xml($whole_item->{'more_subfields_xml'});
Lines 2109-2115 sub _koha_modify_item { Link Here
2109
        $error.="ERROR in _koha_modify_item $query".$dbh->errstr;
2110
        $error.="ERROR in _koha_modify_item $query".$dbh->errstr;
2110
        warn $error;
2111
        warn $error;
2111
    }
2112
    }
2112
    ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
2113
    return ($item->{'itemnumber'},$error);
2113
    return ($item->{'itemnumber'},$error);
2114
}
2114
}
2115
2115
2116
- 
2117
--
2118
C4/Biblio.pm                          |   33 +++++++++++++++++++++++++++++++++
2116
C4/Biblio.pm                          |   33 +++++++++++++++++++++++++++++++++
2119
cataloguing/additem.pl                |    3 ++-
2117
cataloguing/additem.pl                |    3 ++-
2120
misc/migration_tools/rebuild_zebra.pl |   24 +++++++++++-------------
2118
misc/migration_tools/rebuild_zebra.pl |   24 +++++++++++-------------
2121
3 files changed, 46 insertions(+), 14 deletions(-)
2119
3 files changed, 46 insertions(+), 14 deletions(-)
(-)a/C4/Biblio.pm (+33 lines)
Lines 2-7 package C4::Biblio; Link Here
2
2
3
# Copyright 2000-2002 Katipo Communications
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2010 BibLibre
4
# Copyright 2010 BibLibre
5
# Copyright 2011 Equinox Software, Inc.
5
#
6
#
6
# This file is part of Koha.
7
# This file is part of Koha.
7
#
8
#
Lines 35-40 use C4::ClassSource; Link Here
35
use C4::Charset;
36
use C4::Charset;
36
require C4::Heading;
37
require C4::Heading;
37
require C4::Serials;
38
require C4::Serials;
39
require C4::Items;
38
40
39
use vars qw($VERSION @ISA @EXPORT);
41
use vars qw($VERSION @ISA @EXPORT);
40
42
Lines 2564-2569 sub GetNoZebraIndexes { Link Here
2564
    return %indexes;
2566
    return %indexes;
2565
}
2567
}
2566
2568
2569
=head2 EmbedItemsInMarcBiblio
2570
2571
    EmbedItemsInMarcBiblio($marc, $biblionumber);
2572
2573
Given a MARC::Record object containing a bib record,
2574
modify it to include the items attached to it as 9XX
2575
per the bib's MARC framework.
2576
2577
=cut
2578
2579
sub EmbedItemsInMarcBiblio {
2580
    my ($marc, $biblionumber) = @_;
2581
2582
    my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField('items.itemnumber', GetFrameworkCode($biblionumber));
2583
    # delete any fields already in the record that use the item tag
2584
    foreach my $field ( $marc->field($itemtag) ) {
2585
        $marc->delete_field($field);
2586
    }
2587
2588
    # ... and embed the current items
2589
    my $dbh = C4::Context->dbh;
2590
    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
2591
    $sth->execute($biblionumber);
2592
    my @item_fields;
2593
    while (my ($itemnumber) = $sth->fetchrow_array) {
2594
        my $item_marc = C4::Items::GetMarcItem($biblionumber, $itemnumber);
2595
        push @item_fields, $item_marc->field($itemtag);
2596
    }
2597
    $marc->insert_fields_ordered(@item_fields);
2598
}
2599
2567
=head1 INTERNAL FUNCTIONS
2600
=head1 INTERNAL FUNCTIONS
2568
2601
2569
=head2 _DelBiblioNoZebra($biblionumber,$record,$server);
2602
=head2 _DelBiblioNoZebra($biblionumber,$record,$server);
(-)a/cataloguing/additem.pl (-1 / +2 lines)
Lines 494-506 if ($op eq "additem") { Link Here
494
494
495
# now, build existiing item list
495
# now, build existiing item list
496
my $temp = GetMarcBiblio( $biblionumber );
496
my $temp = GetMarcBiblio( $biblionumber );
497
my @fields = $temp->fields();
498
#my @fields = $record->fields();
497
#my @fields = $record->fields();
499
my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
498
my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
500
my @big_array;
499
my @big_array;
501
#---- finds where items.itemnumber is stored
500
#---- finds where items.itemnumber is stored
502
my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode);
501
my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", $frameworkcode);
503
my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode);
502
my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", $frameworkcode);
503
C4::Biblio::EmbedItemsInMarcBiblio($temp, $biblionumber);
504
my @fields = $temp->fields();
504
505
505
foreach my $field (@fields) {
506
foreach my $field (@fields) {
506
    next if ( $field->tag() < 10 );
507
    next if ( $field->tag() < 10 );
(-)a/misc/migration_tools/rebuild_zebra.pl (-15 / +11 lines)
Lines 320-345 sub export_marc_records_from_sth { Link Here
320
                          ? GetXmlBiblio( $record_number )
320
                          ? GetXmlBiblio( $record_number )
321
                          : GetAuthorityXML( $record_number );
321
                          : GetAuthorityXML( $record_number );
322
            if ($record_type eq 'biblio'){
322
            if ($record_type eq 'biblio'){
323
                #CALL  sub ProcessItems
323
                my @items = GetItemsInfo($record_number, 'intra');
324
                my @items=GetItemsInfo($record_number,'intra',30);
325
                if (@items){
324
                if (@items){
326
                    my $record=MARC::Record->new;
325
                    my $record = MARC::Record->new;
327
                    my @itemsrecord;
326
                    my @itemsrecord;
328
                    foreach my $item (@items){
327
                    foreach my $item (@items){
329
                        my $record=Item2Marc($item, $record_number);                        
328
                        my $record = Item2Marc($item, $record_number);                        
330
                        push @itemsrecord, $record->field($itemtag);
329
                        push @itemsrecord, $record->field($itemtag);
331
                        #if xml then print itemfield as xml
332
                        # and update marcxml
333
                        # else push field
334
                    }
330
                    }
335
                    $record->insert_fields_ordered(@itemsrecord);
331
                    $record->insert_fields_ordered(@itemsrecord);
336
                    my $itemsxml=$record->as_xml_record();
332
                    my $itemsxml=$record->as_xml_record();
337
                    my $searchstring='<record>\n';
333
                    my $searchstring = '<record>\n';
338
                    my $index=index($itemsxml,'<record>\n',0);
334
                    my $index = index($itemsxml, '<record>\n', 0);
339
                    $itemsxml=substr($itemsxml,$index+length($searchstring));
335
                    $itemsxml = substr($itemsxml, $index + length($searchstring));
340
                    $searchstring='</record>';
336
                    $searchstring = '</record>';
341
                    $marcxml=substr($marcxml,0,index($marcxml,$searchstring));
337
                    $marcxml = substr($marcxml, 0, index($marcxml, $searchstring));
342
                    $marcxml.=$itemsxml;
338
                    $marcxml .= $itemsxml;
343
                }
339
                }
344
            }
340
            }
345
            if ( $marcxml ) {
341
            if ( $marcxml ) {
Lines 469-474 sub get_raw_marc_record { Link Here
469
                return;
465
                return;
470
            }
466
            }
471
        }
467
        }
468
        # ITEM
469
        C4::Biblio::EmbedItemsInMarcBiblio($marc, $record_number);
472
    } else {
470
    } else {
473
        eval { $marc = GetAuthority($record_number); };
471
        eval { $marc = GetAuthority($record_number); };
474
        if ($@) {
472
        if ($@) {
475
- 
476
 change to an item record
473
 change to an item record
477
--
478
C4/Items.pm |   11 ++---------
474
C4/Items.pm |   11 ++---------
479
1 files changed, 2 insertions(+), 9 deletions(-)
475
1 files changed, 2 insertions(+), 9 deletions(-)
(-)a/C4/Items.pm (-11 / +2 lines)
Lines 33-38 use C4::Branch; Link Here
33
require C4::Reserves;
33
require C4::Reserves;
34
use C4::Charset;
34
use C4::Charset;
35
use C4::Acquisition;
35
use C4::Acquisition;
36
use Data::Dumper;
36
37
37
use vars qw($VERSION @ISA @EXPORT);
38
use vars qw($VERSION @ISA @EXPORT);
38
39
Lines 509-523 sub ModItem { Link Here
509
    my $whole_item = GetItem($itemnumber) or die "FAILED GetItem($itemnumber)";
510
    my $whole_item = GetItem($itemnumber) or die "FAILED GetItem($itemnumber)";
510
    ModZebra( $whole_item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
511
    ModZebra( $whole_item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
511
512
512
    unless (defined $unlinked_item_subfields) {
513
    logaction("CATALOGUING", "MODIFY", $itemnumber, Dumper($item)) if C4::Context->preference("CataloguingLog");
513
        $unlinked_item_subfields = _parse_unlinked_item_subfields_from_xml($whole_item->{'more_subfields_xml'});
514
    }
515
    my $new_item_marc = _marc_from_item_hash($whole_item, $frameworkcode, $unlinked_item_subfields) 
516
        or die "FAILED _marc_from_item_hash($whole_item, $frameworkcode)";
517
    
518
    #_replace_item_field_in_biblio($new_item_marc, $biblionumber, $itemnumber, $frameworkcode);
519
	($new_item_marc       eq '0') and die "$new_item_marc is '0', not hashref";  # logaction line would crash anyway
520
    logaction("CATALOGUING", "MODIFY", $itemnumber, $new_item_marc->as_formatted) if C4::Context->preference("CataloguingLog");
521
}
514
}
522
515
523
=head2 ModItemTransfer
516
=head2 ModItemTransfer
524
- 
525
--
526
misc/maintenance/sync_items_in_marc_bib.pl |  151 ----------------------------
517
misc/maintenance/sync_items_in_marc_bib.pl |  151 ----------------------------
527
1 files changed, 0 insertions(+), 151 deletions(-)
518
1 files changed, 0 insertions(+), 151 deletions(-)
528
delete mode 100755 misc/maintenance/sync_items_in_marc_bib.pl
519
delete mode 100755 misc/maintenance/sync_items_in_marc_bib.pl
(-)a/misc/maintenance/sync_items_in_marc_bib.pl (-153 lines)
Lines 1-151 Link Here
1
#!/usr/bin/perl
2
3
use strict;
4
#use warnings; FIXME - Bug 2505
5
BEGIN {
6
    # find Koha's Perl modules
7
    # test carefully before changing this
8
    use FindBin;
9
    eval { require "$FindBin::Bin/../kohalib.pl" };
10
}
11
12
use C4::Context;
13
use C4::Biblio;
14
use C4::Items;
15
use Getopt::Long;
16
17
$| = 1;
18
19
# command-line parameters
20
my $want_help = 0;
21
my $do_update = 0;
22
my $wherestrings;
23
24
my $result = GetOptions(
25
    'run-update'    => \$do_update,
26
    'where=s@'         => \$wherestrings,
27
    'h|help'        => \$want_help,
28
);
29
30
if (not $result or $want_help or not $do_update) {
31
    print_usage();
32
    exit 0;
33
}
34
35
my $num_bibs_processed     = 0;
36
my $num_bibs_modified      = 0;
37
my $num_marc_items_deleted = 0;
38
my $num_marc_items_added   = 0;
39
my $num_bad_bibs           = 0;
40
my $dbh = C4::Context->dbh;
41
$dbh->{AutoCommit} = 0;
42
43
our ($itemtag, $itemsubfield) = GetMarcFromKohaField("items.itemnumber", '');
44
our ($item_sth) = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
45
46
process_bibs();
47
$dbh->commit();
48
49
exit 0;
50
51
sub process_bibs {
52
    my $sql = "SELECT biblionumber FROM biblio JOIN biblioitems USING (biblionumber)";
53
    $sql.="WHERE ". join(" AND ",@$wherestrings) if ($wherestrings);
54
    $sql.="ORDER BY biblionumber ASC";
55
    my $sth = $dbh->prepare($sql);
56
    eval{$sth->execute();};
57
    if ($@){ die "error $@";};
58
    while (my ($biblionumber) = $sth->fetchrow_array()) {
59
        $num_bibs_processed++;
60
        process_bib($biblionumber);
61
62
        if (($num_bibs_processed % 100) == 0) {
63
            print_progress_and_commit($num_bibs_processed);
64
        }
65
    }
66
67
    $dbh->commit;
68
69
    print <<_SUMMARY_;
70
71
Embedded item synchronization report
72
------------------------------------
73
Number of bibs checked:                   $num_bibs_processed
74
Number of bibs modified:                  $num_bibs_modified
75
Number of item fields removed from bibs:  $num_marc_items_deleted
76
Number of item fields added to bibs:      $num_marc_items_added
77
Number of bibs with errors:               $num_bad_bibs
78
_SUMMARY_
79
}
80
81
sub process_bib {
82
    my $biblionumber = shift;
83
84
    my $bib = GetMarcBiblio($biblionumber);
85
    unless (defined $bib) {
86
        print "\nCould not retrieve bib $biblionumber from the database - record is corrupt.\n";
87
        $num_bad_bibs++;
88
        return;
89
    }
90
91
    my $bib_modified = 0;
92
93
    # delete any item tags
94
    foreach my $field ($bib->field($itemtag)) {
95
        unless ($bib->delete_field($field)) {
96
            warn "Could not delete item in $itemtag for biblionumber $biblionumber";
97
            next;
98
        }
99
        $num_marc_items_deleted++;
100
        $bib_modified = 1;
101
    }
102
103
    # add back items from items table
104
    $item_sth->execute($biblionumber);
105
    while (my $itemnumber = $item_sth->fetchrow_array) {
106
        my $marc_item = C4::Items::GetMarcItem($biblionumber, $itemnumber);
107
        unless ($marc_item) {
108
            warn "FAILED C4::Items::GetMarcItem for biblionumber=$biblionumber, itemnumber=$itemnumber";
109
            next;
110
        }
111
        foreach my $item_field ($marc_item->field($itemtag)) {
112
            $bib->insert_fields_ordered($item_field);
113
            $num_marc_items_added++;
114
            $bib_modified = 1;
115
        }
116
    }
117
118
    if ($bib_modified) {
119
        ModBiblioMarc($bib, $biblionumber, GetFrameworkCode($biblionumber));
120
        $num_bibs_modified++;
121
    }
122
123
}
124
125
sub print_progress_and_commit {
126
    my $recs = shift;
127
    $dbh->commit();
128
    print "... processed $recs records\n";
129
}
130
131
sub print_usage {
132
    print <<_USAGE_;
133
$0: synchronize item data embedded in MARC bibs
134
135
Replaces the item data embedded in the MARC bib 
136
records (for indexing) with the authoritative 
137
item data as stored in the items table.
138
139
If Zebra is used, run rebuild_zebra.pl -b -r after
140
running this script.
141
142
NOTE: this script should be run only if there is
143
reason to suspect that the embedded item tags are
144
not in sync with the items table.
145
146
Parameters:
147
    --run-update            run the synchronization
148
    --where condition       selects the biblios on a criterium (Repeatable)
149
    --help or -h            show this message.
150
_USAGE_
151
}
152
- 
153
--
154
C4/Items.pm |   71 ++--------------------------------------------------------
0
C4/Items.pm |   71 ++--------------------------------------------------------
155
1 files changed, 3 insertions(+), 68 deletions(-)
1
1 files changed, 3 insertions(+), 68 deletions(-)
(-)a/C4/Items.pm (-70 / +3 lines)
Lines 261-269 sub AddItem { Link Here
261
	my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} );
261
	my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} );
262
    $item->{'itemnumber'} = $itemnumber;
262
    $item->{'itemnumber'} = $itemnumber;
263
263
264
    # create MARC tag representing item and add to bib
265
    #my $new_item_marc = _marc_from_item_hash($item, $frameworkcode, $unlinked_item_subfields);
266
    #_add_item_field_to_biblio($new_item_marc, $item->{'biblionumber'}, $frameworkcode );
267
    ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
264
    ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
268
   
265
   
269
    logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
266
    logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
Lines 506-514 sub ModItem { Link Here
506
    # update items table
503
    # update items table
507
    _koha_modify_item($item);
504
    _koha_modify_item($item);
508
505
509
    # update biblio MARC XML
506
    # request that bib be reindexed so that searching on current
510
    my $whole_item = GetItem($itemnumber) or die "FAILED GetItem($itemnumber)";
507
    # item status is possible
511
    ModZebra( $whole_item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
508
    ModZebra( $biblionumber, "specialUpdate", "biblioserver", undef, undef );
512
509
513
    logaction("CATALOGUING", "MODIFY", $itemnumber, Dumper($item)) if C4::Context->preference("CataloguingLog");
510
    logaction("CATALOGUING", "MODIFY", $itemnumber, Dumper($item)) if C4::Context->preference("CataloguingLog");
514
}
511
}
Lines 2187-2254 sub _marc_from_item_hash { Link Here
2187
    return $item_marc;
2184
    return $item_marc;
2188
}
2185
}
2189
2186
2190
=head2 _add_item_field_to_biblio
2191
2192
  _add_item_field_to_biblio($item_marc, $biblionumber, $frameworkcode);
2193
2194
Adds the fields from a MARC record containing the
2195
representation of a Koha item record to the MARC
2196
biblio record.  The input C<$item_marc> record
2197
is expect to contain just one field, the embedded
2198
item information field.
2199
2200
=cut
2201
2202
sub _add_item_field_to_biblio {
2203
    my ($item_marc, $biblionumber, $frameworkcode) = @_;
2204
2205
    my $biblio_marc = GetMarcBiblio($biblionumber);
2206
    foreach my $field ($item_marc->fields()) {
2207
        $biblio_marc->append_fields($field);
2208
    }
2209
2210
    ModBiblioMarc($biblio_marc, $biblionumber, $frameworkcode);
2211
}
2212
2213
=head2 _replace_item_field_in_biblio
2214
2215
  &_replace_item_field_in_biblio($item_marc, $biblionumber, $itemnumber, $frameworkcode)
2216
2217
Given a MARC::Record C<$item_marc> containing one tag with the MARC 
2218
representation of the item, examine the biblio MARC
2219
for the corresponding tag for that item and 
2220
replace it with the tag from C<$item_marc>.
2221
2222
=cut
2223
2224
sub _replace_item_field_in_biblio {
2225
    my ($ItemRecord, $biblionumber, $itemnumber, $frameworkcode) = @_;
2226
    my $dbh = C4::Context->dbh;
2227
    
2228
    # get complete MARC record & replace the item field by the new one
2229
    my $completeRecord = GetMarcBiblio($biblionumber);
2230
    my ($itemtag,$itemsubfield) = GetMarcFromKohaField("items.itemnumber",$frameworkcode);
2231
    my $itemField = $ItemRecord->field($itemtag);
2232
    my @items = $completeRecord->field($itemtag);
2233
    my $found = 0;
2234
    foreach (@items) {
2235
        if ($_->subfield($itemsubfield) eq $itemnumber) {
2236
            $_->replace_with($itemField);
2237
            $found = 1;
2238
        }
2239
    }
2240
  
2241
    unless ($found) { 
2242
        # If we haven't found the matching field,
2243
        # just add it.  However, this means that
2244
        # there is likely a bug.
2245
        $completeRecord->append_fields($itemField);
2246
    }
2247
2248
    # save the record
2249
    #ModBiblioMarc($completeRecord, $biblionumber, $frameworkcode);
2250
}
2251
2252
=head2 _repack_item_errors
2187
=head2 _repack_item_errors
2253
2188
2254
Add an error message hash generated by C<CheckItemPreSave>
2189
Add an error message hash generated by C<CheckItemPreSave>
2255
- 
2256
--
2257
tools/export.pl |    5 +++--
2190
tools/export.pl |    5 +++--
2258
1 files changed, 3 insertions(+), 2 deletions(-)
2191
1 files changed, 3 insertions(+), 2 deletions(-)
(-)a/tools/export.pl (-4 / +3 lines)
Lines 133-145 if ($op eq "export") { Link Here
133
            next;
133
            next;
134
        }
134
        }
135
        next if not defined $record;
135
        next if not defined $record;
136
        if ( $dont_export_items || $strip_nonlocal_items || $limit_ind_branch) {
136
        C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) unless $dont_export_items;
137
        if ($strip_nonlocal_items || $limit_ind_branch) {
137
            my ( $homebranchfield, $homebranchsubfield ) =
138
            my ( $homebranchfield, $homebranchsubfield ) =
138
                GetMarcFromKohaField( 'items.homebranch', '' );
139
                GetMarcFromKohaField( 'items.homebranch', '' );
139
			for my $itemfield ($record->field($homebranchfield)){
140
			for my $itemfield ($record->field($homebranchfield)){
140
				# if stripping nonlocal items, use loggedinuser's branch if they didn't select one
141
				# if stripping nonlocal items, use loggedinuser's branch if they didn't select one
141
				$branch = C4::Context->userenv->{'branch'} unless $branch;
142
				$branch = C4::Context->userenv->{'branch'} unless $branch;
142
                $record->delete_field($itemfield) if($dont_export_items || ($itemfield->subfield($homebranchsubfield) ne $branch) ) ;
143
                $record->delete_field($itemfield) if($itemfield->subfield($homebranchsubfield) ne $branch) ;
143
            }
144
            }
144
        }
145
        }
145
        
146
        
146
- 
147
 - The following export pages used to embed items when exporting,
147
 - The following export pages used to embed items when exporting,
148
   this was no longer the case, so they were fixed :
148
   this was no longer the case, so they were fixed :
149
     Intranet :
149
     Intranet :
150
       - basket/downloadcart.pl,
150
       - basket/downloadcart.pl,
151
       - virtualshelves/downloadshelf.pl
151
       - virtualshelves/downloadshelf.pl
152
       - catalogue/export.pl
152
       - catalogue/export.pl
153
     Opac :
153
     Opac :
154
       - opac/opac-downloadcart.pl
154
       - opac/opac-downloadcart.pl
155
       - opac/opac-downloadshelf.pl
155
       - opac/opac-downloadshelf.pl
156
       - opac/opac-export.pl
156
       - opac/opac-export.pl
157
 - Notes :
157
 - Notes :
158
    - GetMarcBiblio used to embed items data, this was no longer the case,
158
    - GetMarcBiblio used to embed items data, this was no longer the case,
159
      so an optional parameter was added to choose if items should be embedded or not.
159
      so an optional parameter was added to choose if items should be embedded or not.
160
      This way, previous work on this bug is not broken, and this is a pretty usefull
160
      This way, previous work on this bug is not broken, and this is a pretty usefull
161
      feature, imho.
161
      feature, imho.
162
    - An optional parameter has been added to SetUTF8Flag, to be able to use NFD during
162
    - An optional parameter has been added to SetUTF8Flag, to be able to use NFD during
163
      normalization. This was required to make Unicode/UTF-8 export work again.
163
      normalization. This was required to make Unicode/UTF-8 export work again.
164
--
165
C4/Biblio.pm                    |    8 ++++-
164
C4/Biblio.pm                    |    8 ++++-
166
C4/Charset.pm                   |    8 +++--
165
C4/Charset.pm                   |    8 +++--
167
C4/Record.pm                    |    2 +-
166
C4/Record.pm                    |    2 +-
168
basket/downloadcart.pl          |    2 +-
167
basket/downloadcart.pl          |    2 +-
169
catalogue/export.pl             |   15 +++-------
168
catalogue/export.pl             |   15 +++-------
170
opac/opac-downloadcart.pl       |    2 +-
169
opac/opac-downloadcart.pl       |    2 +-
171
opac/opac-downloadshelf.pl      |    2 +-
170
opac/opac-downloadshelf.pl      |    2 +-
172
opac/opac-export.pl             |   56 ++++++++++++++++++--------------------
171
opac/opac-export.pl             |   56 ++++++++++++++++++--------------------
173
virtualshelves/downloadshelf.pl |    2 +-
172
virtualshelves/downloadshelf.pl |    2 +-
174
9 files changed, 48 insertions(+), 49 deletions(-)
173
9 files changed, 48 insertions(+), 49 deletions(-)
(-)a/C4/Biblio.pm (-2 / +6 lines)
Lines 1023-1038 sub GetMarcFromKohaField { Link Here
1023
1023
1024
=head2 GetMarcBiblio
1024
=head2 GetMarcBiblio
1025
1025
1026
  my $record = GetMarcBiblio($biblionumber);
1026
  my $record = GetMarcBiblio($biblionumber, [$embeditems]);
1027
1027
1028
Returns MARC::Record representing bib identified by
1028
Returns MARC::Record representing bib identified by
1029
C<$biblionumber>.  If no bib exists, returns undef.
1029
C<$biblionumber>.  If no bib exists, returns undef.
1030
The MARC record contains both biblio & item data.
1030
C<$embeditems>.  If set to true, items data are included.
1031
The MARC record contains biblio data, and items data if $embeditems is set to true.
1031
1032
1032
=cut
1033
=cut
1033
1034
1034
sub GetMarcBiblio {
1035
sub GetMarcBiblio {
1035
    my $biblionumber = shift;
1036
    my $biblionumber = shift;
1037
    my $embeditems   = shift || 0;
1036
    my $dbh          = C4::Context->dbh;
1038
    my $dbh          = C4::Context->dbh;
1037
    my $sth          = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
1039
    my $sth          = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? ");
1038
    $sth->execute($biblionumber);
1040
    $sth->execute($biblionumber);
Lines 1046-1051 sub GetMarcBiblio { Link Here
1046
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1048
        if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; }
1047
        return unless $record;
1049
        return unless $record;
1048
1050
1051
	C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems);
1052
1049
        #      $record = MARC::Record::new_from_usmarc( $marc) if $marc;
1053
        #      $record = MARC::Record::new_from_usmarc( $marc) if $marc;
1050
        return $record;
1054
        return $record;
1051
    } else {
1055
    } else {
(-)a/C4/Charset.pm (-3 / +5 lines)
Lines 112-118 sub IsStringUTF8ish { Link Here
112
112
113
=head2 SetUTF8Flag
113
=head2 SetUTF8Flag
114
114
115
  my $marc_record = SetUTF8Flag($marc_record);
115
  my $marc_record = SetUTF8Flag($marc_record, $nfd);
116
116
117
This function sets the PERL UTF8 flag for data.
117
This function sets the PERL UTF8 flag for data.
118
It is required when using new_from_usmarc 
118
It is required when using new_from_usmarc 
Lines 120-125 since MARC::File::USMARC does not handle PERL UTF8 setting. Link Here
120
When editing unicode marc records fields and subfields, you
120
When editing unicode marc records fields and subfields, you
121
would end up in double encoding without using this function. 
121
would end up in double encoding without using this function. 
122
122
123
If $nfd is set, string normalization will use NFD instead of NFC
124
123
FIXME
125
FIXME
124
In my opinion, this function belongs to MARC::Record and not
126
In my opinion, this function belongs to MARC::Record and not
125
to this package.
127
to this package.
Lines 128-140 But since it handles charset, and MARC::Record, it finds its way in that package Link Here
128
=cut
130
=cut
129
131
130
sub SetUTF8Flag{
132
sub SetUTF8Flag{
131
	my ($record)=@_;
133
	my ($record, $nfd)=@_;
132
	return unless ($record && $record->fields());
134
	return unless ($record && $record->fields());
133
	foreach my $field ($record->fields()){
135
	foreach my $field ($record->fields()){
134
		if ($field->tag()>=10){
136
		if ($field->tag()>=10){
135
			my @subfields;
137
			my @subfields;
136
			foreach my $subfield ($field->subfields()){
138
			foreach my $subfield ($field->subfields()){
137
				push @subfields,($$subfield[0],NormalizeString($$subfield[1]));
139
				push @subfields,($$subfield[0],NormalizeString($$subfield[1],$nfd));
138
			}
140
			}
139
			my $newfield=MARC::Field->new(
141
			my $newfield=MARC::Field->new(
140
							$field->tag(),
142
							$field->tag(),
(-)a/C4/Record.pm (-1 / +1 lines)
Lines 359-365 sub marcrecord2csv { Link Here
359
    my $output;
359
    my $output;
360
360
361
    # Getting the record
361
    # Getting the record
362
    my $record = GetMarcBiblio($biblio);
362
    my $record = GetMarcBiblio($biblio, 1);
363
    next unless $record;
363
    next unless $record;
364
    # Getting the framework
364
    # Getting the framework
365
    my $frameworkcode = GetFrameworkCode($biblio);
365
    my $frameworkcode = GetFrameworkCode($biblio);
(-)a/basket/downloadcart.pl (-1 / +1 lines)
Lines 65-71 if ($bib_list && $format) { Link Here
65
65
66
        foreach my $biblio (@bibs) {
66
        foreach my $biblio (@bibs) {
67
67
68
            my $record = GetMarcBiblio($biblio);
68
            my $record = GetMarcBiblio($biblio, 1);
69
69
70
            if ($format eq 'iso2709') {
70
            if ($format eq 'iso2709') {
71
                $output .= $record->as_usmarc();
71
                $output .= $record->as_usmarc();
(-)a/catalogue/export.pl (-10 / +5 lines)
Lines 15-28 my $op=$query->param("op"); Link Here
15
my $format=$query->param("format");
15
my $format=$query->param("format");
16
if ($op eq "export") {
16
if ($op eq "export") {
17
	my $biblionumber = $query->param("bib");
17
	my $biblionumber = $query->param("bib");
18
	my $dbh=C4::Context->dbh;
18
		if ($biblionumber){
19
	my $sth;
19
20
	if ($biblionumber) {
20
			my $marc = GetMarcBiblio($biblionumber, 1);
21
		$sth=$dbh->prepare("SELECT marc FROM biblioitems WHERE biblionumber =?");
22
		$sth->execute($biblionumber);
23
	}
24
	while (my ($marc) = $sth->fetchrow) {
25
		if ($marc){
26
21
27
			if ($format =~ /endnote/) {
22
			if ($format =~ /endnote/) {
28
				$marc = marc2endnote($marc);
23
				$marc = marc2endnote($marc);
Lines 44-55 if ($op eq "export") { Link Here
44
				$marc = $marc->as_usmarc();
39
				$marc = $marc->as_usmarc();
45
			}
40
			}
46
			elsif ($format =~ /utf8/) {
41
			elsif ($format =~ /utf8/) {
47
				#default
42
				C4::Charset::SetUTF8Flag($marc, 1);
43
				$marc = $marc->as_usmarc();
48
			}
44
			}
49
			print $query->header(
45
			print $query->header(
50
				-type => 'application/octet-stream',
46
				-type => 'application/octet-stream',
51
                -attachment=>"bib-$biblionumber.$format");
47
                -attachment=>"bib-$biblionumber.$format");
52
			print $marc;
48
			print $marc;
53
		}
49
		}
54
	}
55
}
50
}
(-)a/opac/opac-downloadcart.pl (-1 / +1 lines)
Lines 64-70 if ($bib_list && $format) { Link Here
64
    } else {
64
    } else {
65
        foreach my $biblio (@bibs) {
65
        foreach my $biblio (@bibs) {
66
66
67
            my $record = GetMarcBiblio($biblio);
67
            my $record = GetMarcBiblio($biblio, 1);
68
            next unless $record;
68
            next unless $record;
69
69
70
            if ($format eq 'iso2709') {
70
            if ($format eq 'iso2709') {
(-)a/opac/opac-downloadshelf.pl (-1 / +1 lines)
Lines 68-74 if ($shelfid && $format) { Link Here
68
        foreach my $biblio (@$items) {
68
        foreach my $biblio (@$items) {
69
            my $biblionumber = $biblio->{biblionumber};
69
            my $biblionumber = $biblio->{biblionumber};
70
70
71
            my $record = GetMarcBiblio($biblionumber);
71
            my $record = GetMarcBiblio($biblionumber, 1);
72
            next unless $record;
72
            next unless $record;
73
73
74
            if ($format eq 'iso2709') {
74
            if ($format eq 'iso2709') {
(-)a/opac/opac-export.pl (-29 / +27 lines)
Lines 35-49 my $op=$query->param("op"); Link Here
35
my $format=$query->param("format");
35
my $format=$query->param("format");
36
if ($op eq "export") {
36
if ($op eq "export") {
37
	my $biblionumber = $query->param("bib");
37
	my $biblionumber = $query->param("bib");
38
	my $dbh=C4::Context->dbh;
38
	my $error;
39
	my $sth;
39
40
	if ($biblionumber) {
40
		if ($biblionumber){
41
		$sth=$dbh->prepare("SELECT marc FROM biblioitems WHERE biblionumber =?");
41
42
		$sth->execute($biblionumber);
42
			my $marc = GetMarcBiblio($biblionumber, 1);
43
	}
44
    my $error;
45
	while (my ($marc) = $sth->fetchrow) {
46
		if ($marc){
47
43
48
			if ($format =~ /endnote/) {
44
			if ($format =~ /endnote/) {
49
				$marc = marc2endnote($marc);
45
				$marc = marc2endnote($marc);
Lines 60-91 if ($op eq "export") { Link Here
60
 			}
56
 			}
61
			elsif ($format =~ /bibtex/) {
57
			elsif ($format =~ /bibtex/) {
62
				$marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber);
58
				$marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber);
63
			}elsif ($format =~ /dc/) {
59
			}
64
                ($error,$marc) = marc2dcxml($marc,1);
60
			elsif ($format =~ /dc/) {
61
				($error,$marc) = marc2dcxml($marc,1);
65
				$format = "dublin-core.xml";
62
				$format = "dublin-core.xml";
66
			}
63
			}
67
			elsif ($format =~ /marc8/) {
64
			elsif ($format =~ /marc8/) {
68
				($error,$marc) = changeEncoding($marc,"MARC","MARC21","MARC-8");
65
				($error,$marc) = changeEncoding($marc,"MARC","MARC21","MARC-8");
69
                if (! $error){
66
				if (! $error){
70
                    $marc = $marc->as_usmarc();
67
				    $marc = $marc->as_usmarc();
71
                }
68
				}
72
			}
69
			}
73
			elsif ($format =~ /utf8/) {
70
			elsif ($format =~ /utf8/) {
74
				#default
71
				C4::Charset::SetUTF8Flag($marc,1);
72
				$marc = $marc->as_usmarc();
75
			}
73
			}
76
            if ($error){
74
77
                print $query->header();
75
		if ($error){
78
                print $query->start_html();
76
		    print $query->header();
79
                print "<h1>An error occured </h1>";
77
		    print $query->start_html();
80
                print $error;
78
		    print "<h1>An error occured </h1>";
81
                print $query->end_html();
79
		    print $error;
82
            }
80
		    print $query->end_html();
83
            else {
81
		}
84
                print $query->header(
82
		else {
85
				-type => 'application/octet-stream',
83
		    print $query->header(
86
                -attachment=>"bib-$biblionumber.$format");
84
				    -type => 'application/octet-stream',
87
                print $marc;
85
		    -attachment=>"bib-$biblionumber.$format");
88
            }
86
		    print $marc;
89
		}
87
		}
90
	}
88
	    }
91
}
89
}
(-)a/virtualshelves/downloadshelf.pl (-3 / +1 lines)
Lines 68-74 if ($shelfid && $format) { Link Here
68
    foreach my $biblio (@$items) {
68
    foreach my $biblio (@$items) {
69
        my $biblionumber = $biblio->{biblionumber};
69
        my $biblionumber = $biblio->{biblionumber};
70
70
71
        my $record = GetMarcBiblio($biblionumber);
71
        my $record = GetMarcBiblio($biblionumber, 1);
72
72
73
        if ($format eq 'iso2709') {
73
        if ($format eq 'iso2709') {
74
            $output .= $record->as_usmarc();
74
            $output .= $record->as_usmarc();
75
- 
76
--
77
C4/Biblio.pm |    2 +-
75
C4/Biblio.pm |    2 +-
78
1 files changed, 1 insertions(+), 1 deletions(-)
76
1 files changed, 1 insertions(+), 1 deletions(-)
(-)a/C4/Biblio.pm (-2 / +1 lines)
Lines 737-743 Return the ISBD view which can be included in opac and intranet Link Here
737
737
738
sub GetISBDView {
738
sub GetISBDView {
739
    my ( $biblionumber, $template ) = @_;
739
    my ( $biblionumber, $template ) = @_;
740
    my $record   = GetMarcBiblio($biblionumber);
740
    my $record   = GetMarcBiblio($biblionumber, 1);
741
    my $itemtype = &GetFrameworkCode($biblionumber);
741
    my $itemtype = &GetFrameworkCode($biblionumber);
742
    my ( $holdingbrtagf, $holdingbrtagsubf ) = &GetMarcFromKohaField( "items.holdingbranch", $itemtype );
742
    my ( $holdingbrtagf, $holdingbrtagsubf ) = &GetMarcFromKohaField( "items.holdingbranch", $itemtype );
743
    my $tagslib = &GetMarcStructure( 1, $itemtype );
743
    my $tagslib = &GetMarcStructure( 1, $itemtype );
744
- 

Return to bug 5579