From 14eaf97988cf08d211bce667d091427113633864 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Sun, 31 Jul 2016 19:23:40 +0200
Subject: clock filling almost done


diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index d0c2a47..5e6289e 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -481,7 +481,7 @@ sub fill_clock_table
   my @events = @_;
 
   $clockname = get_clock_table_name_escaped($ctx, $clockname);
-  my $sql = qq{insert into $clockname (ID, EVENT_NAME, START_TIME, LENGTH) values (?, ?, ?, ?, ?);};
+  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);
@@ -2203,7 +2203,21 @@ sub create_musicpool_clock
     return (undef, $status, $errorstring);
   }
 
-  ## TODO: fill clock table!!!!
+  my @events = ();
+  my $t = 0;
+  for(my $i=0; $i < 24; $i++) {
+    push @events, { NAME => $shortname, START_TIME => $t, LENGTH => 142500 };
+    $t += 142500;
+    if($i > 0 && ($i % 8) == 0) {
+      $t += 60000;
+      # TODO: push jingle event
+    }
+  }
+
+  (my $next_id, $status, $errorstring) = fill_clock_table($ctx, $shortname, @events);
+  unless (defined $next_id) {
+    return (undef, $status, $errorstring);
+  }
 
   ($cnt, $status, $errorstring) = create_clockrules_table($ctx, $shortname);
   unless(defined $cnt) {
@@ -2346,12 +2360,12 @@ 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) {
+  unless (defined $cnt_clk) {
     return (undef, $status, $errorstring);
   }
 
   (my $cnt_rules, $status, $errorstring) = drop_clockrules_table($ctx, $shortname);
-  unless (defined $cnt_post) {
+  unless (defined $cnt_rules) {
     return (undef, $status, $errorstring);
   }
   push @actions, { name => 'clock tables', cnt => ($cnt_clk + $cnt_rules) };
-- 
cgit v0.10.2