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

(-)a/Koha/Biblio.pm (-1 / +95 lines)
Lines 33-38 use C4::Acquisition qw( ModOrder GetOrdersByBiblionumber ); Link Here
33
use Koha::Database;
33
use Koha::Database;
34
use Koha::DateUtils qw( dt_from_string );
34
use Koha::DateUtils qw( dt_from_string );
35
use Koha::Exception;
35
use Koha::Exception;
36
use Koha::Exceptions::Biblio;
37
use Koha::Exceptions::SysPref;
36
38
37
use base qw(Koha::Object);
39
use base qw(Koha::Object);
38
40
Lines 2230-2238 sub merge_with { Link Here
2230
    return \%results;
2232
    return \%results;
2231
}
2233
}
2232
2234
2235
=head3 populate_item_callnumbers
2236
2237
    $biblio->populate_item_callnumbers( [ $filter ] );
2238
2239
Populates the linked items callnumbers following the I<itemcallnumber>
2240
system preference. Optionally, this action can be restricted by appliying
2241
a I<$filter> on the items iterator.
2242
2243
=cut
2244
2245
sub populate_item_callnumbers {
2246
    my ( $self, $filter ) = @_;
2247
2248
    my $callnumber = $self->get_first_callnumber();
2249
    my $items      = $self->items->search($filter);
2250
2251
    if ( $items->count ) {
2252
        my ($res) = $items->batch_update( { new_values => { itemcallnumber => $callnumber } } );
2253
        my @modified_itemnumbers = @{ $res->{modified_itemnumbers} };
2254
        $self->add_message(
2255
            {
2256
                message => q{populate_item_callnumbers},
2257
                type    => q{info},
2258
                payload => {
2259
                    updated_items_count => scalar @modified_itemnumbers,
2260
                    callnumber          => $callnumber,
2261
                    modified_item_ids   => \@modified_itemnumbers,
2262
                }
2263
            }
2264
        );
2265
    } else {
2266
        $self->add_message(
2267
            {
2268
                message => q{populate_item_callnumbers},
2269
                type    => q{info},
2270
                payload => {
2271
                    updated_items_count => 0,
2272
                    callnumber          => $callnumber,
2273
                }
2274
            }
2275
        );
2276
    }
2277
2278
    return $self;
2279
}
2280
2281
=head3 get_first_callnumber
2282
2283
    my $callnumber = $biblio->get_first_callnumber();
2284
2285
Retrieves the first callnumber it finds using the I<itemcallnumber> system
2286
preference. Returns undef if it doesn't find any.
2287
2288
Throws a I<Koha::Exceptions::SysPrefs::NotSet> exception if the relevant
2289
system preference is not set.
2290
2291
Throws a I<Koha::Exceptions::Biblio::MissingField> exception if the record
2292
doesn't contain a callnumber.
2293
2294
=cut
2295
2296
sub get_first_callnumber {
2297
    my ($self) = @_;
2298
2299
    my $cn_fields = C4::Context->preference(q{itemcallnumber});
2300
    Koha::Exceptions::SysPref::NotSet->throw( syspref => q{itemcallnumber} )
2301
        unless $cn_fields;
2302
2303
    my $record = $self->record;
2304
    my $callnumber;
2305
2306
    foreach my $callnumber_marc_field ( split( /,/, $cn_fields ) ) {
2307
2308
        my $callnumber_tag       = substr( $callnumber_marc_field, 0, 3 );
2309
        my $callnumber_subfields = substr( $callnumber_marc_field, 3 );
2310
2311
        next unless $callnumber_tag && $callnumber_subfields;
2312
2313
        my $field = $record->field($callnumber_tag);
2314
2315
        next unless $field;
2316
2317
        $callnumber = $field->as_string( $callnumber_subfields, '' );
2318
        last if $callnumber;
2319
    }
2320
2321
    Koha::Exceptions::Biblio::MissingField->throw( field => q{callnumber} )
2322
        unless defined $callnumber;
2323
2324
    return $callnumber;
2325
}
2326
2233
=head2 Internal methods
2327
=head2 Internal methods
2234
2328
2235
=head3 type
2329
=head3 _type
2236
2330
2237
=cut
2331
=cut
2238
2332
(-)a/Koha/Exceptions/Biblio.pm (-1 / +19 lines)
Line 0 Link Here
0
- 
1
package Koha::Exceptions::Biblio;
2
3
use Modern::Perl;
4
5
use Koha::Exception;
6
7
use Exception::Class (
8
9
    'Koha::Exceptions::Biblio' => {
10
        isa => 'Koha::Exception',
11
    },
12
    'Koha::Exceptions::Biblio::MissingField' => {
13
        isa         => 'Koha::Exceptions::Biblio',
14
        description => 'The required field is missing in the record',
15
        fields      => ['field']
16
    }
17
);
18
19
1;

Return to bug 38224