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

(-)a/C4/Circulation.pm (-8 / +10 lines)
Lines 1416-1422 sub AddIssue { Link Here
1416
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1416
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1417
                },
1417
                },
1418
                $item->{'biblionumber'},
1418
                $item->{'biblionumber'},
1419
                $item->{'itemnumber'}
1419
                $item->{'itemnumber'},
1420
                0
1420
            );
1421
            );
1421
            ModDateLastSeen( $item->{'itemnumber'} );
1422
            ModDateLastSeen( $item->{'itemnumber'} );
1422
1423
Lines 1854-1860 sub AddReturn { Link Here
1854
            $item->{location} = $item->{permanent_location};
1855
            $item->{location} = $item->{permanent_location};
1855
        }
1856
        }
1856
1857
1857
        ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
1858
        ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'}, 0 );
1858
    }
1859
    }
1859
1860
1860
        # full item data, but no borrowernumber or checkout info (no issue)
1861
        # full item data, but no borrowernumber or checkout info (no issue)
Lines 1878-1884 sub AddReturn { Link Here
1878
            foreach my $key ( keys %$rules ) {
1879
            foreach my $key ( keys %$rules ) {
1879
                if ( $item->{notforloan} eq $key ) {
1880
                if ( $item->{notforloan} eq $key ) {
1880
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} };
1881
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} };
1881
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber );
1882
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, 0 );
1882
                    last;
1883
                    last;
1883
                }
1884
                }
1884
            }
1885
            }
Lines 1950-1956 sub AddReturn { Link Here
1950
1951
1951
        }
1952
        }
1952
1953
1953
        ModItem({ onloan => undef }, $item->{biblionumber}, $item->{'itemnumber'});
1954
        ModItem( { onloan => undef }, $item->{biblionumber}, $item->{itemnumber}, 0 );
1954
    }
1955
    }
1955
1956
1956
    # the holdingbranch is updated if the document is returned to another location.
1957
    # the holdingbranch is updated if the document is returned to another location.
Lines 2186-2192 sub MarkIssueReturned { Link Here
2186
        # And finally delete the issue
2187
        # And finally delete the issue
2187
        $issue->delete;
2188
        $issue->delete;
2188
2189
2189
        ModItem( { 'onloan' => undef }, undef, $itemnumber );
2190
        ModItem( { 'onloan' => undef }, undef, $itemnumber, 0 );
2190
2191
2191
        if ( C4::Context->preference('StoreLastBorrower') ) {
2192
        if ( C4::Context->preference('StoreLastBorrower') ) {
2192
            my $item = Koha::Items->find( $itemnumber );
2193
            my $item = Koha::Items->find( $itemnumber );
Lines 2425-2431 sub _FixAccountForLostAndReturned { Link Here
2425
        }
2426
        }
2426
    );
2427
    );
2427
2428
2428
    ModItem( { paidfor => '' }, undef, $itemnumber );
2429
    ModItem( { paidfor => '' }, undef, $itemnumber, 0 );
2429
2430
2430
    return $credit_id;
2431
    return $credit_id;
2431
}
2432
}
Lines 2842-2848 sub AddRenewal { Link Here
2842
2843
2843
    # Update the renewal count on the item, and tell zebra to reindex
2844
    # Update the renewal count on the item, and tell zebra to reindex
2844
    $renews = $item->{renewals} + 1;
2845
    $renews = $item->{renewals} + 1;
2845
    ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber);
2846
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, 0 );
2846
2847
2847
    # Charge a new rental fee, if applicable?
2848
    # Charge a new rental fee, if applicable?
2848
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2849
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
Lines 3718-3724 sub ProcessOfflineReturn { Link Here
3718
            ModItem(
3719
            ModItem(
3719
                { renewals => 0, onloan => undef },
3720
                { renewals => 0, onloan => undef },
3720
                $issue->{'biblionumber'},
3721
                $issue->{'biblionumber'},
3721
                $itemnumber
3722
                $itemnumber,
3723
                0
3722
            );
3724
            );
3723
            return "Success.";
3725
            return "Success.";
3724
        } else {
3726
        } else {
(-)a/C4/Items.pm (-6 / +11 lines)
Lines 518-524 sub ModItemFromMarc { Link Here
518
518
519
=head2 ModItem
519
=head2 ModItem
520
520
521
  ModItem({ column => $newvalue }, $biblionumber, $itemnumber);
521
  ModItem({ column => $newvalue }, $biblionumber, $itemnumber, $log_action );
522
522
523
Change one or more columns in an item record and update
523
Change one or more columns in an item record and update
524
the MARC representation of the item.
524
the MARC representation of the item.
Lines 539-550 the derived value of a column such as C<items.cn_sort>, Link Here
539
this routine will perform the necessary calculation
539
this routine will perform the necessary calculation
540
and set the value.
540
and set the value.
541
541
542
If log_action is set to false, the action will not be logged.
543
If log_action is true or undefined, the action will be logged.
544
542
=cut
545
=cut
543
546
544
sub ModItem {
547
sub ModItem {
545
    my $item = shift;
548
    my $item = shift;
546
    my $biblionumber = shift;
549
    my $biblionumber = shift;
547
    my $itemnumber = shift;
550
    my $itemnumber = shift;
551
    my $log_action = shift // 1;
548
552
549
    # if $biblionumber is undefined, get it from the current item
553
    # if $biblionumber is undefined, get it from the current item
550
    unless (defined $biblionumber) {
554
    unless (defined $biblionumber) {
Lines 553-560 sub ModItem { Link Here
553
557
554
    my $dbh           = @_ ? shift : C4::Context->dbh;
558
    my $dbh           = @_ ? shift : C4::Context->dbh;
555
    my $frameworkcode = @_ ? shift : C4::Biblio::GetFrameworkCode( $biblionumber );
559
    my $frameworkcode = @_ ? shift : C4::Biblio::GetFrameworkCode( $biblionumber );
556
    
560
557
    my $unlinked_item_subfields;  
561
    my $unlinked_item_subfields;
558
    if (@_) {
562
    if (@_) {
559
        $unlinked_item_subfields = shift;
563
        $unlinked_item_subfields = shift;
560
        $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields);
564
        $item->{'more_subfields_xml'} = _get_unlinked_subfields_xml($unlinked_item_subfields);
Lines 603-609 sub ModItem { Link Here
603
    # item status is possible
607
    # item status is possible
604
    ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
608
    ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
605
609
606
    logaction("CATALOGUING", "MODIFY", $itemnumber, "item ".Dumper($item)) if C4::Context->preference("CataloguingLog");
610
    logaction( "CATALOGUING", "MODIFY", $itemnumber, "item " . Dumper($item) )
611
      if $log_action && C4::Context->preference("CataloguingLog");
607
}
612
}
608
613
609
=head2 ModItemTransfer
614
=head2 ModItemTransfer
Lines 645-653 C<$itemnum> is the item number Link Here
645
650
646
sub ModDateLastSeen {
651
sub ModDateLastSeen {
647
    my ($itemnumber) = @_;
652
    my ($itemnumber) = @_;
648
    
653
649
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
654
    my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
650
    ModItem({ itemlost => 0, datelastseen => $today }, undef, $itemnumber);
655
    ModItem( { itemlost => 0, datelastseen => $today }, undef, $itemnumber, 0 );
651
}
656
}
652
657
653
=head2 DelItem
658
=head2 DelItem
(-)a/t/db_dependent/Items.t (-2 / +42 lines)
Lines 26-32 use Koha::Library; Link Here
26
use t::lib::Mocks;
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
27
use t::lib::TestBuilder;
28
28
29
use Test::More tests => 12;
29
use Test::More tests => 13;
30
30
31
use Test::Warn;
31
use Test::Warn;
32
32
Lines 797-802 subtest 'get_hostitemnumbers_of' => sub { Link Here
797
    is( @itemnumbers, 0, );
797
    is( @itemnumbers, 0, );
798
};
798
};
799
799
800
subtest 'Test logging for AddItem' => sub {
801
802
    plan tests => 3;
803
804
    t::lib::Mocks::mock_preference('CataloguingLog', 1);
805
806
    $schema->storage->txn_begin;
807
808
    my $builder = t::lib::TestBuilder->new;
809
    my $library = $builder->build({
810
        source => 'Branch',
811
    });
812
    my $itemtype = $builder->build({
813
        source => 'Itemtype',
814
    });
815
816
    # Create a biblio instance for testing
817
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
818
    my ($bibnum, $bibitemnum) = get_biblio();
819
820
    # Add an item.
821
    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, itype => $itemtype->{itemtype} } , $bibnum);
822
823
    # False means no logging
824
    $schema->resultset('ActionLog')->search()->delete();
825
    ModItem({ location => $location }, $bibnum, $itemnumber, 0);
826
    is( $schema->resultset('ActionLog')->count(), 0, 'False value does not trigger logging' );
827
828
    # True means logging
829
    $schema->resultset('ActionLog')->search()->delete();
830
    ModItem({ location => $location }, $bibnum, $itemnumber, 1, 'True value does trigger logging');
831
    is( $schema->resultset('ActionLog')->count(), 1 );
832
833
    # Undefined defaults to true
834
    $schema->resultset('ActionLog')->search()->delete();
835
    ModItem({ location => $location }, $bibnum, $itemnumber);
836
    is( $schema->resultset('ActionLog')->count(), 1, 'Undefined value defaults to true, triggers logging' );
837
838
    $schema->storage->txn_rollback;
839
};
840
800
# Helper method to set up a Biblio.
841
# Helper method to set up a Biblio.
801
sub get_biblio {
842
sub get_biblio {
802
    my ( $frameworkcode ) = @_;
843
    my ( $frameworkcode ) = @_;
803
- 

Return to bug 18816