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

(-)a/C4/Circulation.pm (-15 / +25 lines)
Lines 59-64 use Koha::Config::SysPrefs; Link Here
59
use Koha::Charges::Fees;
59
use Koha::Charges::Fees;
60
use Koha::Util::SystemPreferences;
60
use Koha::Util::SystemPreferences;
61
use Koha::Checkouts::ReturnClaims;
61
use Koha::Checkouts::ReturnClaims;
62
use Koha::SearchEngine::Indexer;
62
use Carp;
63
use Carp;
63
use List::MoreUtils qw( uniq any );
64
use List::MoreUtils qw( uniq any );
64
use Scalar::Util qw( looks_like_number );
65
use Scalar::Util qw( looks_like_number );
Lines 1880-1886 sub AddReturn { Link Here
1880
                . Dumper($issue->unblessed) . "\n";
1881
                . Dumper($issue->unblessed) . "\n";
1881
    } else {
1882
    } else {
1882
        $messages->{'NotIssued'} = $barcode;
1883
        $messages->{'NotIssued'} = $barcode;
1883
        $item->onloan(undef)->store if defined $item->onloan;
1884
        $item->onloan(undef)->store({skip_record_index=>1}) if defined $item->onloan;
1884
1885
1885
        # even though item is not on loan, it may still be transferred;  therefore, get current branch info
1886
        # even though item is not on loan, it may still be transferred;  therefore, get current branch info
1886
        $doreturn = 0;
1887
        $doreturn = 0;
Lines 1908-1916 sub AddReturn { Link Here
1908
        if (defined $update_loc_rules->{_ALL_}) {
1909
        if (defined $update_loc_rules->{_ALL_}) {
1909
            if ($update_loc_rules->{_ALL_} eq '_PERM_') { $update_loc_rules->{_ALL_} = $item->permanent_location; }
1910
            if ($update_loc_rules->{_ALL_} eq '_PERM_') { $update_loc_rules->{_ALL_} = $item->permanent_location; }
1910
            if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
1911
            if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
1911
            if ( $item->location ne $update_loc_rules->{_ALL_}) {
1912
            if ( defined $item->location && $item->location ne $update_loc_rules->{_ALL_}) {
1912
                $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{_ALL_} };
1913
                $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{_ALL_} };
1913
                $item->location($update_loc_rules->{_ALL_})->store;
1914
                $item->location($update_loc_rules->{_ALL_})->store({skip_record_index=>1});
1914
            }
1915
            }
1915
        }
1916
        }
1916
        else {
1917
        else {
Lines 1919-1925 sub AddReturn { Link Here
1919
                if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
1920
                if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
1920
                if ( ($item->location eq $key && $item->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $item->location eq '' && $update_loc_rules->{$key} ne '') ) {
1921
                if ( ($item->location eq $key && $item->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $item->location eq '' && $update_loc_rules->{$key} ne '') ) {
1921
                    $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{$key} };
1922
                    $messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{$key} };
1922
                    $item->location($update_loc_rules->{$key})->store;
1923
                    $item->location($update_loc_rules->{$key})->store({skip_record_index=>1});
1923
                    last;
1924
                    last;
1924
                }
1925
                }
1925
            }
1926
            }
Lines 1938-1944 sub AddReturn { Link Here
1938
            foreach my $key ( keys %$rules ) {
1939
            foreach my $key ( keys %$rules ) {
1939
                if ( $item->notforloan eq $key ) {
1940
                if ( $item->notforloan eq $key ) {
1940
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} };
1941
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} };
1941
                    $item->notforloan($rules->{$key})->store({ log_action => 0 });
1942
                    $item->notforloan($rules->{$key})->store({ log_action => 0, skip_record_index => 1 });
1942
                    last;
1943
                    last;
1943
                }
1944
                }
1944
            }
1945
            }
Lines 1952-1958 sub AddReturn { Link Here
1952
            Wrongbranch => $branch,
1953
            Wrongbranch => $branch,
1953
            Rightbranch => $message
1954
            Rightbranch => $message
1954
        };
1955
        };
1955
        $doreturn = 0;
1956
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
1957
        $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
1956
        return ( $doreturn, $messages, $issue, $patron_unblessed);
1958
        return ( $doreturn, $messages, $issue, $patron_unblessed);
1957
    }
1959
    }
1958
1960
Lines 1972-1978 sub AddReturn { Link Here
1972
1974
1973
        if ($patron) {
1975
        if ($patron) {
1974
            eval {
1976
            eval {
1975
                MarkIssueReturned( $borrowernumber, $item->itemnumber, $return_date, $patron->privacy );
1977
                MarkIssueReturned( $borrowernumber, $item->itemnumber, $return_date, $patron->privacy, { skip_record_index => 1} );
1976
            };
1978
            };
1977
            unless ( $@ ) {
1979
            unless ( $@ ) {
1978
                if (
1980
                if (
Lines 1988-2013 sub AddReturn { Link Here
1988
            } else {
1990
            } else {
1989
                carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue->unblessed );
1991
                carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue->unblessed );
1990
1992
1993
                my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
1994
                $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
1995
1991
                return ( 0, { WasReturned => 0, DataCorrupted => 1 }, $issue, $patron_unblessed );
1996
                return ( 0, { WasReturned => 0, DataCorrupted => 1 }, $issue, $patron_unblessed );
1992
            }
1997
            }
1993
1998
1994
            # FIXME is the "= 1" right?  This could be the borrower hash.
1999
            # FIXME is the "= 1" right?  This could be the borrower hash.
1995
            $messages->{'WasReturned'} = 1;
2000
            $messages->{'WasReturned'} = 1;
1996
2001
2002
        } else {
2003
            $item->onloan(undef)->store({ log_action => 0 , skip_record_index => 1 });
1997
        }
2004
        }
1998
1999
        $item->onloan(undef)->store({ log_action => 0 });
2000
    }
2005
    }
2001
2006
2002
    # the holdingbranch is updated if the document is returned to another location.
2007
    # the holdingbranch is updated if the document is returned to another location.
2003
    # this is always done regardless of whether the item was on loan or not
2008
    # this is always done regardless of whether the item was on loan or not
2004
    my $item_holding_branch = $item->holdingbranch;
2009
    my $item_holding_branch = $item->holdingbranch;
2005
    if ($item->holdingbranch ne $branch) {
2010
    if ($item->holdingbranch ne $branch) {
2006
        $item->holdingbranch($branch)->store;
2011
        $item->holdingbranch($branch)->store({ skip_record_index => 1 });
2007
    }
2012
    }
2008
2013
2009
    my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
2014
    my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
2010
    ModDateLastSeen( $item->itemnumber, $leave_item_lost );
2015
    ModDateLastSeen( $item->itemnumber, $leave_item_lost, { skip_record_index => 1 } );
2011
2016
2012
    # check if we have a transfer for this document
2017
    # check if we have a transfer for this document
2013
    my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->itemnumber );
2018
    my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->itemnumber );
Lines 2144-2150 sub AddReturn { Link Here
2144
           )) {
2149
           )) {
2145
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s, %s)", $item->itemnumber,$branch, $returnbranch, $transfer_trigger;
2150
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s, %s)", $item->itemnumber,$branch, $returnbranch, $transfer_trigger;
2146
            $debug and warn "item: " . Dumper($item->unblessed);
2151
            $debug and warn "item: " . Dumper($item->unblessed);
2147
            ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger);
2152
            ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2148
            $messages->{'WasTransfered'} = 1;
2153
            $messages->{'WasTransfered'} = 1;
2149
        } else {
2154
        } else {
2150
            $messages->{'NeedsTransfer'} = $returnbranch;
2155
            $messages->{'NeedsTransfer'} = $returnbranch;
Lines 2165-2176 sub AddReturn { Link Here
2165
        }
2170
        }
2166
    }
2171
    }
2167
2172
2173
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
2174
    $indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
2175
2168
    return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} ));
2176
    return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} ));
2169
}
2177
}
2170
2178
2171
=head2 MarkIssueReturned
2179
=head2 MarkIssueReturned
2172
2180
2173
  MarkIssueReturned($borrowernumber, $itemnumber, $returndate, $privacy);
2181
  MarkIssueReturned($borrowernumber, $itemnumber, $returndate, $privacy, [$params] );
2174
2182
2175
Unconditionally marks an issue as being returned by
2183
Unconditionally marks an issue as being returned by
2176
moving the C<issues> row to C<old_issues> and
2184
moving the C<issues> row to C<old_issues> and
Lines 2186-2195 Ideally, this function would be internal to C<C4::Circulation>, Link Here
2186
not exported, but it is currently used in misc/cronjobs/longoverdue.pl
2194
not exported, but it is currently used in misc/cronjobs/longoverdue.pl
2187
and offline_circ/process_koc.pl.
2195
and offline_circ/process_koc.pl.
2188
2196
2197
The last optional parameter allos passing skip_record_index to the item store call.
2198
2189
=cut
2199
=cut
2190
2200
2191
sub MarkIssueReturned {
2201
sub MarkIssueReturned {
2192
    my ( $borrowernumber, $itemnumber, $returndate, $privacy ) = @_;
2202
    my ( $borrowernumber, $itemnumber, $returndate, $privacy, $params ) = @_;
2193
2203
2194
    # Retrieve the issue
2204
    # Retrieve the issue
2195
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
2205
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
Lines 2235-2241 sub MarkIssueReturned { Link Here
2235
        # And finally delete the issue
2245
        # And finally delete the issue
2236
        $issue->delete;
2246
        $issue->delete;
2237
2247
2238
        $issue->item->onloan(undef)->store({ log_action => 0 });
2248
        $issue->item->onloan(undef)->store({ log_action => 0, skip_record_index => $params->{skip_record_index} });
2239
2249
2240
        if ( C4::Context->preference('StoreLastBorrower') ) {
2250
        if ( C4::Context->preference('StoreLastBorrower') ) {
2241
            my $item = Koha::Items->find( $itemnumber );
2251
            my $item = Koha::Items->find( $itemnumber );
(-)a/C4/Items.pm (-7 / +11 lines)
Lines 334-347 sub ModItemFromMarc { Link Here
334
334
335
=head2 ModItemTransfer
335
=head2 ModItemTransfer
336
336
337
  ModItemTransfer($itemnumber, $frombranch, $tobranch, $trigger);
337
  ModItemTransfer($itemnumber, $frombranch, $tobranch, $trigger, [$params]);
338
338
339
Marks an item as being transferred from one branch to another and records the trigger.
339
Marks an item as being transferred from one branch to another and records the trigger.
340
340
341
The last optional parameter allows for passing skip_record_index through to the items store call.
342
341
=cut
343
=cut
342
344
343
sub ModItemTransfer {
345
sub ModItemTransfer {
344
    my ( $itemnumber, $frombranch, $tobranch, $trigger ) = @_;
346
    my ( $itemnumber, $frombranch, $tobranch, $trigger, $params ) = @_;
345
347
346
    my $dbh = C4::Context->dbh;
348
    my $dbh = C4::Context->dbh;
347
    my $item = Koha::Items->find( $itemnumber );
349
    my $item = Koha::Items->find( $itemnumber );
Lines 358-387 sub ModItemTransfer { Link Here
358
    $sth->execute($itemnumber, $frombranch, $tobranch, $trigger);
360
    $sth->execute($itemnumber, $frombranch, $tobranch, $trigger);
359
361
360
    # FIXME we are fetching the item twice in the 2 next statements!
362
    # FIXME we are fetching the item twice in the 2 next statements!
361
    Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store({ log_action => 0 });
363
    Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store({ log_action => 0, skip_record_index => $params->{skip_record_index} });
362
    ModDateLastSeen($itemnumber);
364
    ModDateLastSeen($itemnumber, undef, { skip_record_index => $params->{skip_record_index} });
363
    return;
365
    return;
364
}
366
}
365
367
366
=head2 ModDateLastSeen
368
=head2 ModDateLastSeen
367
369
368
ModDateLastSeen( $itemnumber, $leave_item_lost );
370
ModDateLastSeen( $itemnumber, $leave_item_lost, $params );
369
371
370
Mark item as seen. Is called when an item is issued, returned or manually marked during inventory/stocktaking.
372
Mark item as seen. Is called when an item is issued, returned or manually marked during inventory/stocktaking.
371
C<$itemnumber> is the item number
373
C<$itemnumber> is the item number
372
C<$leave_item_lost> determines if a lost item will be found or remain lost
374
C<$leave_item_lost> determines if a lost item will be found or remain lost
373
375
376
The last optional parameter allows for passing skip_record_index through to the items store call.
377
374
=cut
378
=cut
375
379
376
sub ModDateLastSeen {
380
sub ModDateLastSeen {
377
    my ( $itemnumber, $leave_item_lost ) = @_;
381
    my ( $itemnumber, $leave_item_lost, $params ) = @_;
378
382
379
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
383
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
380
384
381
    my $item = Koha::Items->find($itemnumber);
385
    my $item = Koha::Items->find($itemnumber);
382
    $item->datelastseen($today);
386
    $item->datelastseen($today);
383
    $item->itemlost(0) unless $leave_item_lost;
387
    $item->itemlost(0) unless $leave_item_lost;
384
    $item->store({ log_action => 0 });
388
    $item->store({ log_action => 0, skip_record_index => $params->{skip_record_index} });
385
}
389
}
386
390
387
=head2 CheckItemPreSave
391
=head2 CheckItemPreSave
(-)a/t/db_dependent/Koha/SearchEngine/Indexer.t (-5 / +62 lines)
Lines 18-24 use t::lib::Mocks; Link Here
18
use C4::AuthoritiesMarc;
18
use C4::AuthoritiesMarc;
19
use C4::Biblio;
19
use C4::Biblio;
20
use C4::Circulation;
20
use C4::Circulation;
21
use C4::Items;
21
use Koha::Database;
22
use Koha::Database;
23
use Koha::SearchEngine::Elasticsearch;
22
use Koha::SearchEngine::Indexer;
24
use Koha::SearchEngine::Indexer;
23
25
24
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
Lines 58-70 subtest 'Test indexer object creation' => sub { Link Here
58
};
60
};
59
61
60
subtest 'Test indexer calls' => sub {
62
subtest 'Test indexer calls' => sub {
61
    plan tests => 24;
63
    plan tests => 40;
62
64
63
    my @engines = ('Zebra');
65
    my @engines = ('Zebra');
64
    eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; };
66
    eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; };
65
    push @engines, 'Elasticsearch' unless $@;
67
    push @engines, 'Elasticsearch' unless $@;
66
    SKIP: {
68
    SKIP: {
67
    skip 'Elasticsearch configuration not available', 12
69
    skip 'Elasticsearch configuration not available', 20
68
            if scalar @engines == 1;
70
            if scalar @engines == 1;
69
    }
71
    }
70
72
Lines 109-121 subtest 'Test indexer calls' => sub { Link Here
109
        my $item;
111
        my $item;
110
        my $item2;
112
        my $item2;
111
        warnings_are{
113
        warnings_are{
112
            $item = $builder->build_sample_item({biblionumber => $biblio->biblionumber});
114
            $item = $builder->build_sample_item({
113
            $item2 = $builder->build_sample_item({biblionumber => $biblio->biblionumber});
115
                biblionumber => $biblio->biblionumber,
116
                onloan => '2020-02-02',
117
                datelastseen => '2020-01-01'
118
            });
119
            $item2 = $builder->build_sample_item({
120
                biblionumber => $biblio->biblionumber,
121
                onloan => '2020-12-12',
122
                datelastseen => '2020-11-11'
123
            });
114
        } [$engine,"Koha::Item",$engine,"Koha::Item"], "index_records is called for $engine when adding an item (Item->store)";
124
        } [$engine,"Koha::Item",$engine,"Koha::Item"], "index_records is called for $engine when adding an item (Item->store)";
115
        warnings_are{
125
        warnings_are{
116
            $item->store({ skip_record_index => 1 });
126
            $item->store({ skip_record_index => 1 });
117
        } undef, "index_records is not called for $engine when adding an item (Item->store) if skip_record_index passed";
127
        } undef, "index_records is not called for $engine when adding an item (Item->store) if skip_record_index passed";
118
128
129
        my $issue = $builder->build({
130
            source => 'Issue',
131
            value  => {
132
                itemnumber => $item->itemnumber
133
            }
134
        });
135
        my $issue2 = $builder->build({
136
            source => 'Issue',
137
            value  => {
138
                itemnumber => $item2->itemnumber
139
            }
140
        });
141
        warnings_are{
142
            MarkIssueReturned( $issue->{borrowernumber}, $item->itemnumber);
143
        } [$engine,"Koha::Item"], "index_records is called for $engine when calling MarkIssueReturned";
144
        warnings_are{
145
            MarkIssueReturned( $issue2->{borrowernumber}, $item2->itemnumber, undef, undef, { skip_record_index => 1});
146
        } undef, "index_records is not called for $engine when calling MarkIssueReturned if skip_record_index passed";
147
148
        warnings_are{
149
            AddReturn($item->barcode, $item->homebranch, 0, undef);
150
        } [$engine,'C4::Circulation'], "index_records is called once for $engine when calling AddReturn if item not issued";
151
        $issue = $builder->build({
152
            source => 'Issue',
153
            value  => {
154
                itemnumber => $item->itemnumber
155
            }
156
        });
157
        warnings_are{
158
            AddReturn($item->barcode, $item->homebranch, 0, undef);
159
        } [$engine,'C4::Circulation'], "index_records is called once for $engine when calling AddReturn if item not issued";
160
119
        $builder->build({
161
        $builder->build({
120
            source => 'Branchtransfer',
162
            source => 'Branchtransfer',
121
            value => {
163
            value => {
Lines 135-140 subtest 'Test indexer calls' => sub { Link Here
135
            LostItem( $item->itemnumber, "tests", undef, { skip_record_index => 1 });
177
            LostItem( $item->itemnumber, "tests", undef, { skip_record_index => 1 });
136
        } undef, "index_records is not called for $engine when calling LostItem and transfer exists if skip_record_index";
178
        } undef, "index_records is not called for $engine when calling LostItem and transfer exists if skip_record_index";
137
179
180
        $item->datelastseen('2020-02-02');
181
        $item->store({skip_record_index=>1});
182
        warnings_are{
183
            my $t1 = ModDateLastSeen( $item->itemnumber, 1, undef );
184
        } [$engine, "Koha::Item"], "index_records is called for $engine when calling ModDateLastSeen";
185
        warnings_are{
186
            ModDateLastSeen( $item->itemnumber, 1, { skip_record_index =>1 } );
187
        } undef, "index_records is not called for $engine when calling ModDateLastSeen if skip_record_index";
188
189
        warnings_are{
190
            ModItemTransfer( $item->itemnumber, $item->homebranch, $item2->homebranch,'Manual');
191
        } [$engine,"Koha::Item"], "index_records is called for $engine when calling ModItemTransfer";
192
        warnings_are{
193
            ModItemTransfer( $item->itemnumber, $item2->homebranch, $item->homebranch,'Manual',{skip_record_index=>1});
194
        } undef, "index_records is not called for $engine when calling ModItemTransfer with skip_record_index";
195
138
        warnings_are{
196
        warnings_are{
139
            $item->delete();
197
            $item->delete();
140
        } [$engine,"Koha::Item"], "index_records is called for $engine when deleting an item (Item->delete)";
198
        } [$engine,"Koha::Item"], "index_records is called for $engine when deleting an item (Item->delete)";
141
- 

Return to bug 26581