diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-10-06 00:00:39 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-10-06 00:00:39 (GMT) |
commit | 07713309fa3d14e2ff3926901f7571507f44fa32 (patch) | |
tree | 8129651e1c4812953dcfd390a934b72367229c60 /lib/RHRD | |
parent | ce9bb78516ae37a2a912a7d4baec01c6d32c4953 (diff) |
adding show log works now (needs to filled!
Diffstat (limited to 'lib/RHRD')
-rwxr-xr-x | lib/RHRD/rddb.pm | 149 |
1 files changed, 135 insertions, 14 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index 2ad8297..e3e4b0b 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -35,6 +35,7 @@ use constant { RD_MAX_CART => 999999, RD_MIN_CUT => 1, RD_MAX_CUT => 999, + RD_FADE_DEPTH => -3000, RHRD_CONFIG_FILE => '/etc/rhrd.conf', }; @@ -52,7 +53,7 @@ sub init $ctx{'config'}{'specialgroups'}{'shows'} = $cfg->val('specialgroups', 'shows', 'SHOWS'); $ctx{'config'}{'specialgroups'}{'allshows'} = $cfg->val('specialgroups', 'allshows', 'ALL_SHOWS'); $ctx{'config'}{'specialgroups'}{'allpools'} = $cfg->val('specialgroups', 'allpools', 'ALL_POOLS'); - $ctx{'config'}{'specialgroups'}{'allingles'} = $cfg->val('specialgroups', 'alljingles', 'ALL_JINGLE'); + $ctx{'config'}{'specialgroups'}{'alljingles'} = $cfg->val('specialgroups', 'alljingles', 'ALL_JINGLE'); @{$ctx{'config'}{'specialusers'}{'no-update-token'}} = split(' ', $cfg->val('specialusers', 'no-update-token', '')); @{$ctx{'config'}{'specialusers'}{'admins'}} = split(' ', $cfg->val('specialusers', 'admins', 'admin')); @@ -61,6 +62,11 @@ sub init $ctx{'config'}{'dropboxes'}{'dropbox-pseudo-station'} = $cfg->val('dropboxes', 'dropbox-pseudo-station', 'import-dropbox'); + $ctx{'config'}{'shows'}{'service'} = $cfg->val('shows', 'service', ''); + $ctx{'config'}{'shows'}{'defaultuser'} = $cfg->val('shows', 'defaultuser', ''); + @{$ctx{'config'}{'shows'}{'logprefix'}} = split(' ', $cfg->val('shows', 'logprefix', '')); + @{$ctx{'config'}{'shows'}{'logsuffix'}} = split(' ', $cfg->val('shows', 'logsuffix', '')); + my ($dbh, $status, $errorstring) = opendb(); unless(defined $dbh) { return ($dbh, $status, $errorstring); @@ -170,6 +176,88 @@ sub get_next_free_slot return ($low_cart, $high_cart); } +sub check_log_exists +{ + my ($ctx, $logname) = @_; + + my $sql = qq{select LOG_EXISTS from LOGS where NAME = ?;}; + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($logname) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my $log_exists = $sth->fetchrow_array(); + $sth->finish(); + + if(!defined $log_exists || $log_exists ne 'Y') { + return (0, 'OK', 'log does not exist'); + } + return (1, 'OK', 'log exists'); +} + +sub create_log_table +{ + my ($ctx, $logname) = @_; + + $logname=~s/ /_/g; + $logname = $ctx->{'dbh'}->quote_identifier($logname . '_LOG'); + my $sql = qq{ + create table if not exists $logname + (ID INT NOT NULL PRIMARY KEY, + COUNT INT NOT NULL, + TYPE INT DEFAULT 0, + SOURCE INT NOT NULL, + START_TIME int, + GRACE_TIME int default 0, + CART_NUMBER INT UNSIGNED NOT NULL, + TIME_TYPE INT NOT NULL, + POST_POINT enum('N','Y') default 'N', + TRANS_TYPE INT NOT NULL, + START_POINT INT NOT NULL DEFAULT -1, + END_POINT INT NOT NULL DEFAULT -1, + FADEUP_POINT int default -1, + FADEUP_GAIN int default ?, + FADEDOWN_POINT int default -1, + FADEDOWN_GAIN int default ?, + SEGUE_START_POINT INT NOT NULL DEFAULT -1, + SEGUE_END_POINT INT NOT NULL DEFAULT -1, + SEGUE_GAIN int default ?, + DUCK_UP_GAIN int default 0, + DUCK_DOWN_GAIN int default 0, + COMMENT CHAR(255), + LABEL CHAR(64), + ORIGIN_USER char(255), + ORIGIN_DATETIME datetime, + EVENT_LENGTH int default -1, + LINK_EVENT_NAME char(64), + LINK_START_TIME int, + LINK_LENGTH int default 0, + LINK_START_SLOP int default 0, + LINK_END_SLOP int default 0, + LINK_ID int default -1, + LINK_EMBEDDED enum('N','Y') default 'N', + EXT_START_TIME time, + EXT_LENGTH int, + EXT_CART_NAME char(32), + EXT_DATA char(32), + EXT_EVENT_ID char(32), + EXT_ANNC_TYPE char(8), + index COUNT_IDX (COUNT), + index CART_NUMBER_IDX (CART_NUMBER), + index LABEL_IDX (LABEL)); + }; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute(RD_FADE_DEPTH, RD_FADE_DEPTH, RD_FADE_DEPTH) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + return (1, 'OK', 'success'); +} + + ########################### TOKEN handling ########################### sub get_token @@ -850,25 +938,19 @@ sub get_show_carts return (undef, $status, $errorstring); } - my $sql = qq{select LOG_EXISTS from LOGS where NAME = ?;}; - my $sth = $ctx->{'dbh'}->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); - - $sth->execute($log) - or return (undef, 'ERROR', "Database Error: " . $sth->errstr); - - my $log_exists = $sth->fetchrow_array(); - $sth->finish(); - - if(!defined $log_exists || $log_exists ne 'Y') { + (my $log_exists, $status, $errorstring) = check_log_exists($ctx, $log); + unless (defined $log_exists) { + return (undef, $status, $errorstring); + } + unless($log_exists) { return (undef, 'ERROR', "Log with name '$log' does not exist") } $log=~s/ /_/g; $log = $ctx->{'dbh'}->quote_identifier($log . '_LOG'); - $sql = qq{select COUNT,CART_NUMBER from $log order by COUNT;}; + my $sql = qq{select COUNT,CART_NUMBER from $log order by COUNT;}; - $sth = $ctx->{'dbh'}->prepare($sql) + my $sth = $ctx->{'dbh'}->prepare($sql) or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute() @@ -885,6 +967,45 @@ sub get_show_carts return @carts; } +sub create_show_log +{ + my ($ctx, $logname, $low_cart, $high_cart) = @_; + + my ($log_exists, $status, $errorstring) = check_log_exists($ctx, $logname); + unless (defined $log_exists) { + return (undef, $status, $errorstring); + } + if($log_exists) { + return (undef, 'ERROR', "Log with name '" . $logname . "' already exists") + } + + my $sql = qq{insert into LOGS set NAME = ?, LOG_EXISTS='N', TYPE=0, DESCRIPTION = ?, ORIGIN_USER = ?, ORIGIN_DATETIME=NOW(), LINK_DATETIME=NOW(), SERVICE = ?}; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($logname, $logname . " log", $ctx->{'config'}{'shows'}{'defaultuser'}, $ctx->{'config'}{'shows'}{'service'}) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + (my $result, $status, $errorstring) = create_log_table($ctx, $logname); + unless (defined $result && defined $status) { + return (undef, $status, $errorstring); + } + +# TODO: fill up new log with cart references + my $next_id = 0; + + $sql = qq{update LOGS set LOG_EXISTS='Y', AUTO_REFRESH='Y', NEXT_ID = ? where NAME = ?}; + + $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($next_id, $logname) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + return (1, 'OK', 'success'); +} + ########################### MUSICPOOL handling ########################### sub get_musicpools_cart_range |