summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-09-14 20:05:48 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-09-14 20:05:48 (GMT)
commit308a989ca62ba7d97fa7a60a8940d9d2b6dbb7b7 (patch)
tree99a547c57e955dbc0540a6980bf26614e54a29bb
parent043bcc2f9a395458c18f369f06ac876d26a9b814 (diff)
harmonized input output values for mulit-show lib functions
-rwxr-xr-xlib/RHRD/rddb.pm6
-rwxr-xr-xutils/rhrd-show53
2 files changed, 31 insertions, 28 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index d4ff7a5..5e0afbc 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -2036,7 +2036,9 @@ sub create_multi_show
{
my $ctx = shift;
my $title = shift;
- my $shows = join(";", @_);
+ my %shows = %{shift()};
+
+ my $showstr = join(";", map { "$_:$shows{$_}" } sort keys %shows);
my ($number, $status, $errorstring) = get_next_free_multi_showid($ctx);
unless (defined $number) {
@@ -2048,7 +2050,7 @@ sub create_multi_show
my $sth = $ctx->{'dbh'}->prepare($sql)
or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
- $sth->execute($number, $ctx->{'config'}{'specialgroups'}{'multishows'}, $title, $shows)
+ $sth->execute($number, $ctx->{'config'}{'specialgroups'}{'multishows'}, $title, $showstr)
or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
$sth->finish();
diff --git a/utils/rhrd-show b/utils/rhrd-show
index dad0800..d4646ba 100755
--- a/utils/rhrd-show
+++ b/utils/rhrd-show
@@ -38,7 +38,7 @@ sub print_usage
" multi show handling:\n" .
" rhrd-show multi-list\n" .
" rhrd-show (multi-show|multi-remove) <multi-show-id>\n" .
- " rhrd-show (multi-add) <title> <week>:<show-id> [ <week>:<show-id> [ .. ] ]\n" .
+ " rhrd-show (multi-add) <title> <week>=<show-id> [ <week>=<show-id> [ .. ] ]\n" .
" rhrd-show (multi-add-id|multi-remove-id) <multi-show-id> <show-id> [ <show-id> [ .. ] ]\n";
}
@@ -333,80 +333,81 @@ sub multi_list
}
-sub multi_add__check_shows
+sub multi_add__parse_shows
{
my $ctx = shift;
- my @shows = @_;
- my %weeks = ( 1 => 0, 2 => 0, 3 => 0, 4 => 0 );
-
- foreach my $show (@shows) {
- my ($week, $show_id) = split(':', $show, 2);
+ my %shows = ( 1 => 0, 2 => 0, 3 => 0, 4 => 0 );
+ foreach my $show (@_) {
+ my ($week, $show_id) = split('=', $show, 2);
unless(defined $week && defined $show_id) {
- print STDERR "'" . $show . "' is invalid, needs to have format <week>:<showid>\n";
- return 1;
+ print STDERR "'" . $show . "' is invalid, needs to have format <week>=<showid>\n";
+ return undef;
}
$week = int($week);
if($week < 1 || $week > 4) {
print STDERR "week '" . $week . "' is out of range (needs to be 1,2,3 or 4)\n";
- return 1;
+ return undef;
}
- if($weeks{$week} != 0) {
- print STDERR "week " . $week . " is already set to show-id $weeks{$week}\n";
- return 1;
+ if($shows{$week} != 0) {
+ print STDERR "week " . $week . " is already set to show-id $shows{$week}\n";
+ return undef;
}
$show_id = int($show_id);
my ($show_id_min, $show_id_max, $errorstring) = RHRD::rddb::get_showid_range($ctx);
unless(defined $show_id_min) {
print STDERR $show_id_max . ": " . $errorstring . "\n";
- return 1;
+ return undef;
}
if ($show_id < $show_id_min || $show_id > $show_id_max) {
print STDERR "show-id '" . $show_id . "' is out of range (min: $show_id_min, max: $show_id_max)\n";
- return 1;
+ return undef;
}
(my $exists, my $status, $errorstring) = RHRD::rddb::check_show_exists($ctx, $show_id);
unless(defined $exists) {
print STDERR $status . ": " . $errorstring . "\n";
- return 1;
+ return undef;
}
if($exists != 1) {
print STDERR "show with id '" . $show_id . "' does not exist!\n";
- return 1;
+ return undef;
}
(my $title, undef, $status, $errorstring) = RHRD::rddb::get_show_title_and_log($ctx, $show_id);
unless(defined $title) {
print STDERR $status . ": " . $errorstring . "\n";
- return 1;
+ return undef;
}
- $weeks{$week} = $show_id;
+ $shows{$week} = $show_id;
- print "W$week: ($show_id) $title\n";
+ print " - W$week: ($show_id) $title\n";
}
- return 0;
+ return \%shows;
}
sub multi_add
{
my $ctx = shift;
my $title = shift;
- my @shows = @_;
- my $ret = multi_add__check_shows($ctx, @shows);
- if($ret) {
- return $ret;
+ print " * creating multi-show: " . $title . "\n";
+
+ my %shows = %{multi_add__parse_shows($ctx, @_)};
+ unless(%shows) {
+ return 1;
}
- my ($result, $status, $errorstring) = RHRD::rddb::create_multi_show($ctx, $title, @shows);
+ my ($result, $status, $errorstring) = RHRD::rddb::create_multi_show($ctx, $title, \%shows);
unless(defined $result) {
print STDERR $status . ": " . $errorstring . "\n";
return 1;
}
+ print " * finished\n";
+
return 0;
}