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

(-)a/C4/Biblio.pm (-88 / +112 lines)
Lines 2926-3041 sub prepare_host_field { Link Here
2926
2926
2927
    my $biblio = Koha::Biblios->find($hostbiblio);
2927
    my $biblio = Koha::Biblios->find($hostbiblio);
2928
    my $host = $biblio->metadata->record;
2928
    my $host = $biblio->metadata->record;
2929
    my $prepared_host_field = C4::Context->yaml_preference('PrepareHostField') || q{};
2929
    # unfortunately as_string does not 'do the right thing'
2930
    # unfortunately as_string does not 'do the right thing'
2930
    # if field returns undef
2931
    # if field returns undef
2931
    my %sfd;
2932
    my %sfd;
2932
    my $field;
2933
    my $field;
2933
    my $host_field;
2934
    my $host_field;
2934
    if ( $marcflavour eq 'MARC21' ) {
2935
    if ( $prepared_host_field ) {
2935
        if ( $field = $host->field('100') || $host->field('110') || $host->field('11') ) {
2936
        foreach my $key (keys %$prepared_host_field) {
2936
            my $s = $field->as_string('ab');
2937
            my ($tag, $subfields) = split(/\$/, $key);
2937
            if ($s) {
2938
            my ($part_field, $part_subfield) = split(/\$/, $prepared_host_field->{$key});
2938
                $sfd{a} = $s;
2939
            my $field = $host->field($tag);
2940
            if ( $field ) {
2941
                if ($field->is_control_field) {
2942
                    $sfd{$part_subfield} = $field->data();
2943
                } else {
2944
                    my $s = $field->as_string($subfields);
2945
                    if ($s) {
2946
                        $sfd{$part_subfield} = $s;
2947
                    }
2948
                }
2939
            }
2949
            }
2940
        }
2950
            if (%sfd) {
2941
        if ( $field = $host->field('245') ) {
2951
                $host_field = MARC::Field->new( $part_field, '0', ' ', %sfd );
2942
            my $s = $field->as_string('a');
2943
            if ($s) {
2944
                $sfd{t} = $s;
2945
            }
2952
            }
2946
        }
2953
        }
2947
        if ( $field = $host->field('260') ) {
2954
2948
            my $s = $field->as_string('abc');
2955
        return $host_field;
2949
            if ($s) {
2956
    } else {
2950
                $sfd{d} = $s;
2957
        if ( $marcflavour eq 'MARC21' ) {
2958
            if ( $field = $host->field('100') || $host->field('110') || $host->field('11') ) {
2959
                my $s = $field->as_string('ab');
2960
                if ($s) {
2961
                    $sfd{a} = $s;
2962
                }
2951
            }
2963
            }
2952
        }
2964
            if ( $field = $host->field('245') ) {
2953
        if ( $field = $host->field('240') ) {
2965
                my $s = $field->as_string('a');
2954
            my $s = $field->as_string();
2966
                if ($s) {
2955
            if ($s) {
2967
                    $sfd{t} = $s;
2956
                $sfd{b} = $s;
2968
                }
2957
            }
2969
            }
2958
        }
2970
            if ( $field = $host->field('260') ) {
2959
        if ( $field = $host->field('022') ) {
2971
                my $s = $field->as_string('abc');
2960
            my $s = $field->as_string('a');
2972
                if ($s) {
2961
            if ($s) {
2973
                    $sfd{d} = $s;
2962
                $sfd{x} = $s;
2974
                }
2963
            }
2975
            }
2964
        }
2976
            if ( $field = $host->field('240') ) {
2965
        if ( $field = $host->field('020') ) {
2977
                my $s = $field->as_string();
2966
            my $s = $field->as_string('a');
2978
                if ($s) {
2967
            if ($s) {
2979
                    $sfd{b} = $s;
2968
                $sfd{z} = $s;
2980
                }
2969
            }
2981
            }
2970
        }
2982
            if ( $field = $host->field('022') ) {
2971
        if ( $field = $host->field('001') ) {
2983
                my $s = $field->as_string('a');
2972
            $sfd{w} = $field->data(),;
2984
                if ($s) {
2973
        }
2985
                    $sfd{x} = $s;
2974
        $host_field = MARC::Field->new( 773, '0', ' ', %sfd );
2986
                }
2975
        return $host_field;
2976
    }
2977
    elsif ( $marcflavour eq 'UNIMARC' ) {
2978
        #author
2979
        if ( $field = $host->field('700') || $host->field('710') || $host->field('720') ) {
2980
            my $s = $field->as_string('ab');
2981
            if ($s) {
2982
                $sfd{a} = $s;
2983
            }
2987
            }
2984
        }
2988
            if ( $field = $host->field('020') ) {
2985
        #title
2989
                my $s = $field->as_string('a');
2986
        if ( $field = $host->field('200') ) {
2990
                if ($s) {
2987
            my $s = $field->as_string('a');
2991
                    $sfd{z} = $s;
2988
            if ($s) {
2992
                }
2989
                $sfd{t} = $s;
2990
            }
2993
            }
2991
        }
2994
            if ( $field = $host->field('001') ) {
2992
        #place of publicaton
2995
                $sfd{w} = $field->data(),;
2993
        if ( $field = $host->field('210') ) {
2994
            my $s = $field->as_string('a');
2995
            if ($s) {
2996
                $sfd{c} = $s;
2997
            }
2996
            }
2997
            $host_field = MARC::Field->new( 773, '0', ' ', %sfd );
2998
            return $host_field;
2998
        }
2999
        }
2999
        #date of publication
3000
        elsif ( $marcflavour eq 'UNIMARC' ) {
3000
        if ( $field = $host->field('210') ) {
3001
            #author
3001
            my $s = $field->as_string('d');
3002
            if ( $field = $host->field('700') || $host->field('710') || $host->field('720') ) {
3002
            if ($s) {
3003
                my $s = $field->as_string('ab');
3003
                $sfd{d} = $s;
3004
                if ($s) {
3005
                    $sfd{a} = $s;
3006
                }
3004
            }
3007
            }
3005
        }
3008
            #title
3006
        #edition statement
3009
            if ( $field = $host->field('200') ) {
3007
        if ( $field = $host->field('205') ) {
3010
                my $s = $field->as_string('a');
3008
            my $s = $field->as_string();
3011
                if ($s) {
3009
            if ($s) {
3012
                    $sfd{t} = $s;
3010
                $sfd{e} = $s;
3013
                }
3011
            }
3014
            }
3012
        }
3015
            #place of publicaton
3013
        #URL
3016
            if ( $field = $host->field('210') ) {
3014
        if ( $field = $host->field('856') ) {
3017
                my $s = $field->as_string('a');
3015
            my $s = $field->as_string('u');
3018
                if ($s) {
3016
            if ($s) {
3019
                    $sfd{c} = $s;
3017
                $sfd{u} = $s;
3020
                }
3018
            }
3021
            }
3019
        }
3022
            #date of publication
3020
        #ISSN
3023
            if ( $field = $host->field('210') ) {
3021
        if ( $field = $host->field('011') ) {
3024
                my $s = $field->as_string('d');
3022
            my $s = $field->as_string('a');
3025
                if ($s) {
3023
            if ($s) {
3026
                    $sfd{d} = $s;
3024
                $sfd{x} = $s;
3027
                }
3025
            }
3028
            }
3026
        }
3029
            #edition statement
3027
        #ISBN
3030
            if ( $field = $host->field('205') ) {
3028
        if ( $field = $host->field('010') ) {
3031
                my $s = $field->as_string();
3029
            my $s = $field->as_string('a');
3032
                if ($s) {
3030
            if ($s) {
3033
                    $sfd{e} = $s;
3031
                $sfd{y} = $s;
3034
                }
3032
            }
3035
            }
3036
            #URL
3037
            if ( $field = $host->field('856') ) {
3038
                my $s = $field->as_string('u');
3039
                if ($s) {
3040
                    $sfd{u} = $s;
3041
                }
3042
            }
3043
            #ISSN
3044
            if ( $field = $host->field('011') ) {
3045
                my $s = $field->as_string('a');
3046
                if ($s) {
3047
                    $sfd{x} = $s;
3048
                }
3049
            }
3050
            #ISBN
3051
            if ( $field = $host->field('010') ) {
3052
                my $s = $field->as_string('a');
3053
                if ($s) {
3054
                    $sfd{y} = $s;
3055
                }
3056
            }
3057
            if ( $field = $host->field('001') ) {
3058
                $sfd{0} = $field->data(),;
3059
            }
3060
            $host_field = MARC::Field->new( 461, '0', ' ', %sfd );
3061
            return $host_field;
3033
        }
3062
        }
3034
        if ( $field = $host->field('001') ) {
3035
            $sfd{0} = $field->data(),;
3036
        }
3037
        $host_field = MARC::Field->new( 461, '0', ' ', %sfd );
3038
        return $host_field;
3039
    }
3063
    }
3040
    return;
3064
    return;
3041
}
3065
}
(-)a/installer/data/mysql/atomicupdate/bug_37061.pl (+17 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "37061",
5
    description => "Add a new system preference PrepareHostField",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        # Do you stuffs here
11
        $dbh->do(q{
12
            INSERT IGNORE INTO systempreferences (variable, value, options, type, explanation)
13
            VALUES ('PrepareHostField', '', '', 'Textarea', 'Define YAML rules for copying host data to component parts.');});
14
15
        say $out "Added new system preference 'PrepareHostField'";
16
    },
17
};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (-1 / +14 lines)
Lines 346-351 Cataloging: Link Here
346
                  dsc: descending.
346
                  dsc: descending.
347
                  az: from A to Z.
347
                  az: from A to Z.
348
                  za: from Z to A.
348
                  za: from Z to A.
349
        -
350
            - "Define rules for copying host data to component parts.<br/>"
351
            - pref: PrepareHostField
352
              type: textarea
353
              syntax: text/x-yaml
354
              class: code
355
            - "Example:<br/>"
356
            - "001: 773$w<br/>"
357
            - "020$a: 773$z<br/>"
358
            - "022$a: 773$x<br/>"
359
            - "028$ba: 773$o<br/>"
360
            - "245$abnpc: 773$t<br/>"
361
            - "264$abc: 773$d<br/>"
362
            - "300$ae: 773$h"
349
    Importing:
363
    Importing:
350
        -
364
        -
351
            - When matching on ISBN with the record import tool,
365
            - When matching on ISBN with the record import tool,
352
- 

Return to bug 37061