https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43604
Bug ID: 43604
Summary: commit_file.pl --revert dies: safe_to_delete calls
can_edit_items_from on undef
Initiative type: ---
Sponsorship ---
status:
Product: Koha
Version: Main
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P5 - low
Component: Tools
Assignee: [email protected]
Reporter: [email protected]
QA Contact: [email protected]
Target Milestone: ---
This fixes a regression introduced by bug 33070, where
Koha::Item->safe_to_delete assumed C4::Context->userenv->{number} always
corresponds to a real Koha::Patron.
misc/commit_file.pl sets a dummy CLI userenv with borrowernumber 0:
C4::Context->set_userenv( 0, 'batch', 0, 'batch', 'batch', 'batch', 'batch'
);
Running --revert on a batch calls C4::ImportBatch::BatchRevertItems, which
calls Koha::Item->safe_delete on every item created by the batch. safe_delete
calls safe_to_delete, which runs:
!Koha::Patrons->find( C4::Context->userenv->{number}
)->can_edit_items_from( $self->homebranch )
Since there is no patron with borrowernumber 0, Koha::Patrons->find returns
undef, and calling ->can_edit_items_from on undef is a fatal error that aborts
the whole script.
Other call sites touched by bug 33070 already guard against a missing patron
(e.g. Koha::UI::Table::Builder::Items->build_table: nomod => $patron ?
!$patron->can_edit_items_from(...) : 0), but Koha::Item->safe_to_delete never
got the same guard.
Test plan:
1. Stage and commit a batch of records so items get created (e.g. via the
Manage staged MARC records tool, or misc/commit_file.pl --batch-number NNN).
2. Run: misc/commit_file.pl --batch-number NNN --revert
3. Without this patch, the script dies with:
Can't call method "can_edit_items_from" on an undefined value at
Koha/Item.pm line 374.
4. Apply the patch.
5. Run: prove t/db_dependent/Koha/Item.t -- all tests pass, including the new
regression test.
6. Repeat step 2 -- the batch reverts successfully.
--
You are receiving this mail because:
You are the assignee for the bug.
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/