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 2208-2216 sub merge_with { Link Here
2208
    return \%results;
2210
    return \%results;
2209
}
2211
}
2210
2212
2213
=head3 populate_item_callnumbers
2214
2215
    $biblio->populate_item_callnumbers( [ $filter ] );
2216
2217
Populates the linked items callnumbers following the I<itemcallnumber>
2218
system preference. Optionally, this action can be restricted by appliying
2219
a I<$filter> on the items iterator.
2220
2221
=cut
2222
2223
sub populate_item_callnumbers {
2224
    my ( $self, $filter ) = @_;
2225
2226
    my $callnumber = $self->get_first_callnumber();
2227
    my $items      = $self->items->search($filter);
2228
2229
    if ( $items->count ) {
2230
        my ($res) = $items->batch_update( { new_values => { itemcallnumber => $callnumber } } );
2231
        my @modified_itemnumbers = @{ $res->{modified_itemnumbers} };
2232
        $self->add_message(
2233
            {
2234
                message => q{populate_item_callnumbers},
2235
                type    => q{info},
2236
                payload => {
2237
                    updated_items_count => scalar @modified_itemnumbers,
2238
                    callnumber          => $callnumber,
2239
                    modified_item_ids   => \@modified_itemnumbers,
2240
                }
2241
            }
2242
        );
2243
    } else {
2244
        $self->add_message(
2245
            {
2246
                message => q{populate_item_callnumbers},
2247
                type    => q{info},
2248
                payload => {
2249
                    updated_items_count => 0,
2250
                    callnumber          => $callnumber,
2251
                }
2252
            }
2253
        );
2254
    }
2255
2256
    return $self;
2257
}
2258
2259
=head3 get_first_callnumber
2260
2261
    my $callnumber = $biblio->get_first_callnumber();
2262
2263
Retrieves the first callnumber it finds using the I<itemcallnumber> system
2264
preference. Returns undef if it doesn't find any.
2265
2266
Throws a I<Koha::Exceptions::SysPrefs::NotSet> exception if the relevant
2267
system preference is not set.
2268
2269
Throws a I<Koha::Exceptions::Biblio::MissingField> exception if the record
2270
doesn't contain a callnumber.
2271
2272
=cut
2273
2274
sub get_first_callnumber {
2275
    my ($self) = @_;
2276
2277
    my $cn_fields = C4::Context->preference(q{itemcallnumber});
2278
    Koha::Exceptions::SysPref::NotSet->throw( syspref => q{itemcallnumber} )
2279
        unless $cn_fields;
2280
2281
    my $record = $self->record;
2282
    my $callnumber;
2283
2284
    foreach my $callnumber_marc_field ( split( /,/, $cn_fields ) ) {
2285
2286
        my $callnumber_tag       = substr( $callnumber_marc_field, 0, 3 );
2287
        my $callnumber_subfields = substr( $callnumber_marc_field, 3 );
2288
2289
        next unless $callnumber_tag && $callnumber_subfields;
2290
2291
        my $field = $record->field($callnumber_tag);
2292
2293
        next unless $field;
2294
2295
        $callnumber = $field->as_string( $callnumber_subfields, '' );
2296
        last if $callnumber;
2297
    }
2298
2299
    Koha::Exceptions::Biblio::MissingField->throw( field => q{callnumber} )
2300
        unless defined $callnumber;
2301
2302
    return $callnumber;
2303
}
2304
2211
=head2 Internal methods
2305
=head2 Internal methods
2212
2306
2213
=head3 type
2307
=head3 _type
2214
2308
2215
=cut
2309
=cut
2216
2310
(-)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