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

(-)a/Koha/Biblio.pm (-9 / +60 lines)
Lines 995-1000 sub subscriptions { Link Here
995
    return Koha::Subscriptions->_new_from_dbic($rs);
995
    return Koha::Subscriptions->_new_from_dbic($rs);
996
}
996
}
997
997
998
=head3 serials
999
1000
my $serials = $self->serials
1001
1002
Returns the related Koha::Serials object for this Biblio object
1003
1004
=cut
1005
1006
sub serials {
1007
    my ($self) = @_;
1008
    my $rs = $self->_result->serials;
1009
    return Koha::Serials->_new_from_dbic($rs);
1010
}
1011
1012
=head3 subscription_histories
1013
1014
my $subscription_histories = $self->subscription_histories
1015
1016
Returns the related Koha::Subscription::Histories object for this Biblio object
1017
1018
=cut
1019
1020
sub subscription_histories {
1021
    my ($self) = @_;
1022
    my $rs = $self->_result->subscriptionhistories;
1023
    return Koha::Subscription::Histories->_new_from_dbic($rs);
1024
}
1025
998
=head3 has_items_waiting_or_intransit
1026
=head3 has_items_waiting_or_intransit
999
1027
1000
my $itemsWaitingOrInTransit = $biblio->has_items_waiting_or_intransit
1028
my $itemsWaitingOrInTransit = $biblio->has_items_waiting_or_intransit
Lines 1953-1979 sub merge_with { Link Here
1953
                foreach my $bn_merge (@biblio_ids_to_merge) {
1981
                foreach my $bn_merge (@biblio_ids_to_merge) {
1954
                    my $from_biblio = Koha::Biblios->find($bn_merge);
1982
                    my $from_biblio = Koha::Biblios->find($bn_merge);
1955
                    $from_biblio->items->move_to_biblio($self);
1983
                    $from_biblio->items->move_to_biblio($self);
1984
1985
                    # Move article requests
1956
                    $from_biblio->article_requests->update(
1986
                    $from_biblio->article_requests->update(
1957
                        { biblionumber => $ref_biblionumber },
1987
                        { biblionumber => $ref_biblionumber },
1958
                        { no_triggers  => 1 }
1988
                        { no_triggers  => 1 }
1959
                    );
1989
                    );
1960
1990
1961
                    for my $resultset_name (qw(Subscription Subscriptionhistory Serial Suggestion)) {
1991
                    # Move subscriptions
1962
                        $schema->resultset($resultset_name)->search( { biblionumber => $bn_merge } )
1992
                    $from_biblio->subscriptions->update(
1963
                            ->update( { biblionumber => $ref_biblionumber } );
1993
                        { biblionumber => $ref_biblionumber },
1964
                    }
1994
                        { no_triggers  => 1 }
1995
                    );
1965
1996
1966
                    # TODO should this be ported to more modern DB usage (i.e. DBIx::Class)?
1997
                    # Move subscription histories
1967
                    my @allorders = GetOrdersByBiblionumber($bn_merge);
1998
                    $from_biblio->subscription_histories->update(
1968
                    foreach my $myorder (@allorders) {
1999
                        { biblionumber => $ref_biblionumber },
1969
                        $myorder->{'biblionumber'} = $ref_biblionumber;
2000
                        { no_triggers  => 1 }
1970
                        ModOrder($myorder);
2001
                    );
2002
2003
                    # Move serials
2004
                    $from_biblio->serials->update(
2005
                        { biblionumber => $ref_biblionumber },
2006
                        { no_triggers  => 1 }
2007
                    );
2008
2009
                    # Move suggestions
2010
                    $from_biblio->suggestions->update(
2011
                        { biblionumber => $ref_biblionumber },
2012
                        { no_triggers  => 1 }
2013
                    );
2014
2015
                    my $orders = $from_biblio->orders->unblessed;
2016
                    for my $order (@$orders) {
2017
                        $order->{'biblionumber'} = $ref_biblionumber;
2018
2019
                        # TODO Do we really need to call ModOrder here?
2020
                        ModOrder($order);
1971
2021
1972
                        # TODO : add error control (in ModOrder?)
2022
                        # TODO : add error control (in ModOrder?)
1973
                    }
2023
                    }
1974
2024
1975
                    # Move holds
2025
                    # Move holds
1976
                    MergeHolds( $schema->storage->dbh, $ref_biblionumber, $bn_merge );
2026
                    MergeHolds( $schema->storage->dbh, $ref_biblionumber, $bn_merge );
2027
1977
                    my $error = DelBiblio($bn_merge);    #DelBiblio return undef unless an error occurs
2028
                    my $error = DelBiblio($bn_merge);    #DelBiblio return undef unless an error occurs
1978
                    if ($error) {
2029
                    if ($error) {
1979
                        die $error;
2030
                        die $error;
(-)a/t/db_dependent/Koha/Biblio.t (-2 / +77 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 31;
20
use Test::More tests => 33;
21
use Test::Exception;
21
use Test::Exception;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 912-917 subtest 'tickets() tests' => sub { Link Here
912
    $schema->storage->txn_rollback;
912
    $schema->storage->txn_rollback;
913
};
913
};
914
914
915
subtest 'serials() tests' => sub {
916
917
    plan tests => 4;
918
919
    $schema->storage->txn_begin;
920
921
    my $biblio = $builder->build_sample_biblio;
922
923
    my $serials = $biblio->serials;
924
    is(
925
        ref($serials), 'Koha::Serials',
926
        'Koha::Biblio->serials should return a Koha::Serials object'
927
    );
928
    is( $serials->count, 0, 'Koha::Biblio->serials should return the correct number of serials' );
929
930
    # Add two serials
931
    foreach ( 1 .. 2 ) {
932
        $builder->build_object(
933
            {
934
                class => 'Koha::Serials',
935
                value => { biblionumber => $biblio->biblionumber }
936
            }
937
        );
938
    }
939
940
    $serials = $biblio->serials;
941
    is(
942
        ref($serials), 'Koha::Serials',
943
        'Koha::Biblio->serials should return a Koha::Serials object'
944
    );
945
    is( $serials->count, 2, 'Koha::Biblio->serials should return the correct number of serials' );
946
947
    $schema->storage->txn_rollback;
948
};
949
915
subtest 'subscriptions() tests' => sub {
950
subtest 'subscriptions() tests' => sub {
916
951
917
    plan tests => 4;
952
    plan tests => 4;
Lines 945-950 subtest 'subscriptions() tests' => sub { Link Here
945
    $schema->storage->txn_rollback;
980
    $schema->storage->txn_rollback;
946
};
981
};
947
982
983
subtest 'subscription_histories() tests' => sub {
984
985
    plan tests => 4;
986
987
    $schema->storage->txn_begin;
988
989
    my $biblio = $builder->build_sample_biblio;
990
991
    my $sub_histories = $biblio->subscription_histories;
992
    is(
993
        ref($sub_histories), 'Koha::Subscription::Histories',
994
        'Koha::Biblio->subscription_histories should return a Koha::Subscription::Histories object'
995
    );
996
    is(
997
        $sub_histories->count, 0,
998
        'Koha::Biblio->subscription_histories should return the correct number of subscription histories'
999
    );
1000
1001
    # Add two subscription histories
1002
    foreach ( 1 .. 2 ) {
1003
        $builder->build_object(
1004
            {
1005
                class => 'Koha::Subscription::Histories',
1006
                value => { biblionumber => $biblio->biblionumber }
1007
            }
1008
        );
1009
    }
1010
1011
    $sub_histories = $biblio->subscription_histories;
1012
    is(
1013
        ref($sub_histories), 'Koha::Subscription::Histories',
1014
        'Koha::Biblio->subscription_histories should return a Koha::Subscription::Histories object'
1015
    );
1016
    is(
1017
        $sub_histories->count, 2,
1018
        'Koha::Biblio->subscription_histories should return the correct number of subscription histories'
1019
    );
1020
1021
    $schema->storage->txn_rollback;
1022
};
1023
948
subtest 'get_marc_notes() MARC21 tests' => sub {
1024
subtest 'get_marc_notes() MARC21 tests' => sub {
949
    plan tests => 14;
1025
    plan tests => 14;
950
1026
951
- 

Return to bug 33036