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

(-)a/C4/Items.pm (-34 / +49 lines)
Lines 442-479 Returns item record Link Here
442
442
443
=cut
443
=cut
444
444
445
my %default_values_for_mod_from_marc = (
445
our %default_values_for_mod_from_marc;
446
# DO NOT include (internal) item fields here.
446
447
# Only fields that are related to the MARC structure used in additem.pl
447
sub _build_default_values_for_mod_marc {
448
# Bug 7817 removed permanent_location.
448
    my ($frameworkcode) = @_;
449
    barcode              => undef, 
449
    return $default_values_for_mod_from_marc{$frameworkcode}
450
    booksellerid         => undef, 
450
      if exists $default_values_for_mod_from_marc{$frameworkcode};
451
    ccode                => undef, 
451
    my $marc_structure = C4::Biblio::GetMarcStructure( 1, $frameworkcode );
452
    'items.cn_source'    => undef, 
452
    my $default_values = {
453
    coded_location_qualifier => undef,
453
        barcode                  => undef,
454
    copynumber           => undef, 
454
        booksellerid             => undef,
455
    damaged              => 0,
455
        ccode                    => undef,
456
#    dateaccessioned      => undef,
456
        'items.cn_source'        => undef,
457
    enumchron            => undef, 
457
        coded_location_qualifier => undef,
458
    holdingbranch        => undef, 
458
        copynumber               => undef,
459
    homebranch           => undef, 
459
        damaged                  => 0,
460
    itemcallnumber       => undef, 
460
        enumchron                => undef,
461
    itemlost             => 0,
461
        holdingbranch            => undef,
462
    itemnotes            => undef, 
462
        homebranch               => undef,
463
    itype                => undef, 
463
        itemcallnumber           => undef,
464
    location             => undef, 
464
        itemlost                 => 0,
465
    materials            => undef, 
465
        itemnotes                => undef,
466
    notforloan           => 0,
466
        itype                    => undef,
467
    paidfor              => undef,  # should not be here: see BZ 12817
467
        location                 => undef,
468
    price                => undef, 
468
        permanent_location       => undef,
469
    replacementprice     => undef, 
469
        materials                => undef,
470
    replacementpricedate => undef, 
470
        notforloan               => 0,
471
    restricted           => undef, 
471
        # paidfor => undef, # commented, see bug 12817
472
    stack                => undef, 
472
        price                    => undef,
473
    stocknumber          => undef, 
473
        replacementprice         => undef,
474
    uri                  => undef, 
474
        replacementpricedate     => undef,
475
    withdrawn             => 0,
475
        restricted               => undef,
476
);
476
        stack                    => undef,
477
        stocknumber              => undef,
478
        uri                      => undef,
479
        withdrawn                => 0,
480
    };
481
    while ( my ( $field, $default_value ) = each %$default_values ) {
482
        $field =~ s|[^\.]*\.?(.*)|items.$1|;
483
        $default_values_for_mod_from_marc{$frameworkcode}{$field} =
484
          $default_value
485
          if C4::Koha::IsKohaFieldLinked(
486
            { kohafield => $field, frameworkcode => $frameworkcode } );
487
    }
488
    return $default_values_for_mod_from_marc{$frameworkcode};
489
}
477
490
478
sub ModItemFromMarc {
491
sub ModItemFromMarc {
479
    my $item_marc = shift;
492
    my $item_marc = shift;
Lines 487-494 sub ModItemFromMarc { Link Here
487
    my $localitemmarc = MARC::Record->new;
500
    my $localitemmarc = MARC::Record->new;
488
    $localitemmarc->append_fields( $item_marc->field($itemtag) );
501
    $localitemmarc->append_fields( $item_marc->field($itemtag) );
489
    my $item = &TransformMarcToKoha( $dbh, $localitemmarc, $frameworkcode, 'items' );
502
    my $item = &TransformMarcToKoha( $dbh, $localitemmarc, $frameworkcode, 'items' );
490
    foreach my $item_field ( keys %default_values_for_mod_from_marc ) {
503
    my $default_values = _build_default_values_for_mod_marc();
491
        $item->{$item_field} = $default_values_for_mod_from_marc{$item_field} unless (exists $item->{$item_field});
504
    foreach my $item_field ( keys %$default_values ) {
505
        $item->{$item_field} = $default_values->{$item_field}
506
          unless exists $item->{$item_field};
492
    }
507
    }
493
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
508
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
494
509
(-)a/C4/Koha.pm (+25 lines)
Lines 1722-1727 sub GetVariationsOfISBNs { Link Here
1722
    return wantarray ? @isbns : join( " | ", @isbns );
1722
    return wantarray ? @isbns : join( " | ", @isbns );
1723
}
1723
}
1724
1724
1725
=head2 IsKohaFieldLinked
1726
1727
    my $is_linked = IsKohaFieldLinked({
1728
        kohafield => $kohafield,
1729
        frameworkcode => $frameworkcode,
1730
    });
1731
1732
    Return 1 if the field is linked
1733
1734
=cut
1735
1736
sub IsKohaFieldLinked {
1737
    my ( $params ) = @_;
1738
    my $kohafield = $params->{kohafield};
1739
    my $frameworkcode = $params->{frameworkcode} || '';
1740
    my $dbh = C4::Context->dbh;
1741
    my $is_linked = $dbh->selectcol_arrayref( q|
1742
        SELECT COUNT(*)
1743
        FROM marc_subfield_structure
1744
        WHERE frameworkcode = ?
1745
        AND kohafield = ?
1746
    |,{}, $frameworkcode, $kohafield );
1747
    return $is_linked->[0];
1748
}
1749
1725
1;
1750
1;
1726
1751
1727
__END__
1752
__END__
(-)a/t/db_dependent/Koha/IsKohaFieldLinked.t (-1 / +44 lines)
Line 0 Link Here
0
- 
1
use Modern::Perl;
2
use Test::More;
3
4
use C4::Context;
5
use C4::Koha;
6
7
my $dbh = C4::Context->dbh;
8
$dbh->{RaiseError} = 1;
9
$dbh->{AutoCommit} = 0;
10
11
my $frameworkcode = 'FCUT';
12
$dbh->do( qq|
13
    INSERT INTO marc_subfield_structure(
14
        tagfield, tagsubfield, liblibrarian, kohafield, frameworkcode
15
    ) VALUES
16
        ('952', 'p', 'Barcode', 'items.barcode', '$frameworkcode'),
17
        ('952', '8', 'Collection code', 'items.ccode', '$frameworkcode'),
18
        ('952', '7', 'Not for loan', 'items.notforloan', '$frameworkcode'),
19
        ('952', 'y', 'Koha item type', 'items.itype', '$frameworkcode'),
20
        ('952', 'c', 'Permanent location', '', '$frameworkcode')
21
|);
22
23
is ( C4::Koha::IsKohaFieldLinked( {
24
    kohafield => 'items.barcode',
25
    frameworkcode => $frameworkcode,
26
}), 1, 'items.barcode is linked' );
27
28
is ( C4::Koha::IsKohaFieldLinked( {
29
    kohafield => 'items.notforloan',
30
    frameworkcode => $frameworkcode,
31
}), 1, 'items.notforloan is linked' );
32
33
is ( C4::Koha::IsKohaFieldLinked( {
34
    kohafield => 'notforloan',
35
    frameworkcode => $frameworkcode,
36
}), 0, 'notforloan is not linked' );
37
38
is ( C4::Koha::IsKohaFieldLinked( {
39
    kohafield => 'items.permanent_location',
40
    frameworkcode => $frameworkcode,
41
}), 0, 'items.permanent_location is not linked' );
42
43
44
done_testing;

Return to bug 12874