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

(-)a/Koha/CirculationRules.pm (+15 lines)
Lines 162-167 sub set_rules { Link Here
162
    return $rule_objects;
162
    return $rule_objects;
163
}
163
}
164
164
165
=head3 delete
166
167
Delete a set of circulation rules, needed for cleaning up when deleting issuingrules
168
169
=cut
170
171
sub delete {
172
    my ( $self ) = @_;
173
174
    while ( my $rule = $self->next ){
175
        $rule->delete;
176
    }
177
178
}
179
165
=head3 type
180
=head3 type
166
181
167
=cut
182
=cut
(-)a/Koha/IssuingRule.pm (-1 / +22 lines)
Lines 31-36 Koha::Hold - Koha Hold object class Link Here
31
31
32
=cut
32
=cut
33
33
34
=head3 delete
35
36
=cut
37
38
sub delete {
39
    my ($self) = @_;
40
41
    my $branchcode = $self->branchcode eq '*' ? undef : $self->branchcode;
42
    my $categorycode = $self->categorycode eq '*' ? undef : $self->categorycode;
43
    my $itemtype = $self->itemtype eq '*' ? undef : $self->itemtype;
44
45
    Koha::CirculationRules->search({
46
        branchcode   => $branchcode,
47
        itemtype     => $itemtype,
48
        categorycode => $categorycode,
49
    })->delete;
50
51
    $self->SUPER::delete;
52
53
}
54
34
=head3 type
55
=head3 type
35
56
36
=cut
57
=cut
Lines 39-42 sub _type { Link Here
39
    return 'Issuingrule';
60
    return 'Issuingrule';
40
}
61
}
41
62
42
1;
63
1;
(-)a/admin/smart-rules.pl (-2 / +6 lines)
Lines 82-89 if ($op eq 'delete') { Link Here
82
    my $categorycode = $input->param('categorycode');
82
    my $categorycode = $input->param('categorycode');
83
    $debug and warn "deleting $1 $2 $branch";
83
    $debug and warn "deleting $1 $2 $branch";
84
84
85
    my $sth_Idelete = $dbh->prepare("delete from issuingrules where branchcode=? and categorycode=? and itemtype=?");
85
    Koha::IssuingRules->find({
86
    $sth_Idelete->execute($branch, $categorycode, $itemtype);
86
        branchcode   => $branch,
87
        categorycode => $categorycode,
88
        itemtype     => $itemtype
89
    })->delete;
90
87
}
91
}
88
elsif ($op eq 'delete-branch-cat') {
92
elsif ($op eq 'delete-branch-cat') {
89
    my $categorycode  = $input->param('categorycode');
93
    my $categorycode  = $input->param('categorycode');
(-)a/t/db_dependent/Koha/CirculationRules.t (-1 / +8 lines)
Lines 33-39 $schema->storage->txn_begin; Link Here
33
my $builder = t::lib::TestBuilder->new;
33
my $builder = t::lib::TestBuilder->new;
34
34
35
subtest 'set_rule + get_effective_rule' => sub {
35
subtest 'set_rule + get_effective_rule' => sub {
36
    plan tests => 11;
36
    plan tests => 13;
37
37
38
    my $categorycode = $builder->build_object( { class => 'Koha::Patron::Categories' } )->categorycode;
38
    my $categorycode = $builder->build_object( { class => 'Koha::Patron::Categories' } )->categorycode;
39
    my $itemtype     = $builder->build_object( { class => 'Koha::ItemTypes' } )->itemtype;
39
    my $itemtype     = $builder->build_object( { class => 'Koha::ItemTypes' } )->itemtype;
Lines 232-237 subtest 'set_rule + get_effective_rule' => sub { Link Here
232
    is( $rule->rule_value, 8,
232
    is( $rule->rule_value, 8,
233
        'More specific rule is returned when branchcode, categorycode and itemtype exist'
233
        'More specific rule is returned when branchcode, categorycode and itemtype exist'
234
    );
234
    );
235
236
    my $our_branch_rules = Koha::CirculationRules->search({branchcode => $branchcode});
237
    is( $our_branch_rules->count, 4, "We added 8 rules");
238
    $our_branch_rules->delete;
239
    is( $our_branch_rules->count, 0, "We deleted 8 rules");
240
241
235
};
242
};
236
243
237
$schema->storage->txn_rollback;
244
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/IssuingRules.t (-2 / +40 lines)
Lines 19-29 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 4;
23
23
24
use Benchmark;
24
use Benchmark;
25
25
26
use Koha::IssuingRules;
26
use Koha::IssuingRules;
27
use Koha::CirculationRules;
27
28
28
use t::lib::TestBuilder;
29
use t::lib::TestBuilder;
29
use t::lib::Mocks;
30
use t::lib::Mocks;
Lines 306-311 subtest 'get_onshelfholds_policy' => sub { Link Here
306
    is( Koha::IssuingRules->get_onshelfholds_policy({ item => $item, patron => $patron }), 2, 'Should be two now' );
307
    is( Koha::IssuingRules->get_onshelfholds_policy({ item => $item, patron => $patron }), 2, 'Should be two now' );
307
};
308
};
308
309
310
subtest 'delete' => sub {
311
    plan tests => 1;
312
313
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
314
    my $library  = $builder->build_object({ class => 'Koha::Libraries' });
315
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
316
317
    # We make an issuing rule
318
    my $issue_rule = $builder->build_object({ class => 'Koha::IssuingRules', value => {
319
            categorycode => $category->categorycode,
320
            itemtype     => $itemtype->itemtype,
321
            branchcode   => $library->branchcode
322
        }
323
    });
324
325
    my $count = Koha::CirculationRules->search()->count;
326
    # Note how many circulation rules we start with
327
328
    # We make some circulation rules for the same thing
329
    $builder->build_object({ class => 'Koha::CirculationRules', value => {
330
            categorycode => $category->categorycode,
331
            itemtype     => $itemtype->itemtype,
332
            branchcode   => $library->branchcode
333
        }
334
    });
335
    $builder->build_object({ class => 'Koha::CirculationRules', value => {
336
            categorycode => $category->categorycode,
337
            itemtype     => $itemtype->itemtype,
338
            branchcode   => $library->branchcode
339
        }
340
    });
341
342
    # Now we delete the issuing rule
343
    $issue_rule->delete;
344
    is( Koha::CirculationRules->search()->count ,$count, "We remove related circ rules with our issuing rule");
345
346
};
347
309
sub _row_match {
348
sub _row_match {
310
    my ($rule, $branchcode, $categorycode, $itemtype) = @_;
349
    my ($rule, $branchcode, $categorycode, $itemtype) = @_;
311
350
312
- 

Return to bug 22679