summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2016-04-27 15:34:02 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2016-04-27 15:34:02 (GMT)
commit29e5b192b58cd020ce44b0c8b19bd5ac73b2cfb4 (patch)
tree4ed28289688955083317a269ae34966e654ee364 /lib
parentec629f278662cc3323bac49ffc5d19bc0cf57a5e (diff)
generating schedule logs works now
Diffstat (limited to 'lib')
-rwxr-xr-xlib/RHRD/rddb.pm68
1 files changed, 63 insertions, 5 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);