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

(-)a/C4/Circulation.pm (-8 / +10 lines)
Lines 1399-1405 sub AddIssue { Link Here
1399
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1399
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1400
                },
1400
                },
1401
                $item->{'biblionumber'},
1401
                $item->{'biblionumber'},
1402
                $item->{'itemnumber'}
1402
                $item->{'itemnumber'},
1403
                0
1403
            );
1404
            );
1404
            ModDateLastSeen( $item->{'itemnumber'} );
1405
            ModDateLastSeen( $item->{'itemnumber'} );
1405
1406
Lines 1832-1838 sub AddReturn { Link Here
1832
            $item->{location} = $item->{permanent_location};
1833
            $item->{location} = $item->{permanent_location};
1833
        }
1834
        }
1834
1835
1835
        ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
1836
        ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'}, 0 );
1836
    }
1837
    }
1837
1838
1838
        # full item data, but no borrowernumber or checkout info (no issue)
1839
        # full item data, but no borrowernumber or checkout info (no issue)
Lines 1856-1862 sub AddReturn { Link Here
1856
            foreach my $key ( keys %$rules ) {
1857
            foreach my $key ( keys %$rules ) {
1857
                if ( $item->{notforloan} eq $key ) {
1858
                if ( $item->{notforloan} eq $key ) {
1858
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} };
1859
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} };
1859
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber );
1860
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, 0 );
1860
                    last;
1861
                    last;
1861
                }
1862
                }
1862
            }
1863
            }
Lines 1922-1928 sub AddReturn { Link Here
1922
1923
1923
        }
1924
        }
1924
1925
1925
        ModItem({ onloan => undef }, $item->{biblionumber}, $item->{'itemnumber'});
1926
        ModItem( { onloan => undef }, $item->{biblionumber}, $item->{itemnumber}, 0 );
1926
    }
1927
    }
1927
1928
1928
    # the holdingbranch is updated if the document is returned to another location.
1929
    # the holdingbranch is updated if the document is returned to another location.
Lines 2158-2164 sub MarkIssueReturned { Link Here
2158
        # And finally delete the issue
2159
        # And finally delete the issue
2159
        $issue->delete;
2160
        $issue->delete;
2160
2161
2161
        ModItem( { 'onloan' => undef }, undef, $itemnumber );
2162
        ModItem( { 'onloan' => undef }, undef, $itemnumber, 0 );
2162
2163
2163
        if ( C4::Context->preference('StoreLastBorrower') ) {
2164
        if ( C4::Context->preference('StoreLastBorrower') ) {
2164
            my $item = Koha::Items->find( $itemnumber );
2165
            my $item = Koha::Items->find( $itemnumber );
Lines 2397-2403 sub _FixAccountForLostAndReturned { Link Here
2397
        }
2398
        }
2398
    );
2399
    );
2399
2400
2400
    ModItem( { paidfor => '' }, undef, $itemnumber );
2401
    ModItem( { paidfor => '' }, undef, $itemnumber, 0 );
2401
2402
2402
    return $credit_id;
2403
    return $credit_id;
2403
}
2404
}
Lines 2822-2828 sub AddRenewal { Link Here
2822
2823
2823
    # Update the renewal count on the item, and tell zebra to reindex
2824
    # Update the renewal count on the item, and tell zebra to reindex
2824
    $renews = $item->{renewals} + 1;
2825
    $renews = $item->{renewals} + 1;
2825
    ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber);
2826
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, 0 );
2826
2827
2827
    # Charge a new rental fee, if applicable?
2828
    # Charge a new rental fee, if applicable?
2828
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2829
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
Lines 3701-3707 sub ProcessOfflineReturn { Link Here
3701
            ModItem(
3702
            ModItem(
3702
                { renewals => 0, onloan => undef },
3703
                { renewals => 0, onloan => undef },
3703
                $issue->{'biblionumber'},
3704
                $issue->{'biblionumber'},
3704
                $itemnumber
3705
                $itemnumber,
3706
                0
3705
            );
3707
            );
3706
            return "Success.";
3708
            return "Success.";
3707
        } else {
3709
        } else {
(-)a/C4/Items.pm (-6 / +11 lines)
Lines 517-523 sub ModItemFromMarc { Link Here
517
517
518
=head2 ModItem
518
=head2 ModItem
519
519
520
  ModItem({ column => $newvalue }, $biblionumber, $itemnumber);
520
  ModItem({ column => $newvalue }, $biblionumber, $itemnumber, $log_action );
521
521
522
Change one or more columns in an item record and update
522
Change one or more columns in an item record and update
523
the MARC representation of the item.
523
the MARC representation of the item.
Lines 538-549 the derived value of a column such as C<items.cn_sort>, Link Here
538
this routine will perform the necessary calculation
538
this routine will perform the necessary calculation
539
and set the value.
539
and set the value.
540
540
541
If log_action is set to false, the action will not be logged.
542
If log_action is true or undefined, the action will be logged.
543
541
=cut
544
=cut
542
545
543
sub ModItem {
546
sub ModItem {
544
    my $item = shift;
547
    my $item = shift;
545
    my $biblionumber = shift;
548
    my $biblionumber = shift;
546
    my $itemnumber = shift;
549
    my $itemnumber = shift;
550
    my $log_action = shift // 1;
547
551
548
    # if $biblionumber is undefined, get it from the current item
552
    # if $biblionumber is undefined, get it from the current item
549
    unless (defined $biblionumber) {
553
    unless (defined $biblionumber) {
Lines 552-559 sub ModItem { Link Here
552
556
553
    my $dbh           = @_ ? shift : C4::Context->dbh;
557
    my $dbh           = @_ ? shift : C4::Context->dbh;
554
    my $frameworkcode = @_ ? shift : C4::Biblio::GetFrameworkCode( $biblionumber );
558
    my $frameworkcode = @_ ? shift : C4::Biblio::GetFrameworkCode( $biblionumber );
555
    
559
556
    my $unlinked_item_subfields;  
560
    my $unlinked_item_subfields;
557
    if (@_) {
561
    if (@_) {
558
        $unlinked_item_subfields = shift;
562
        $unlinked_item_subfields = shift;
559
        $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields);
563
        $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields);
Lines 602-608 sub ModItem { Link Here
602
    # item status is possible
606
    # item status is possible
603
    ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
607
    ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
604
608
605
    logaction("CATALOGUING", "MODIFY", $itemnumber, "item ".Dumper($item)) if C4::Context->preference("CataloguingLog");
609
    logaction( "CATALOGUING", "MODIFY", $itemnumber, "item " . Dumper($item) )
610
      if $log_action && C4::Context->preference("CataloguingLog");
606
}
611
}
607
612
608
=head2 ModItemTransfer
613
=head2 ModItemTransfer
Lines 646-654 C<$itemnum> is the item number Link Here
646
651
647
sub ModDateLastSeen {
652
sub ModDateLastSeen {
648
    my ($itemnumber) = @_;
653
    my ($itemnumber) = @_;
649
    
654
650
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
655
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
651
    ModItem({ itemlost => 0, datelastseen => $today }, undef, $itemnumber);
656
    ModItem( { itemlost => 0, datelastseen => $today }, undef, $itemnumber, 0 );
652
}
657
}
653
658
654
=head2 DelItem
659
=head2 DelItem
(-)a/t/db_dependent/Items.t (-4 / +43 lines)
Lines 25-37 use Koha::Database; Link Here
25
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
26
use Koha::Library;
26
use Koha::Library;
27
use Koha::DateUtils;
27
use Koha::DateUtils;
28
use Koha::MarcSubfieldStructures;
29
use Koha::Caches;
28
30
29
use t::lib::Mocks;
31
use t::lib::Mocks;
30
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
31
33
32
use Koha::MarcSubfieldStructures;
33
use Koha::Caches;
34
35
use Test::More tests => 13;
34
use Test::More tests => 13;
36
35
37
use Test::Warn;
36
use Test::Warn;
Lines 797-802 subtest 'get_hostitemnumbers_of' => sub { Link Here
797
    is( @itemnumbers, 0, );
796
    is( @itemnumbers, 0, );
798
};
797
};
799
798
799
subtest 'Test logging for AddItem' => sub {
800
801
    plan tests => 3;
802
803
    t::lib::Mocks::mock_preference('CataloguingLog', 1);
804
805
    $schema->storage->txn_begin;
806
807
    my $builder = t::lib::TestBuilder->new;
808
    my $library = $builder->build({
809
        source => 'Branch',
810
    });
811
    my $itemtype = $builder->build({
812
        source => 'Itemtype',
813
    });
814
815
    # Create a biblio instance for testing
816
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
817
    my ($bibnum, $bibitemnum) = get_biblio();
818
819
    # Add an item.
820
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum);
821
822
    # False means no logging
823
    $schema->resultset('ActionLog')->search()->delete();
824
    ModItem({ location => $location }, $bibnum, $itemnumber, 0);
825
    is( $schema->resultset('ActionLog')->count(), 0, 'False value does not trigger logging' );
826
827
    # True means logging
828
    $schema->resultset('ActionLog')->search()->delete();
829
    ModItem({ location => $location }, $bibnum, $itemnumber, 1, 'True value does trigger logging');
830
    is( $schema->resultset('ActionLog')->count(), 1 );
831
832
    # Undefined defaults to true
833
    $schema->resultset('ActionLog')->search()->delete();
834
    ModItem({ location => $location }, $bibnum, $itemnumber);
835
    is( $schema->resultset('ActionLog')->count(), 1, 'Undefined value defaults to true, triggers logging' );
836
837
    $schema->storage->txn_rollback;
838
};
839
800
# Helper method to set up a Biblio.
840
# Helper method to set up a Biblio.
801
sub get_biblio {
841
sub get_biblio {
802
    my ( $frameworkcode ) = @_;
842
    my ( $frameworkcode ) = @_;
803
- 

Return to bug 18816