-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandhold.pl
46 lines (42 loc) · 1.65 KB
/
randhold.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/perl
use t::lib::TestBuilder;
use Koha::Libraries;
use Koha::Holds;
use Koha::Patrons;
use Koha::DateUtils qw(dt_from_string);
my $libraries = Koha::Libraries->search();
my $builder = t::lib::TestBuilder->new();
while( my $library = $libraries->next) {
my $several = int( rand(10) )+10;
for( my $i = 0; $i < $several; $i++ ){
my $holder = Koha::Patrons->search({},{'order_by'=>\"rand()"})->next;
my $biblio = Koha::Biblios->search({},{'order_by'=>\"rand()"})->next;
next unless $biblio;
my $item = $biblio->items->search({},{ order_by => \["rand()"] })->next;
# Below is to set a 50/50 chance of creating an item level versus next available hold
my $itemnumber = $item && int( rand(2) ) ? $item->itemnumber : undef;
my $hold = $builder->build_object({
class => "Koha::Holds",
value => {
borrowernumber => $holder->borrowernumber,
biblionumber => $biblio->biblionumber,
reservedate => dt_from_string(),
branchcode => $library->branchcode,
desk_id => undef,
cancellationdate => undef,
cancellation_reason => undef,
priority => $biblio->holds->count()+1,
found => undef,
itemnumber => $itemnumber,
waitingdate => undef,
expirationdate => undef,
suspend => 0,
suspend_until=>undef,
item_level_hold => $itemnumber ? 1 : 0,
itemtype => undef,
patron_expiration_date => undef,
}
});
}
}
1;