diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-10-05 22:40:41 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-10-05 22:40:41 (GMT) |
commit | ce9bb78516ae37a2a912a7d4baec01c6d32c4953 (patch) | |
tree | ec6830d18f12133fdafb24528b32ce6dc4da4cf2 | |
parent | 29350f384f80c0d5399edaf90e0c0d66bf3d4427 (diff) |
search for free cart inside group cart range works now
-rwxr-xr-x | lib/RHRD/rddb.pm | 2 | ||||
-rwxr-xr-x | utils/rd-show | 52 |
2 files changed, 47 insertions, 7 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index c4f7642..2ad8297 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -677,7 +677,7 @@ sub get_dropboxes my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.TO_CART,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME = ?;}; if(defined $groupname) { - $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.TO_CART,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME=? and GROUPS.NAME = ?;}; + $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.TO_CART,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME = ? and GROUPS.NAME = ?;}; } my $sth = $ctx->{'dbh'}->prepare($sql) diff --git a/utils/rd-show b/utils/rd-show index c9a71c9..c2db583 100755 --- a/utils/rd-show +++ b/utils/rd-show @@ -79,7 +79,6 @@ sub add__create_group { my ($ctx, $groupname) = @_; - print " > '" . $groupname . "' does not exist - creating it .. "; my ($cnt, $status, $errorstring) = RHRD::rddb::add_group($ctx, $groupname); unless(defined $cnt) { print STDERR $status . ": " . $errorstring . "\n"; @@ -112,7 +111,49 @@ sub add__create_group return $low_cart; } -sub add__get_group_carts +sub add__get_free_group_carts +{ + my ($ctx, $groupname, $num_carts) = @_; + + my ($low_cart, $high_cart, $type, undef) = RHRD::rddb::get_group_carts($ctx, $groupname); + unless(defined $low_cart) { + print STDERR $high_cart . ": " . $type . "\n"; + return undef; + } + + my @dropboxes = RHRD::rddb::get_dropboxes($ctx, 'player', $groupname, 'S'); + if(!defined $dropboxes[0]) { + if(defined $dropboxes[1]) { + print STDERR "$dropboxes[1]: $dropboxes[2]"; + return undef; + } + return $low_cart; + } + + my @carts = (); + for my $db (@dropboxes) { + my @show_carts = RHRD::rddb::get_show_carts($ctx, $db->{'SHOWID'}); + if(!defined $show_carts[0] && defined $show_carts[1]) { + print STDERR "$show_carts[1]: $show_carts[2]\n"; + return undef; + } + @carts = (@carts, @show_carts) if defined($show_carts[0]) + } + + @carts = sort(@carts); + for my $cart (@carts) { + last if(($low_cart + $num_carts - 1) < $cart); + $low_cart += 1; + } + if(($low_cart + $num_carts -1) > $high_cart) { + print STDERR "there are not enough carts free\n"; + return undef; + } + + return $low_cart; +} + +sub add__get_show_carts { my ($ctx, $groupname, $num_carts) = @_; @@ -125,10 +166,9 @@ sub add__get_group_carts my $low_cart = 0; if($result) { print " > using existing group '" . $groupname . "'\n"; - # TODO: - # find free range in group which is big enough for $num_carts carts - + $low_cart = add__get_free_group_carts($ctx, $groupname, $num_carts); } else { + print " > '" . $groupname . "' does not exist - creating it .. "; $low_cart = add__create_group($ctx, $groupname); } @@ -185,7 +225,7 @@ sub add print " * creating show: " . $title . " (" . $name . ") for group '" . $groupname . "'\n"; - my $low_cart = add__get_group_carts($ctx, $groupname, $num_carts); + my $low_cart = add__get_show_carts($ctx, $groupname, $num_carts); return 1 unless defined($low_cart); my $high_cart = $low_cart + $num_carts - 1; print " * will be using carts: " . $low_cart . " - " . $high_cart . "\n"; |