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

(-)a/C4/AuthoritiesMarc.pm (-1 / +81 lines)
Lines 785-790 sub ModAuthority { Link Here
785
785
786
    my $oldrecord = GetAuthority($authid);
786
    my $oldrecord = GetAuthority($authid);
787
787
788
    if ( C4::Context->preference('AutoUpdateRecordStatus') && $oldrecord ) {
789
        my $ldr_5            = substr( $record->leader,    5, 1 );
790
        my $ldr_5_before_mod = substr( $oldrecord->leader, 5, 1 );
791
        if ( $ldr_5 ne 'c' && $ldr_5 eq $ldr_5_before_mod ) {  # we update LDR/5 only if it has not been already changed
792
            _update_record_status( $record, $authid );
793
        }
794
    }
795
788
    #Now rewrite the $record to table with an add
796
    #Now rewrite the $record to table with an add
789
    $authid = AddAuthority( $record, $authid, $authtypecode, { skip_record_index => $skip_record_index } );
797
    $authid = AddAuthority( $record, $authid, $authtypecode, { skip_record_index => $skip_record_index } );
790
    merge( { mergefrom => $authid, MARCfrom => $oldrecord, mergeto => $authid, MARCto => $record } )
798
    merge( { mergefrom => $authid, MARCfrom => $oldrecord, mergeto => $authid, MARCto => $record } )
Lines 1892-1898 sub _after_authority_action_hooks { Link Here
1892
    return Koha::Plugins->call( 'after_authority_action', $args );
1900
    return Koha::Plugins->call( 'after_authority_action', $args );
1893
}
1901
}
1894
1902
1895
END { }                 # module clean-up code here (global destructor)
1903
=head2 _update_record_status
1904
1905
    _update_record_status( $record, $authid )
1906
1907
Updates LDR/5 if need
1908
1909
=cut
1910
1911
sub _update_record_status {
1912
    my ( $record, $authid ) = @_;
1913
    my $do_update_record_status;
1914
    my $marcflavour = C4::Context->preference("marcflavour");
1915
1916
    # first - check date entered on file
1917
    my $today        = POSIX::strftime( "%y%m%d", localtime );
1918
    my $date_created = '';
1919
    if ( $marcflavour eq 'MARC21' ) {
1920
        $date_created = substr( $record->field('008')->data, 0, 6 )
1921
            if $record->field('008');
1922
    } elsif ( $marcflavour eq 'UNIMARC' ) {
1923
        $date_created = substr( $record->subfield( '100', 'a' ), 2, 6 )
1924
            if $record->subfield( '100', 'a' );
1925
1926
    }
1927
    if ( $date_created && $date_created ne $today ) {
1928
        $do_update_record_status = 1;
1929
    }
1930
1931
    # second - if dates equal, check for 040 $d (for MARC 21)
1932
    if (  !$do_update_record_status
1933
        && $marcflavour eq 'MARC21'
1934
        && $record->subfield( '040', 'd' ) )
1935
    {
1936
        $do_update_record_status = 1;
1937
    }
1938
1939
    # third - if created today and no 040 $d, compare creator and modifier
1940
    if ( !$do_update_record_status ) {
1941
        if ( C4::Context->preference("AuthoritiesLog") ) {
1942
            my $logs = Koha::ActionLogs->search(
1943
                {
1944
                    module => 'AUTHORITIES',
1945
                    action => 'ADD',
1946
                    object => $authid
1947
                }
1948
            );
1949
            my $creator;
1950
            if ( my $log = $logs->next ) {
1951
                $creator = $log->user;
1952
            }
1953
            my $userenv = C4::Context->userenv();
1954
            my $modifier;
1955
            $modifier = $userenv->{'number'} if ref($userenv) eq 'HASH';
1956
1957
            # if not sure that modified by creator - set LDR/5
1958
            unless ( defined $creator
1959
                && defined $modifier
1960
                && $creator == $modifier )
1961
            {
1962
                $do_update_record_status = 1;
1963
            }
1964
        } else {
1965
            $do_update_record_status = 1;
1966
        }
1967
    }
1968
    if ($do_update_record_status) {
1969
        my $leader = $record->leader;
1970
        substr( $leader, 5, 1, 'c' );
1971
        $record->leader($leader);
1972
    }
1973
}
1974
1975
END { }    # module clean-up code here (global destructor)
1896
1976
1897
1;
1977
1;
1898
__END__
1978
__END__
(-)a/C4/Biblio.pm (-8 / +93 lines)
Lines 395-412 sub ModBiblio { Link Here
395
        return 0;
395
        return 0;
396
    }
396
    }
397
397
398
    if ( C4::Context->preference("CataloguingLog") ) {
398
    my $record_before_mod;
399
    my $decoding_error = "";
400
    if ( C4::Context->preference("CataloguingLog") || C4::Context->preference('AutoUpdateRecordStatus') ) {
399
        my $biblio = Koha::Biblios->find($biblionumber);
401
        my $biblio = Koha::Biblios->find($biblionumber);
400
        my $record;
402
        eval { $record_before_mod = $biblio->metadata->record };
401
        my $decoding_error = "";
402
        eval { $record = $biblio->metadata->record };
403
        if ($@) {
403
        if ($@) {
404
            my $exception = $@;
404
            my $exception = $@;
405
            $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') );
405
            $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') );
406
            $decoding_error = "There was an error with this bibliographic record: " . $exception;
406
            $decoding_error    = "There was an error with this bibliographic record: " . $exception;
407
            $record         = $biblio->metadata->record_strip_nonxml;
407
            $record_before_mod = $biblio->metadata->record_strip_nonxml;
408
        }
409
    }
410
411
    if ( C4::Context->preference("CataloguingLog") ) {
412
        logaction(
413
            "CATALOGUING", "MODIFY", $biblionumber,
414
            "biblio $decoding_error BEFORE=>" . $record_before_mod->as_formatted
415
        );
416
    }
417
418
    if ( C4::Context->preference('AutoUpdateRecordStatus') && $record_before_mod ) {
419
        my $ldr_5            = substr( $record->leader,            5, 1 );
420
        my $ldr_5_before_mod = substr( $record_before_mod->leader, 5, 1 );
421
        if ( $ldr_5 ne 'c' && $ldr_5 eq $ldr_5_before_mod ) {  # we update LDR/5 only if it has not been already changed
422
            _update_record_status( $record, $biblionumber );
408
        }
423
        }
409
        logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio $decoding_error BEFORE=>" . $record->as_formatted );
410
    }
424
    }
411
425
412
    if ( !$options->{disable_autolink} && C4::Context->preference('AutoLinkBiblios') ) {
426
    if ( !$options->{disable_autolink} && C4::Context->preference('AutoLinkBiblios') ) {
Lines 3201-3206 sub _after_biblio_action_hooks { Link Here
3201
    );
3215
    );
3202
}
3216
}
3203
3217
3218
=head2 _update_record_status
3219
3220
    _update_record_status( $record, $biblionumber )
3221
3222
Updates LDR/5 if need
3223
3224
=cut
3225
3226
sub _update_record_status {
3227
    my ( $record, $biblionumber ) = @_;
3228
    my $do_update_record_status;
3229
    my $marcflavour = C4::Context->preference("marcflavour");
3230
3231
    # first - check date entered on file
3232
    my $today        = POSIX::strftime( "%y%m%d", localtime );
3233
    my $date_created = '';
3234
    if ( $marcflavour eq 'MARC21' ) {
3235
        $date_created = substr( $record->field('008')->data, 0, 6 )
3236
            if $record->field('008');
3237
    } elsif ( $marcflavour eq 'UNIMARC' ) {
3238
        $date_created = substr( $record->subfield( '100', 'a' ), 2, 6 )
3239
            if $record->subfield( '100', 'a' );
3240
3241
    }
3242
    if ( $date_created && $date_created ne $today ) {
3243
        $do_update_record_status = 1;
3244
    }
3245
3246
    # second - if dates equal, check for 040 $d (for MARC 21)
3247
    if (  !$do_update_record_status
3248
        && $marcflavour eq 'MARC21'
3249
        && $record->subfield( '040', 'd' ) )
3250
    {
3251
        $do_update_record_status = 1;
3252
    }
3253
3254
    # third - if created today and no 040 $d, compare creator and modifier
3255
    if ( !$do_update_record_status ) {
3256
        if ( C4::Context->preference("CataloguingLog") ) {
3257
            my $logs = Koha::ActionLogs->search(
3258
                {
3259
                    module => 'CATALOGUING',
3260
                    action => 'ADD',
3261
                    object => $biblionumber
3262
                }
3263
            );
3264
            my $creator;
3265
            if ( my $log = $logs->next ) {
3266
                $creator = $log->user;
3267
            }
3268
            my $userenv = C4::Context->userenv();
3269
            my $modifier;
3270
            $modifier = $userenv->{'number'} if ref($userenv) eq 'HASH';
3271
3272
            # if not sure that modified by creator - set LDR/5
3273
            unless ( defined $creator
3274
                && defined $modifier
3275
                && $creator == $modifier )
3276
            {
3277
                $do_update_record_status = 1;
3278
            }
3279
        } else {
3280
            $do_update_record_status = 1;
3281
        }
3282
    }
3283
    if ($do_update_record_status) {
3284
        my $leader = $record->leader;
3285
        substr( $leader, 5, 1, 'c' );
3286
        $record->leader($leader);
3287
    }
3288
}
3289
3204
1;
3290
1;
3205
3291
3206
__END__
3292
__END__
3207
- 

Return to bug 42044