summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/RHRD/rddb.pm84
-rwxr-xr-xtest/get-dropboxes1
-rwxr-xr-xutils/rhrd-show44
3 files changed, 78 insertions, 51 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index 1064505..14c21a1 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -806,19 +806,37 @@ sub get_dropboxes
{
my ($ctx, $username, $groupname, $type) = @_;
- 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) {
+ my $sql;
+ if(defined $username && !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 = ?;};
+ }
+ elsif(defined $username && 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 = ?;};
}
+ elsif(!defined $username && defined $groupname) {
+ $sql = qq{select GROUPS.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 DROPBOXES, GROUPS where DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME = ? and GROUPS.NAME = ?;};
+ }
+ else {
+ $sql = qq{select GROUPS.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 DROPBOXES, GROUPS where DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME = ?;};
+ }
my $sth = $ctx->{'dbh'}->prepare($sql)
or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
- if(defined $groupname) {
+ if(defined $username && !defined $groupname) {
+ $sth->execute($username, $ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'})
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+ }
+ elsif(defined $username && defined $groupname) {
$sth->execute($username, $ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'}, $groupname)
or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
- } else {
- $sth->execute($username, $ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'})
+ }
+ elsif(!defined $username && defined $groupname) {
+ $sth->execute($ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'}, $groupname)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+ }
+ else {
+ $sth->execute($ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'})
or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
}
@@ -885,7 +903,7 @@ sub list_shows
{
my ($ctx) = @_;
- my $sql = qq{select TO_CART,SET_USER_DEFINED from DROPBOXES where STATION_NAME=?;};
+ my $sql = qq{select TO_CART,SET_USER_DEFINED from DROPBOXES where STATION_NAME=? order by TO_CART;};
my $sth = $ctx->{'dbh'}->prepare($sql)
or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
@@ -920,7 +938,7 @@ sub list_shows
return @show_dbs;
}
-sub get_show_group_carts
+sub get_show_group_cart_range
{
my ($ctx, $showid) = @_;
@@ -938,6 +956,56 @@ sub get_show_group_carts
return ($group_low_cart, $group_high_cart, 'OK', 'success');
}
+sub get_show_group_carts_used
+{
+ my ($ctx, $groupname) = @_;
+
+ my @dropboxes = RHRD::rddb::get_dropboxes($ctx, undef, $groupname, 'S');
+ if(!defined $dropboxes[0]) {
+ if(defined $dropboxes[1]) {
+ return (undef, $dropboxes[1], $dropboxes[2]);
+ }
+ return ();
+ }
+
+ 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]) {
+ return (undef, $show_carts[1], $show_carts[2]);
+ }
+ @carts = (@carts, @show_carts) if defined($show_carts[0])
+ }
+
+ return sort(@carts);
+}
+
+sub get_next_free_show_group_carts
+{
+ my ($ctx, $groupname, $num_carts) = @_;
+
+ my ($low_cart, $high_cart, $type, undef) = get_group_cart_range($ctx, $groupname);
+ unless(defined $low_cart) {
+ return (undef, $high_cart, $type);
+ }
+
+ my @carts = get_show_group_carts_used($ctx, $groupname);
+ if(!defined $carts[0] && defined $carts[1]) {
+ return (undef, $carts[1], $carts[2]);
+ }
+
+ for my $cart (@carts) {
+ last if(($low_cart + $num_carts - 1) < $cart);
+ $low_cart = $cart + 1;
+ }
+ if(($low_cart + $num_carts -1) > $high_cart) {
+ return (undef, 'ERROR', 'not enough free carts left in group');
+ }
+
+ return ($low_cart, 'OK', 'success');
+}
+
+
sub get_show_title_and_log
{
my ($ctx, $showid) = @_;
@@ -971,7 +1039,7 @@ sub get_show_carts
{
my ($ctx, $showid) = @_;
- my ($group_low_cart, $group_high_cart, $status, $errorstring) = get_show_group_carts($ctx, $showid);
+ my ($group_low_cart, $group_high_cart, $status, $errorstring) = get_show_group_cart_range($ctx, $showid);
unless (defined $group_low_cart && defined $group_high_cart) {
return (undef, $status, $errorstring);
}
diff --git a/test/get-dropboxes b/test/get-dropboxes
index 89a4935..577b8e0 100755
--- a/test/get-dropboxes
+++ b/test/get-dropboxes
@@ -27,6 +27,7 @@ use RHRD::rddb;
my $username = $ARGV[0];
+$username = undef if (defined($username) && $username eq '');
my $groupname = $ARGV[1];
$groupname = undef if (defined($groupname) && $groupname eq '');
my $type = $ARGV[2];
diff --git a/utils/rhrd-show b/utils/rhrd-show
index 276eaef..6f3bc7d 100755
--- a/utils/rhrd-show
+++ b/utils/rhrd-show
@@ -127,7 +127,7 @@ sub add__get_show_carts
my $low_cart = 0;
if($result) {
print " > using existing group '" . $groupname . "'\n";
- $low_cart = add__get_free_group_carts($ctx, $groupname, $num_carts);
+ ($low_cart, $status, $errorstring) = RHRD::rddb::get_next_free_show_group_carts($ctx, $groupname, $num_carts);
} else {
print " > '" . $groupname . "' does not exist - creating it .. ";
$low_cart = add__create_group($ctx, $groupname);
@@ -172,48 +172,6 @@ sub add__create_group
return $low_cart;
}
-sub add__get_free_group_carts
-{
- my ($ctx, $groupname, $num_carts) = @_;
-
- my ($low_cart, $high_cart, $type, undef) = RHRD::rddb::get_group_cart_range($ctx, $groupname);
- unless(defined $low_cart) {
- print STDERR $high_cart . ": " . $type . "\n";
- return undef;
- }
-
- my @dropboxes = RHRD::rddb::get_dropboxes($ctx, $ctx->{'config'}{'shows'}{'defaultuser'}, $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 free carts\n";
- return undef;
- }
-
- return $low_cart;
-}
-
sub add
{
my ($ctx, $groupname, $name, $title, $num_carts, $rhythm, $dow, $starttime, $len) = @_;