diff options
Diffstat (limited to 'rhimport.pm')
-rw-r--r-- | rhimport.pm | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/rhimport.pm b/rhimport.pm index 3cdcf62..353b75d 100644 --- a/rhimport.pm +++ b/rhimport.pm @@ -35,8 +35,6 @@ use DateTime; use DateTime::TimeZone; use LWP::Simple; use XML::Feed; -use DBI; -use Config::IniFiles; my $ssh_host = "airplay"; my $ssh_user = "rhimport"; @@ -91,172 +89,6 @@ sub fetch_parse_rss return XML::Feed->parse(\$xml); } -sub opendb -{ - my $RD_CONF = "/etc/rd.conf"; - my $cfg = Config::IniFiles->new(-file => $RD_CONF) - or return (undef, "Config File Error: " . join("\n", @Config::IniFiles::errors)); - - my $dbhost = $cfg->val('mySQL', 'Hostname'); - my $dbname = $cfg->val('mySQL', 'Database'); - my $dbuser = $cfg->val('mySQL', 'Loginname'); - my $dbpasswd = $cfg->val('mySQL', 'Password'); - - my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost","$dbuser","$dbpasswd") - or return (undef, "Database Error: " . $DBI::errstr); - - $dbh->do(qq{SET CHARACTER SET utf8;}) - or return (undef, "Database Error: " . $dbh->errstr); - - return ($dbh); -} - -sub closedb -{ - my $dbh = shift; - $dbh->disconnect(); -} - -sub get_token -{ - my ($dbh, $username) = @_; - - my $sql = qq{select PASSWORD from USERS where LOGIN_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, "Database Error: " . $dbh->errstr); - - $sth->execute($username) - or return (undef, "Database Error: " . $sth->errstr); - - my ($token) = $sth->fetchrow_array; - $sth->finish(); - - unless(defined $token) { - return (undef, "user '" . $username . "' not known by rivendell") - } - return ($token, 'OK', 'success'); -} - - -sub get_showtitle_and_log -{ - my ($dbh, $showid) = @_; - - my $sql = qq{select TITLE,MACROS from CART where NUMBER = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, undef, "Database Error: " . $dbh->errstr); - - $sth->execute($showid) - or return (undef, undef, "Database Error: " . $sth->errstr); - - my ($title, $macros) = $sth->fetchrow_array; - $sth->finish(); - - unless(defined $title) { - return (undef, undef, "Show with ID=" . $showid . " not found!") - } - unless(defined $macros) { - return (undef, undef, "Show with ID=" . $showid . " has no macro!"); - } - - unless($macros =~ /^LL 1 ([^ ]+) 0\!$/) { - return (undef, undef, "Show with ID=" . $showid . " has invalid macro: '" . $macros . "'"); - } - my $log = $1; - - return ($title, $log); -} - -sub get_dropboxes -{ - my ($dbh, $username) = @_; - - my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.TO_CART,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME=? and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME=?;}; - - my $sth = $dbh->prepare($sql) - or return (undef, "Database Error: " . $dbh->errstr); - - $sth->execute($username, 'import-dropbox') # TODO: hardcoded value - or return (undef, "Database Error: " . $sth->errstr); - - my @allowed_dbs; - while(my ($group, $to_cart, $normlevel, $trimlevel, $params, $lowcart, $highcart, $groupdesc) = $sth->fetchrow_array()) { - my @p = split(';', $params); - - next unless($p[0] eq "S"); - - my $entry = {}; - $entry->{'GROUP'} = $group; - $entry->{'GROUPDESC'} = $groupdesc; - $entry->{'GROUPLOWCART'} = int $lowcart; - $entry->{'GROUPHIGHCART'} = int $highcart; - $entry->{'NORMLEVEL'} = int $normlevel; - $entry->{'TRIMLEVEL'} = int $trimlevel; - $entry->{'PARAM'} = $params; - $entry->{'TYPE'} = 'show'; - $entry->{'SHOWID'} = $to_cart; - - my ($title, $log, $status, $errorstring) = get_showtitle_and_log($dbh, $to_cart); - unless (defined $title && defined $log) { - return (undef, $status, $errorstring); - } - $entry->{'SHOWTITLE'} = $title; - $entry->{'SHOWLOG'} = $log; - - $entry->{'SHOWRHYTHM'} = $p[1]; - $entry->{'SHOWDOW'} = int $p[2]; - $entry->{'SHOWDOW'} = 0 unless $entry->{'SHOWDOW'} < 7; - substr($p[3], 2, 0) = ':'; - $entry->{'SHOWSTARTTIME'} = $p[3]; - $entry->{'SHOWLEN'} = int $p[4]; - - push @allowed_dbs, $entry; - } - $sth->finish(); - - return @allowed_dbs; -} - -sub get_show_carts -{ - my ($dbh, $logname, $group_low_cart, $group_high_cart) = @_; - - my $sql = qq{select LOG_EXISTS from LOGS where NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, "Database Error: " . $dbh->errstr); - - $sth->execute($logname) - or return (undef, "Database Error: " . $sth->errstr); - - my $log_exists = $sth->fetchrow_array; - $sth->finish(); - - if(!defined $log_exists && $log_exists eq 'Y') { - return (undef, "log $logname does not exist") - } - - $logname=~s/ /_/g; - $logname = $dbh->quote_identifier($logname . '_LOG'); - $sql = qq{select COUNT,CART_NUMBER from $logname order by COUNT;}; - - $sth = $dbh->prepare($sql) - or return (undef, "Database Error: " . $dbh->errstr); - - $sth->execute() - or return (undef, "Database Error: " . $sth->errstr); - - my @carts; - while(my ($count, $cart) = $sth->fetchrow_array()) { - if($cart >= $group_low_cart && $cart <= $group_high_cart) { - push @carts, $cart; - } - } - $sth->finish(); - - return @carts; -} - - sub clear_carts { my ($dbh, $group, $to_cart, $progress_cb) = @_; |