summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/RHRD/rddb.pm68
-rwxr-xr-xutils/rhrd-schedules20
2 files changed, 80 insertions, 8 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index 380a486..a3c4f7a 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -26,6 +26,7 @@ use strict;
use Config::IniFiles;
use DBI;
use RHRD::utils;
+use Date::Calc;
########################### constants ###########################
@@ -68,6 +69,7 @@ sub init
$ctx{'config'}{'shows'}{'service'} = $cfg->val('shows', 'service', '');
$ctx{'config'}{'shows'}{'defaultuser'} = $cfg->val('shows', 'defaultuser', '');
+ $ctx{'config'}{'shows'}{'schedule-lifetime'} = $cfg->val('shows', 'schedule-lifetime', 35);
@{$ctx{'config'}{'shows'}{'logprefix'}} = split(' ', $cfg->val('shows', 'logprefix', ''));
@{$ctx{'config'}{'shows'}{'logsuffix'}} = split(' ', $cfg->val('shows', 'logsuffix', ''));
@@ -303,7 +305,7 @@ sub fill_log_table
my @carts = @_;
$logname = get_log_table_name_escaped($ctx, $logname);
- my $sql_log = qq{insert into $logname (ID, COUNT, TYPE, START_TIME, CART_NUMBER, TRANS_TYPE) values (?, ?, ?, ?, ?, ?);};
+ my $sql_log = qq{insert into $logname (ID, COUNT, TYPE, START_TIME, CART_NUMBER, TRANS_TYPE, TIME_TYPE) values (?, ?, ?, ?, ?, ?, ?);};
my $sql_cart_type = qq{select TYPE from CART where NUMBER = ?;};
my $sth_log = $ctx->{'dbh'}->prepare($sql_log)
@@ -320,7 +322,7 @@ sub fill_log_table
my ($type) = $sth_cart_type->fetchrow_array;
$type = 0 unless(defined($type) && $type == 2);
- $sth_log->execute($cnt + 1, $cnt, $type, $cart->{'START_TIME'}, $cart->{'NUMBER'}, $cart->{'TRANS_TYPE'})
+ $sth_log->execute($cnt + 1, $cnt, $type, $cart->{'START_TIME'}, $cart->{'NUMBER'}, $cart->{'TRANS_TYPE'}, $cart->{'TIME_TYPE'})
or return (undef, 'ERROR', "Database Error: " . $sth_log->errstr);
$sth_log->finish();
@@ -964,6 +966,62 @@ sub list_logs
return @logs;
}
+sub create_schedule_log
+{
+ my $ctx = shift;
+ my $year = shift;
+ my $month = shift;
+ my $day = shift;
+ my @shows = @_;
+
+ my $logname = sprintf("%04d_%02d_%02d", $year, $month, $day);
+ 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 (NAME, LOG_EXISTS, TYPE, DESCRIPTION, ORIGIN_USER, ORIGIN_DATETIME, LINK_DATETIME, SERVICE) values (?, 'N', 0, ?, ?, NOW(), NOW(), ?)};
+
+ my $sth = $ctx->{'dbh'}->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+ $sth->execute($logname, $logname . " schedule", $ctx->{'config'}{'shows'}{'defaultuser'}, $ctx->{'config'}{'shows'}{'service'})
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ $sth->finish();
+
+ (my $result, $status, $errorstring) = create_log_table($ctx, $logname);
+ unless (defined $result) {
+ return (undef, $status, $errorstring);
+ }
+
+ my @carts = ();
+ for my $show (@shows) {
+ push @carts, { NUMBER => $show->{'ID'}, START_TIME => $show->{'START_TIME'}*1000, TRANS_TYPE => 2, TIME_TYPE => 1 };
+ }
+
+ (my $next_id, $status, $errorstring) = fill_log_table($ctx, $logname, @carts);
+ unless (defined $next_id) {
+ return (undef, $status, $errorstring);
+ }
+
+ $sql = qq{update LOGS set LOG_EXISTS='Y', AUTO_REFRESH='Y', NEXT_ID = ?, PURGE_DATE = ? where NAME = ?};
+
+ $sth = $ctx->{'dbh'}->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+ my @purge_date = Date::Calc::Add_Delta_Days($year, $month, $day, $ctx->{'config'}{'shows'}{'schedule-lifetime'});
+ $sth->execute($next_id, sprintf("%04d-%02d-%02d", $purge_date[0], $purge_date[1], $purge_date[2]), $logname)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ $sth->finish();
+
+ return (1, 'OK', 'success');
+}
+
########################### SHOW handling ###########################
sub get_shows_cart_range
@@ -1312,13 +1370,13 @@ sub create_show_log
my @carts = ();
for my $cart (@{$ctx->{'config'}{'shows'}{'logprefix'}}) {
- push @carts, { NUMBER => $cart, START_TIME => 0, TRANS_TYPE => 1 };
+ push @carts, { NUMBER => $cart, START_TIME => 0, TRANS_TYPE => 1, TIME_TYPE => 0 };
}
for my $cart ($low_cart .. $high_cart) {
- push @carts, { NUMBER => $cart, START_TIME => 0, TRANS_TYPE => 0 };
+ push @carts, { NUMBER => $cart, START_TIME => 0, TRANS_TYPE => 0, TIME_TYPE => 0 };
}
for my $cart (@{$ctx->{'config'}{'shows'}{'logsuffix'}}) {
- push @carts, { NUMBER => $cart, START_TIME => 0, TRANS_TYPE => 0 };
+ push @carts, { NUMBER => $cart, START_TIME => 0, TRANS_TYPE => 0, TIME_TYPE => 0 };
}
(my $next_id, $status, $errorstring) = fill_log_table($ctx, $logname, @carts);
diff --git a/utils/rhrd-schedules b/utils/rhrd-schedules
index 1021b76..f6d60ae 100755
--- a/utils/rhrd-schedules
+++ b/utils/rhrd-schedules
@@ -24,7 +24,6 @@ use strict;
# TODO: remove me!!!
use lib "../lib/";
-use Data::Dumper::Simple;
use RHRD::rddb;
use RHRD::utils;
@@ -48,22 +47,37 @@ sub generate
return 1;
}
+ my @shows = ();
for my $entry (@{$data}) {
my $start = DateTime::Format::Strptime::strptime("%Y-%m-%d_%H:%M:%S", ${$entry}{'start'});
my $title = ${$entry}{'title'};
my $pvid = ${$entry}{'id'};
my $showid = ${$entry}{'automation-id'};
+ next if $pvid == 1; # 'Unmoderiertes Musikprogramm'
+
if($start->year != $year || $start->month != $month || $start->day != $day) {
print "WARNING: skipping entry whith invalid start -> $start: $title ($pvid)\n";
next;
}
+ if($showid < 0) {
+ print "WARNING: skipping entry whith invalid/unset automation id -> $start: $title ($pvid)\n";
+ next;
+ }
+
# Rivendell has problems with events starting at midnight
if($start->hour == 0 && $start->minute == 0 && $start->second == 0) {
$start->set_second(1);
}
- print "$start: $showid\n";
+ my $show = {};
+ $show->{'ID'} = $showid;
+ $show->{'START_TIME'} = ($start->hour * 3600) + ($start->minute * 60) + $start->second;
+ push @shows, $show;
+ }
+ my ($result, $status, $errorstring) = RHRD::rddb::create_schedule_log($ctx, $year, $month, $day, @shows);
+ unless(defined $result) {
+ print "$status: $errorstring\n";
+ return 1;
}
- # TODO: create day log in rddb
return 0;
}