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

(-)a/Koha/Biblio.pm (-24 lines)
Lines 39-45 use Koha::CirculationRules; Link Here
39
use Koha::Item::Transfer::Limits;
39
use Koha::Item::Transfer::Limits;
40
use Koha::Items;
40
use Koha::Items;
41
use Koha::Libraries;
41
use Koha::Libraries;
42
use Koha::SearchEngine::Indexer;
43
use Koha::Suggestions;
42
use Koha::Suggestions;
44
use Koha::Subscriptions;
43
use Koha::Subscriptions;
45
44
Lines 953-981 sub get_marc_host { Link Here
953
    }
952
    }
954
}
953
}
955
954
956
=head3 adopt_items_from_biblio
957
958
$biblio->adopt_items_from_biblio($from_biblio);
959
960
Move items from the given biblio to this one.
961
962
=cut
963
964
sub adopt_items_from_biblio {
965
    my ( $self, $from_biblio ) = @_;
966
967
    my $items = $from_biblio->items;
968
    if ($items) {
969
        while (my $item = $items->next()) {
970
            $item->move_to_biblio($self, { skip_record_index => 1 });
971
        }
972
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
973
        $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" );
974
        $indexer->index_records( $from_biblio->biblionumber, "specialUpdate", "biblioserver" );
975
    }
976
}
977
978
979
=head2 Internal methods
955
=head2 Internal methods
980
956
981
=head3 type
957
=head3 type
(-)a/Koha/Items.pm (+22 lines)
Lines 26-31 use Koha::Item; Link Here
26
26
27
use base qw(Koha::Objects);
27
use base qw(Koha::Objects);
28
28
29
use Koha::SearchEngine::Indexer;
30
29
=head1 NAME
31
=head1 NAME
30
32
31
Koha::Items - Koha Item object set class
33
Koha::Items - Koha Item object set class
Lines 108-113 sub filter_out_lost { Link Here
108
    return $self->search( $params );
110
    return $self->search( $params );
109
}
111
}
110
112
113
=head3 move_to_biblio
114
115
 $items->move_to_biblio($to_biblio);
116
117
Move items to a given biblio.
118
119
=cut
120
121
sub move_to_biblio {
122
    my ( $self, $to_biblio ) = @_;
123
124
    while (my $item = $self->next()) {
125
        $item->move_to_biblio($to_biblio, { skip_record_index => 1 });
126
    }
127
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
128
    $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" );
129
    $indexer->index_records( $from_biblio->biblionumber, "specialUpdate", "biblioserver" );
130
}
131
132
111
=head2 Internal methods
133
=head2 Internal methods
112
134
113
=head3 _type
135
=head3 _type
(-)a/cataloguing/merge.pl (-2 / +2 lines)
Lines 96-102 if ($merge) { Link Here
96
    my $biblio = Koha::Biblios->find($ref_biblionumber);
96
    my $biblio = Koha::Biblios->find($ref_biblionumber);
97
    foreach my $biblionumber (@biblionumbers) {
97
    foreach my $biblionumber (@biblionumbers) {
98
        my $from_biblio = Koha::Biblios->find($biblionumber);
98
        my $from_biblio = Koha::Biblios->find($biblionumber);
99
        $biblio->adopt_items_from_biblio($from_biblio);
99
        $from_biblio->items->move_to_biblio($biblio);
100
        $from_biblio->article_requests->update({ biblionumber => $ref_biblionumber }, { no_triggers => 1 });
100
        $from_biblio->article_requests->update({ biblionumber => $ref_biblionumber }, { no_triggers => 1 });
101
    }
101
    }
102
102
Lines 161-167 if ($merge) { Link Here
161
    # Moving suggestions
161
    # Moving suggestions
162
    $sth_suggestions->execute($ref_biblionumber, $biblionumber);
162
    $sth_suggestions->execute($ref_biblionumber, $biblionumber);
163
163
164
    # Moving orders (orders linked to items of frombiblio have already been moved by adopt_items_from_biblio)
164
    # Moving orders (orders linked to items of frombiblio have already been moved by move_to_biblio)
165
    my @allorders = GetOrdersByBiblionumber($biblionumber);
165
    my @allorders = GetOrdersByBiblionumber($biblionumber);
166
    foreach my $myorder (@allorders) {
166
    foreach my $myorder (@allorders) {
167
        $myorder->{'biblionumber'} = $ref_biblionumber;
167
        $myorder->{'biblionumber'} = $ref_biblionumber;
(-)a/t/db_dependent/Koha/Biblio.t (-23 / +1 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 15;
20
use Test::More tests => 14;
21
21
22
use C4::Biblio qw( AddBiblio ModBiblio );
22
use C4::Biblio qw( AddBiblio ModBiblio );
23
use Koha::Database;
23
use Koha::Database;
Lines 637-661 subtest 'get_marc_notes() UNIMARC tests' => sub { Link Here
637
637
638
    $schema->storage->txn_rollback;
638
    $schema->storage->txn_rollback;
639
};
639
};
640
641
subtest 'adopt_items_from_biblio() tests' => sub {
642
643
    plan tests => 2;
644
645
    $schema->storage->txn_begin;
646
647
    my $biblio1 = $builder->build_sample_biblio;
648
    my $biblio2 = $builder->build_sample_biblio;
649
    my $item1 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber });
650
    my $item2 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber });
651
652
    $biblio2->adopt_items_from_biblio($biblio1);
653
654
    $item1->discard_changes;
655
    $item2->discard_changes;
656
657
    is($item1->biblionumber, $biblio2->biblionumber, "Item 1 moved");
658
    is($item2->biblionumber, $biblio2->biblionumber, "Item 2 moved");
659
660
    $schema->storage->txn_rollback;
661
};
(-)a/t/db_dependent/Koha/Items.t (-1 / +23 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 14;
22
use Test::More tests => 15;
23
23
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Exception;
25
use Test::Exception;
Lines 1686-1688 subtest 'filter_out_lost() tests' => sub { Link Here
1686
    $schema->storage->txn_rollback;
1686
    $schema->storage->txn_rollback;
1687
};
1687
};
1688
1688
1689
subtest 'move_to_biblio() tests' => sub {
1690
1691
    plan tests => 2;
1692
1693
    $schema->storage->txn_begin;
1694
1695
    my $biblio1 = $builder->build_sample_biblio;
1696
    my $biblio2 = $builder->build_sample_biblio;
1697
    my $item1 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber });
1698
    my $item2 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber });
1699
1700
    $biblio1->items->move_to_biblio($biblio2);
1701
1702
    $item1->discard_changes;
1703
    $item2->discard_changes;
1704
1705
    is($item1->biblionumber, $biblio2->biblionumber, "Item 1 moved");
1706
    is($item2->biblionumber, $biblio2->biblionumber, "Item 2 moved");
1707
1708
    $schema->storage->txn_rollback;
1709
1710
};
(-)a/t/db_dependent/Koha/SearchEngine/Indexer.t (-3 / +2 lines)
Lines 184-191 subtest 'Test indexer calls' => sub { Link Here
184
        } undef, "index_records is not called for $engine when moving an item to another biblio (Item->move_to_biblio) if skip_record_index passed";
184
        } undef, "index_records is not called for $engine when moving an item to another biblio (Item->move_to_biblio) if skip_record_index passed";
185
185
186
        warnings_are{
186
        warnings_are{
187
            $biblio2->adopt_items_from_biblio($biblio);
187
            $biblio->items->move_to_biblio($biblio2);
188
        } [$engine,"Koha::Biblio",$engine,"Koha::Biblio"], "index_records is called for both biblios for $engine when adopting items (Biblio->adopt_items_from_biblio)";
188
        } [$engine,"Koha::Biblio",$engine,"Koha::Biblio"], "index_records is called for both biblios for $engine when adopting items (Biblio->items->move_to_biblio(Biblio)";
189
189
190
        $builder->build({
190
        $builder->build({
191
            source => 'Issue',
191
            source => 'Issue',
192
- 

Return to bug 22690