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

(-)a/Koha/Item.pm (-8 / +10 lines)
Lines 87-93 sub store { Link Here
87
        $self->itype($self->biblio->biblioitem->itemtype);
87
        $self->itype($self->biblio->biblioitem->itemtype);
88
    }
88
    }
89
89
90
    my $today = dt_from_string;
90
    my $today  = dt_from_string;
91
    my $action = 'create';
92
91
    unless ( $self->in_storage ) { #AddItem
93
    unless ( $self->in_storage ) { #AddItem
92
        unless ( $self->permanent_location ) {
94
        unless ( $self->permanent_location ) {
93
            $self->permanent_location($self->location);
95
            $self->permanent_location($self->location);
Lines 110-122 sub store { Link Here
110
            $self->cn_sort($cn_sort);
112
            $self->cn_sort($cn_sort);
111
        }
113
        }
112
114
113
        logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" )
114
          if $log_action && C4::Context->preference("CataloguingLog");
115
116
        $self->_after_item_action_hooks({ action => 'create' });
117
118
    } else { # ModItem
115
    } else { # ModItem
119
116
117
        $action = 'modify';
118
120
        { # Update *_on  fields if needed
119
        { # Update *_on  fields if needed
121
          # Why not for AddItem as well?
120
          # Why not for AddItem as well?
122
            my @fields = qw( itemlost withdrawn damaged );
121
            my @fields = qw( itemlost withdrawn damaged );
Lines 167-174 sub store { Link Here
167
166
168
        $self->_after_item_action_hooks({ action => 'modify' });
167
        $self->_after_item_action_hooks({ action => 'modify' });
169
168
170
        logaction( "CATALOGUING", "MODIFY", $self->itemnumber, "item " . Dumper($self->unblessed) )
171
          if $log_action && C4::Context->preference("CataloguingLog");
172
    }
169
    }
173
170
174
    unless ( $self->dateaccessioned ) {
171
    unless ( $self->dateaccessioned ) {
Lines 176-181 sub store { Link Here
176
    }
173
    }
177
174
178
    my $result = $self->SUPER::store;
175
    my $result = $self->SUPER::store;
176
    if ( $log_action && C4::Context->preference("CataloguingLog") ) {
177
        $action eq 'create'
178
          ? logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" )
179
          : logaction( "CATALOGUING", "MODIFY", $self->itemnumber, "item " . Dumper( $self->unblessed ) );
180
    }
179
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
181
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
180
    $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" )
182
    $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" )
181
        unless $params->{skip_record_index};
183
        unless $params->{skip_record_index};
(-)a/t/db_dependent/Koha/Items.t (-2 / +42 lines)
Lines 64-70 my $retrieved_item_1 = Koha::Items->find( $new_item_1->itemnumber ); Link Here
64
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' );
64
is( $retrieved_item_1->barcode, $new_item_1->barcode, 'Find a item by id should return the correct item' );
65
65
66
subtest 'store' => sub {
66
subtest 'store' => sub {
67
    plan tests => 4;
67
    plan tests => 5;
68
68
    my $biblio = $builder->build_sample_biblio;
69
    my $biblio = $builder->build_sample_biblio;
69
    my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 );
70
    my $today = dt_from_string->set( hour => 0, minute => 0, second => 0 );
70
    my $item = Koha::Item->new(
71
    my $item = Koha::Item->new(
Lines 82-87 subtest 'store' => sub { Link Here
82
    is( $item->itype, $biblio->biblioitem->itemtype, 'items.itype must have been set to biblioitem.itemtype is not given');
83
    is( $item->itype, $biblio->biblioitem->itemtype, 'items.itype must have been set to biblioitem.itemtype is not given');
83
    is( $item->permanent_location, $item->location, 'permanent_location must have been set to location if not given' );
84
    is( $item->permanent_location, $item->location, 'permanent_location must have been set to location if not given' );
84
    $item->delete;
85
    $item->delete;
86
87
    subtest 'log_action' => sub {
88
        plan tests => 2;
89
        t::lib::Mocks::mock_preference( 'CataloguingLog', 1 );
90
91
        my $item = Koha::Item->new(
92
            {
93
                homebranch    => $library->{branchcode},
94
                holdingbranch => $library->{branchcode},
95
                biblionumber  => $biblio->biblionumber,
96
                location      => 'my_loc',
97
            }
98
        )->store;
99
        is(
100
            Koha::ActionLogs->search(
101
                {
102
                    module => 'CATALOGUING',
103
                    action => 'ADD',
104
                    object => $item->itemnumber,
105
                    info   => 'item'
106
                }
107
            )->count,
108
            1,
109
            "Item creation logged"
110
        );
111
112
        $item->location('another_loc')->store;
113
        is(
114
            Koha::ActionLogs->search(
115
                {
116
                    module => 'CATALOGUING',
117
                    action => 'MODIFY',
118
                    object => $item->itemnumber
119
                }
120
            )->count,
121
            1,
122
            "Item modification logged"
123
        );
124
        $item->delete;
125
    };
85
};
126
};
86
127
87
subtest 'get_transfer' => sub {
128
subtest 'get_transfer' => sub {
88
- 

Return to bug 27003