diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-07-30 03:13:05 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-07-30 03:13:05 (GMT) |
commit | 96b197680f423d4afda7c113a1049a656cc81abf (patch) | |
tree | 955506a6f805a92b708933cc189b374480dbbe7e /lib/RHRD/rddb.pm | |
parent | a9748ac28517cd9a6162c797d143d2c1777dc9ed (diff) |
pool creation allmost done
Diffstat (limited to 'lib/RHRD/rddb.pm')
-rwxr-xr-x | lib/RHRD/rddb.pm | 212 |
1 files changed, 209 insertions, 3 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index 81ca9be..b576ad4 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -436,6 +436,133 @@ sub drop_logevent_table return (1, 'OK', 'success'); } +sub get_clock_table_name +{ + my ($clockname) = @_; + $clockname=~s/ /_/g; + return $clockname . '_CLK'; +} + +sub get_clock_table_name_escaped +{ + my ($ctx, $clockname) = @_; + return $ctx->{'dbh'}->quote_identifier(get_clock_table_name($clockname)); +} + +sub create_clock_table +{ + my ($ctx, $clockname) = @_; + + $clockname = get_clock_table_name_escaped($ctx, $clockname); + my $sql = qq{ + create table if not exists $clockname + (ID int unsigned auto_increment not null primary key, + EVENT_NAME char(64) not null, + START_TIME int not null, + LENGTH int not null, + INDEX EVENT_NAME_IDX (EVENT_NAME)); + }; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute() + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + $sth->finish(); + + return (1, 'OK', 'success'); +} + +sub fill_clock_table +{ + my $ctx = shift; + my $clockname = shift; + my @events = @_; + + $clockname = get_clock_table_name_escaped($ctx, $clockname); + my $sql = qq{insert into $clockname (ID, EVENT_NAME, START_TIME, LENGTH) values (?, ?, ?, ?, ?);}; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + my $cnt = 0; + for my $event (@events) { + $sth->execute($cnt + 1, $event->{'NAME'}, $event->{'START_TIME'}, $event->{'LENGTH'}) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + $sth->finish(); + + $cnt++; + } + + return ($cnt+1, 'OK', 'success'); +} + +sub drop_clock_table +{ + my ($ctx, $clockname) = @_; + + $clockname = get_clock_table_name_escaped($ctx, $clockname); + my $sql = qq{drop table $clockname;}; + + $ctx->{'dbh'}->do($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + return (1, 'OK', 'success'); +} + +sub get_clockrules_table_name +{ + my ($clockname) = @_; + $clockname=~s/ /_/g; + return $clockname . '_RULES'; +} + +sub get_clockrules_table_name_escaped +{ + my ($ctx, $clockname) = @_; + return $ctx->{'dbh'}->quote_identifier(get_clockrules_table_name($clockname)); +} + +sub create_clockrules_table +{ + my ($ctx, $clockname) = @_; + + $clockname = get_clockrules_table_name_escaped($ctx, $clockname); + my $sql = qq{ + create table if not exists $clockname + (CODE varchar(10) not null primary key, + MAX_ROW int unsigned, + MIN_WAIT int unsigned, + NOT_AFTER varchar(10), + OR_AFTER varchar(10), + OR_AFTER_II varchar(10)); + }; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute() + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + $sth->finish(); + + return (1, 'OK', 'success'); +} + +sub drop_clockrules_table +{ + my ($ctx, $clockname) = @_; + + $clockname = get_clockrules_table_name_escaped($ctx, $clockname); + my $sql = qq{drop table $clockname;}; + + $ctx->{'dbh'}->do($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + return (1, 'OK', 'success'); +} + ########################### TOKEN handling ########################### sub get_token @@ -1882,6 +2009,7 @@ sub get_musicpool_group unless(defined($groupname)) { return (undef, 'ERROR', "Pool not found"); } + return ($groupname, 'OK', 'success'); } @@ -1945,9 +2073,9 @@ sub get_musicpool_info sub create_musicpool_group { - my ($ctx, $groupname) = @_; + my ($ctx, $groupname, $title) = @_; - my ($cnt, $status, $errorstring) = add_group($ctx, $groupname); + my ($cnt, $status, $errorstring) = add_group($ctx, $groupname, $title); unless(defined $cnt) { return (undef, $status, $errorstring); } @@ -1999,7 +2127,7 @@ sub create_musicpool_event my $sth = $ctx->{'dbh'}->prepare($sql) or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); - $sth->execute($shortname, 'SEGUE, Scheduler', 3, 1, 1, '#' . $color, $groupname, 25) # TODO: make title seperartion configurable !?!? + $sth->execute($shortname, 'SEGUE, Scheduler', 3, 1, 1, $color, $groupname, 25) # TODO: make title seperartion configurable !?!? or return (undef, 'ERROR', "Database Error: " . $sth->errstr); $sth->finish(); @@ -2024,6 +2152,59 @@ sub create_musicpool_event return (1, 'OK', 'success'); } +sub create_musicpool_clock +{ + my ($ctx, $shortname, $color) = @_; + + my $sql = qq{insert into CLOCKS (NAME, SHORT_NAME, ARTISTSEP, COLOR, REMARKS) values (?, ?, ?, ?, '');}; + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($shortname, $shortname, 15, $color) # TODO: make artist seperation configurable !?!? + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + $sth->finish(); + + $sql = qq{insert into CLOCK_PERMS (CLOCK_NAME, SERVICE_NAME) values (?, ?);}; + $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($shortname, $ctx->{'config'}{'shows'}{'service'}) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + $sth->finish(); + + my ($cnt, $status, $errorstring) = create_clock_table($ctx, $shortname); + unless(defined $cnt) { + return (undef, $status, $errorstring); + } + + ## TODO: fill clock table!!!! + + ($cnt, $status, $errorstring) = create_clockrules_table($ctx, $shortname); + unless(defined $cnt) { + return (undef, $status, $errorstring); + } + + return (1, 'OK', 'success'); +} + +sub create_musicpool_dropbox +{ + my ($ctx, $groupname, $shortname) = @_; + my $param = 'M;'; + + my $sql = qq{insert into DROPBOXES (STATION_NAME, GROUP_NAME, NORMALIZATION_LEVEL, AUTOTRIM_LEVEL, PATH, FIX_BROKEN_FORMATS, SET_USER_DEFINED) values (?, ?, ?, ?, ?, 'Y', ?)}; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + my $cnt = $sth->execute($ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'}, $groupname, $ctx->{'config'}{'dropboxes'}{'norm-level'}, $ctx->{'config'}{'dropboxes'}{'trim-level'}, $shortname, $param) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + $sth->finish(); + + return ($cnt, 'OK', 'success'); +} + sub remove_musicpool { my ($ctx, $shortname) = @_; @@ -2033,7 +2214,20 @@ sub remove_musicpool return (undef, $status, $errorstring); } + # TODO: remove grid/clock entries! my @actions = ({ + # Delete Clock Permissions + sql => qq{delete from CLOCK_PERMS where CLOCK_NAME = ?;}, + param => $shortname, + name => 'clock permissions', + cnt => 0 + }, { + # Delete Event + sql => qq{delete from CLOCKS where NAME = ?;}, + param => $shortname, + name => 'clocks', + cnt => 0 + }, { # Delete Event Permissions sql => qq{delete from EVENT_PERMS where EVENT_NAME = ?;}, param => $shortname, @@ -2069,6 +2263,18 @@ sub remove_musicpool } push @actions, { name => 'log-event tables', cnt => ($cnt_pre + $cnt_post) }; + (my $cnt_clk, $status, $errorstring) = drop_clock_table($ctx, $shortname); + unless (defined $cnt_pre) { + return (undef, $status, $errorstring); + } + + (my $cnt_rules, $status, $errorstring) = drop_clockrules_table($ctx, $shortname); + unless (defined $cnt_post) { + return (undef, $status, $errorstring); + } + push @actions, { name => 'clock tables', cnt => ($cnt_clk + $cnt_rules) }; + + my @group_results = remove_group($ctx, $groupname); if(!defined $group_results[0] && defined $group_results[2]) { return (undef, $group_results[1], $group_results[2]); |