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

(-)a/C4/Stats.pm (-2 / +2 lines)
Lines 48-61 The functions of this module deals with statistics table of Koha database. Link Here
48
48
49
    C4::Stats::UpdateStats($params);
49
    C4::Stats::UpdateStats($params);
50
50
51
    This is a (legacy) alias for Koha::Statistic->insert($params).
51
    This is a (legacy) alias for Koha::Statistic->new($params)->store.
52
    Please see Koha::Statistic module.
52
    Please see Koha::Statistic module.
53
53
54
=cut
54
=cut
55
55
56
sub UpdateStats {
56
sub UpdateStats {
57
    my $params = shift;
57
    my $params = shift;
58
    Koha::Statistic->insert($params);
58
    Koha::Statistic->new($params)->store;
59
}
59
}
60
60
61
1;
61
1;
(-)a/Koha/Item.pm (-10 / +12 lines)
Lines 231-246 sub store { Link Here
231
231
232
sub _add_statistic {
232
sub _add_statistic {
233
    my ( $self, $type ) = @_;
233
    my ( $self, $type ) = @_;
234
    C4::Stats::UpdateStats({
234
    C4::Stats::UpdateStats(
235
        type           => $type,
235
        {
236
        branch         => C4::Context->userenv ? C4::Context->userenv->{branch} : undef,
236
            borrowernumber => undef,
237
        borrowernumber => undef,
237
            branch         => C4::Context->userenv ? C4::Context->userenv->{branch} : undef,
238
        categorycode   => undef,
238
            categorycode   => undef,
239
        itemnumber     => $self->itemnumber,
239
            ccode          => $self->ccode,
240
        ccode          => $self->ccode,
240
            itemnumber     => $self->itemnumber,
241
        itemtype       => $self->effective_itemtype,
241
            itemtype       => $self->effective_itemtype,
242
        location       => $self->location,
242
            location       => $self->location,
243
    });
243
            type           => $type,
244
        }
245
    );
244
}
246
}
245
247
246
=head3 delete
248
=head3 delete
(-)a/Koha/Statistic.pm (-16 lines)
Lines 129-150 sub store { Link Here
129
    return $self;
129
    return $self;
130
}
130
}
131
131
132
=head3 insert
133
134
    Koha::Statistic->insert( $params );
135
136
    This is a shorthand for ->new($params)->store.
137
    It is the new equivalent for the legacy C4::Stats::UpdateStats call.
138
139
=cut
140
141
sub insert {
142
    my ( $class, $params ) = @_;
143
    my $statistic = $class->new($params) or return;
144
    $statistic->store;
145
    return $statistic;
146
}
147
148
=head3 item
132
=head3 item
149
133
150
    my $item = $statistic->item;
134
    my $item = $statistic->item;
(-)a/t/db_dependent/Koha/Statistics.t (-5 / +4 lines)
Lines 52-58 subtest 'Basic Koha object tests' => sub { Link Here
52
    my $item    = $builder->build_sample_item;
52
    my $item    = $builder->build_sample_item;
53
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
53
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
54
54
55
    Koha::Statistic->insert(
55
    Koha::Statistic->new(
56
        {
56
        {
57
            type           => 'issue',
57
            type           => 'issue',
58
            branch         => $library->branchcode,
58
            branch         => $library->branchcode,
Lines 63-69 subtest 'Basic Koha object tests' => sub { Link Here
63
            ccode          => $item->ccode,
63
            ccode          => $item->ccode,
64
            interface      => C4::Context->interface,
64
            interface      => C4::Context->interface,
65
        }
65
        }
66
    );
66
    )->store;
67
67
68
    my $stat = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next;
68
    my $stat = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next;
69
    is( $stat->borrowernumber,   $patron->borrowernumber, 'Patron is there' );
69
    is( $stat->borrowernumber,   $patron->borrowernumber, 'Patron is there' );
Lines 107-113 subtest 'Test exceptions in ->new' => sub { Link Here
107
    $schema->storage->txn_rollback;
107
    $schema->storage->txn_rollback;
108
};
108
};
109
109
110
subtest 'Test ->insert (fka UpdateStats)' => sub {
110
subtest 'Test new->store (fka UpdateStats)' => sub {
111
    plan tests => 15;
111
    plan tests => 15;
112
    $schema->storage->txn_begin;
112
    $schema->storage->txn_begin;
113
113
Lines 154-160 subtest 'Test ->insert (fka UpdateStats)' => sub { Link Here
154
154
155
sub insert_and_fetch {
155
sub insert_and_fetch {
156
    my $params    = shift;
156
    my $params    = shift;
157
    my $statistic = Koha::Statistic->insert($params);
157
    my $statistic = Koha::Statistic->new($params)->store;
158
    return Koha::Statistics->search( { borrowernumber => $test_params->{borrowernumber} } )->last;
158
    return Koha::Statistics->search( { borrowernumber => $test_params->{borrowernumber} } )->last;
159
159
160
    # FIXME discard_changes would be nicer, but we dont have a PK (yet)
160
    # FIXME discard_changes would be nicer, but we dont have a PK (yet)
161
- 

Return to bug 33608