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

(-)a/C4/Circulation.pm (-8 / +10 lines)
Lines 1397-1403 sub AddIssue { Link Here
1397
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1397
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1398
                },
1398
                },
1399
                $item->{'biblionumber'},
1399
                $item->{'biblionumber'},
1400
                $item->{'itemnumber'}
1400
                $item->{'itemnumber'},
1401
                0
1401
            );
1402
            );
1402
            ModDateLastSeen( $item->{'itemnumber'} );
1403
            ModDateLastSeen( $item->{'itemnumber'} );
1403
1404
Lines 1830-1836 sub AddReturn { Link Here
1830
            $item->{location} = $item->{permanent_location};
1831
            $item->{location} = $item->{permanent_location};
1831
        }
1832
        }
1832
1833
1833
        ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
1834
        ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'}, 0 );
1834
    }
1835
    }
1835
1836
1836
        # full item data, but no borrowernumber or checkout info (no issue)
1837
        # full item data, but no borrowernumber or checkout info (no issue)
Lines 1854-1860 sub AddReturn { Link Here
1854
            foreach my $key ( keys %$rules ) {
1855
            foreach my $key ( keys %$rules ) {
1855
                if ( $item->{notforloan} eq $key ) {
1856
                if ( $item->{notforloan} eq $key ) {
1856
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} };
1857
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} };
1857
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber );
1858
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, 0 );
1858
                    last;
1859
                    last;
1859
                }
1860
                }
1860
            }
1861
            }
Lines 1920-1926 sub AddReturn { Link Here
1920
1921
1921
        }
1922
        }
1922
1923
1923
        ModItem({ onloan => undef }, $item->{biblionumber}, $item->{'itemnumber'});
1924
        ModItem( { onloan => undef }, $item->{biblionumber}, $item->{itemnumber}, 0 );
1924
    }
1925
    }
1925
1926
1926
    # the holdingbranch is updated if the document is returned to another location.
1927
    # the holdingbranch is updated if the document is returned to another location.
Lines 2156-2162 sub MarkIssueReturned { Link Here
2156
        # And finally delete the issue
2157
        # And finally delete the issue
2157
        $issue->delete;
2158
        $issue->delete;
2158
2159
2159
        ModItem( { 'onloan' => undef }, undef, $itemnumber );
2160
        ModItem( { 'onloan' => undef }, undef, $itemnumber, 0 );
2160
2161
2161
        if ( C4::Context->preference('StoreLastBorrower') ) {
2162
        if ( C4::Context->preference('StoreLastBorrower') ) {
2162
            my $item = Koha::Items->find( $itemnumber );
2163
            my $item = Koha::Items->find( $itemnumber );
Lines 2395-2401 sub _FixAccountForLostAndReturned { Link Here
2395
        }
2396
        }
2396
    );
2397
    );
2397
2398
2398
    ModItem( { paidfor => '' }, undef, $itemnumber );
2399
    ModItem( { paidfor => '' }, undef, $itemnumber, 0 );
2399
2400
2400
    return $credit_id;
2401
    return $credit_id;
2401
}
2402
}
Lines 2820-2826 sub AddRenewal { Link Here
2820
2821
2821
    # Update the renewal count on the item, and tell zebra to reindex
2822
    # Update the renewal count on the item, and tell zebra to reindex
2822
    $renews = $item->{renewals} + 1;
2823
    $renews = $item->{renewals} + 1;
2823
    ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber);
2824
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, 0 );
2824
2825
2825
    # Charge a new rental fee, if applicable?
2826
    # Charge a new rental fee, if applicable?
2826
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2827
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
Lines 3699-3705 sub ProcessOfflineReturn { Link Here
3699
            ModItem(
3700
            ModItem(
3700
                { renewals => 0, onloan => undef },
3701
                { renewals => 0, onloan => undef },
3701
                $issue->{'biblionumber'},
3702
                $issue->{'biblionumber'},
3702
                $itemnumber
3703
                $itemnumber,
3704
                0
3703
            );
3705
            );
3704
            return "Success.";
3706
            return "Success.";
3705
        } else {
3707
        } 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