diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-09-14 20:49:08 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-09-14 21:04:40 (GMT) |
commit | df8affb33e4230860545b4a3e36eb791363a341f (patch) | |
tree | 499fa8229352219fea32db8e773891c87bbd7d6e | |
parent | 444c7d9f9da66309ed0e4e2d6d7050ecc436b0fc (diff) |
implemented multi-edit
-rwxr-xr-x | lib/RHRD/rddb.pm | 32 | ||||
-rwxr-xr-x | utils/rhrd-show | 47 |
2 files changed, 73 insertions, 6 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index 4f8f469..228f76c 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -2064,6 +2064,32 @@ sub create_multi_show return ($number, 'OK', 'success'); } +sub update_multi_show +{ + my $ctx = shift; + my $showid = shift; + my $title = shift; + my %shows = %{shift()}; + + my $showstr = join(";", map { "$_:$shows{$_}" } sort keys %shows); + + my $sql = qq{update CART set TITLE = ?, USER_DEFINED = ? where NUMBER = ?}; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + my $cnt = $sth->execute($title, $showstr, $showid) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + $sth->finish(); + + unless($cnt == 1) { + return (undef, 'ERROR', 'multi-show does not exist'); + } + + return ($cnt, 'OK', 'success'); +} + sub get_multi_show_info { my ($ctx, $showid) = @_; @@ -2073,9 +2099,13 @@ sub get_multi_show_info my $sth = $ctx->{'dbh'}->prepare($sql) or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); - $sth->execute($showid) + my $cnt = $sth->execute($showid) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + unless($cnt == 1) { + return (undef, 'ERROR', 'multi-show does not exist'); + } + my ($title, $shows) = $sth->fetchrow_array(); $sth->finish(); diff --git a/utils/rhrd-show b/utils/rhrd-show index 534f467..af5079c 100755 --- a/utils/rhrd-show +++ b/utils/rhrd-show @@ -38,8 +38,8 @@ 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-id|multi-remove-id) <multi-show-id> <show-id> [ <show-id> [ .. ] ]\n"; + " rhrd-show multi-add <title> <week>=<show-id> [ <week>=<show-id> [ .. ] ]\n" . + " rhrd-show multi-edit <multi-show-id> <title> <week>=<show-id> [ <week>=<show-id> [ .. ] ]\n"; } sub list @@ -314,6 +314,7 @@ sub remove return 0; } + sub multi_list { my ($ctx) = @_; @@ -333,7 +334,7 @@ sub multi_list } -sub multi_add__parse_shows +sub multi__parse_shows { my $ctx = shift; @@ -395,10 +396,11 @@ sub multi_add print " * creating multi-show: " . $title . "\n"; - my %shows = %{multi_add__parse_shows($ctx, @_)}; - unless(%shows) { + my $showref = multi__parse_shows($ctx, @_); + unless(defined($showref)) { return 1; } + my %shows = %{$showref}; my ($result, $status, $errorstring) = RHRD::rddb::create_multi_show($ctx, $title, \%shows); unless(defined $result) { @@ -411,6 +413,30 @@ sub multi_add return 0; } +sub multi_edit +{ + my $ctx = shift; + my $showid = shift; + my $title = shift; + + print " * updating multi-show: " . $showid . "\n"; + + my $showref = multi__parse_shows($ctx, @_); + unless(defined($showref)) { + return 1; + } + my %shows = %{$showref}; + + my ($result, $status, $errorstring) = RHRD::rddb::update_multi_show($ctx, $showid, $title, \%shows); + unless(defined $result) { + print STDERR $status . ": " . $errorstring . "\n"; + return 1; + } + + print " * mulit-show '" . $showid . "' successfully changed!\n"; + return 0; +} + sub multi_show { my ($ctx, $showid) = @_; @@ -553,6 +579,17 @@ if(defined $ctx) { $ret = multi_remove($ctx, $ARGV[1]); } } + elsif($cmd eq "multi-edit") { + if($num_args < 4) { + print_usage(); + $ret = 1; + } else { + shift @ARGV; + my $showid = shift @ARGV; + my $title = shift @ARGV; + $ret = multi_edit($ctx, $showid, $title, @ARGV) + } + } else { print_usage(); $ret = 1; |