diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-09-30 23:05:11 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-09-30 23:05:11 (GMT) |
commit | 6f1943313a0e503189dd9685483a9ecd1bd7cc6e (patch) | |
tree | 7461bd743125feb61a7f977a06e7698bb184d333 /lib | |
parent | 88ba274e7841fedffe9ef98b0933c0610ac6997c (diff) |
introduced rhrd context
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/RHRD/rddb.pm | 248 |
1 files changed, 134 insertions, 114 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index 894c03e..9155d8e 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -31,12 +31,12 @@ use DBI; use constant { DB_VERSION => 245, RD_CONFIG_FILE => '/etc/rd.conf', - DROPBOX_PSEUDO_STATION_NAME => 'import-dropbox', RD_MIN_CART => 1, RD_MAX_CART => 999999, RD_MIN_CUT => 1, RD_MAX_CUT => 999, + RHRD_DROPBOX_PSEUDO_STATION_NAME => 'import-dropbox', RHRD_SYSTEM_MACROS_GROUP => 'SYSTEM', RHRD_SHOW_MACROS_GROUP => 'SHOWS', RHRD_ALLSHOWS_GROUP => 'ALL_SHOWS', @@ -44,7 +44,27 @@ use constant { RHRD_ALLJINGLES_GROUP => 'ALL_JINGLE', }; -########################### connection handling ########################### +########################### context handling ########################### + +sub init +{ + my %ctx; + + my ($dbh, $status, $errorstring) = opendb(); + unless(defined $dbh) { + return ($dbh, $status, $errorstring); + } + $ctx{'dbh'} = $dbh; + + return \%ctx; +} + +sub destroy +{ + my ($ctx) = @_; + + closedb($ctx->{'dbh'}); +} sub opendb { @@ -91,11 +111,11 @@ sub closedb sub get_cart_range { - my ($dbh, $groupname) = @_; + my ($ctx, $groupname) = @_; my $sql = qq{select DEFAULT_LOW_CART, DEFAULT_HIGH_CART, DEFAULT_TITLE from GROUPS where NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($groupname) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -110,13 +130,13 @@ sub get_cart_range sub get_next_free_slot { - my ($dbh, $groupname) = @_; + my ($ctx, $groupname) = @_; - my ($group_low_cart, $group_high_cart, $group_chunksize) = get_cart_range($dbh, $groupname); + my ($group_low_cart, $group_high_cart, $group_chunksize) = get_cart_range($ctx, $groupname); my $sql = qq{select NAME, DEFAULT_LOW_CART, DEFAULT_HIGH_CART from GROUPS where NAME != ? and DEFAULT_LOW_CART >= ? and DEFAULT_HIGH_CART <= ? order by DEFAULT_LOW_CART;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($groupname, $group_low_cart, $group_high_cart) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -144,11 +164,11 @@ sub get_next_free_slot sub get_token { - my ($dbh, $username) = @_; + my ($ctx, $username) = @_; my $sql = qq{select PASSWORD from USERS where LOGIN_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($username) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -164,14 +184,14 @@ sub get_token sub set_token { - my ($dbh, $username, $token) = @_; + my ($ctx, $username, $token) = @_; if(!defined $token || $token eq '') { return (undef, 'ERROR', "empty token is not allowed") } my $sql = qq{update USERS set PASSWORD = ? where LOGIN_NAME = ?;}; - my $rows = $dbh->do($sql, undef, $token, $username) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $rows = $ctx->{'dbh'}->do($sql, undef, $token, $username) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); unless($rows == 1) { return (undef, 'ERROR', "user '" . $username . "' not known by rivendell") @@ -181,14 +201,14 @@ sub set_token sub check_token { - my ($dbh, $username, $token) = @_; + my ($ctx, $username, $token) = @_; if(!defined $token || $token eq '') { return (undef, 'ERROR', "empty token is not allowed") } my $sql = qq{select PASSWORD from USERS where LOGIN_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($username) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -210,7 +230,7 @@ sub check_token sub add_user { - my ($dbh, $username, $token, $fullname) = @_; + my ($ctx, $username, $token, $fullname) = @_; if(!defined $token || $token eq '') { return (undef, 'ERROR', "empty token is not allowed") } @@ -219,8 +239,8 @@ sub add_user } my $sql = qq{insert into USERS (LOGIN_NAME, FULL_NAME, PHONE_NUMBER, DESCRIPTION, PASSWORD, ENABLE_WEB, ADMIN_USERS_PRIV, ADMIN_CONFIG_PRIV, CREATE_CARTS_PRIV, DELETE_CARTS_PRIV, MODIFY_CARTS_PRIV, EDIT_AUDIO_PRIV, ASSIGN_CART_PRIV, CREATE_LOG_PRIV, DELETE_LOG_PRIV, DELETE_REC_PRIV, PLAYOUT_LOG_PRIV, ARRANGE_LOG_PRIV, MODIFY_TEMPLATE_PRIV, ADDTO_LOG_PRIV, REMOVEFROM_LOG_PRIV, CONFIG_PANELS_PRIV, VOICETRACK_LOG_PRIV, EDIT_CATCHES_PRIV, ADD_PODCAST_PRIV, EDIT_PODCAST_PRIV, DELETE_PODCAST_PRIV) values ( ?, ?, "", "", ? , "N", "N", "N", "Y", "Y", "Y", "Y", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N");}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); my $cnt = $sth->execute($username, $fullname, $token) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -231,7 +251,7 @@ sub add_user sub remove_user { - my ($dbh, $username) = @_; + my ($ctx, $username) = @_; my @actions = ({ # Delete RSS Feed Perms @@ -256,8 +276,8 @@ sub remove_user }); for my $href (@actions) { - my $sth = $dbh->prepare($href->{sql}) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($href->{sql}) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); delete($href->{sql}); $href->{cnt} = $sth->execute($username) @@ -271,11 +291,11 @@ sub remove_user sub check_user { - my ($dbh, $username) = @_; + my ($ctx, $username) = @_; my $sql = qq{select count(*) from USERS where LOGIN_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($username) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -285,8 +305,8 @@ sub check_user if ($cnt != 0) { $sql = qq{select count(*) from STATIONS where DEFAULT_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($username) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -303,11 +323,11 @@ sub check_user sub get_fullname { - my ($dbh, $username) = @_; + my ($ctx, $username) = @_; my $sql = qq{select FULL_NAME from USERS where LOGIN_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($username) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -323,11 +343,11 @@ sub get_fullname sub list_users { - my ($dbh) = @_; + my ($ctx) = @_; my $sql = qq{select LOGIN_NAME from USERS order by LOGIN_NAME;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute() or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -345,14 +365,14 @@ sub list_users sub add_group { - my ($dbh, $groupname, $description) = @_; + my ($ctx, $groupname, $description) = @_; if(!defined $description) { $description = ''; } my $sql = qq{insert into GROUPS (NAME, DESCRIPTION) values (?, ?);}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); my $cnt = $sth->execute($groupname, $description) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -363,7 +383,7 @@ sub add_group sub remove_group { - my ($dbh, $groupname) = @_; + my ($ctx, $groupname) = @_; my @actions = ({ # Delete Member Carts @@ -398,8 +418,8 @@ sub remove_group }); for my $href (@actions) { - my $sth = $dbh->prepare($href->{sql}) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($href->{sql}) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); delete($href->{sql}); $href->{cnt} = $sth->execute($groupname) @@ -413,11 +433,11 @@ sub remove_group sub check_group { - my ($dbh, $groupname) = @_; + my ($ctx, $groupname) = @_; my $sql = qq{select count(*) from GROUPS where NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($groupname) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -427,8 +447,8 @@ sub check_group if ($cnt != 0) { $sql = qq{select count(*) from CART where GROUP_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($groupname) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -445,11 +465,11 @@ sub check_group sub get_group_carts { - my ($dbh, $groupname) = @_; + my ($ctx, $groupname) = @_; my $sql = qq{select DEFAULT_LOW_CART, DEFAULT_HIGH_CART, DEFAULT_CART_TYPE, ENFORCE_CART_RANGE from GROUPS where NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($groupname) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -464,7 +484,7 @@ sub get_group_carts sub set_group_carts { - my ($dbh, $groupname, $low_cart, $high_cart, $cart_type, $enforce_cart_range) = @_; + my ($ctx, $groupname, $low_cart, $high_cart, $cart_type, $enforce_cart_range) = @_; if(!defined $low_cart) { $low_cart = 0; } @@ -479,8 +499,8 @@ sub set_group_carts } my $sql = qq{update GROUPS set DEFAULT_LOW_CART = ?, DEFAULT_HIGH_CART = ?, DEFAULT_CART_TYPE = ? , ENFORCE_CART_RANGE = ? where NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); my $cnt = $sth->execute($low_cart, $high_cart, $cart_type, $enforce_cart_range, $groupname) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -492,11 +512,11 @@ sub set_group_carts sub get_group_reports { - my ($dbh, $groupname) = @_; + my ($ctx, $groupname) = @_; my $sql = qq{select ENABLE_NOW_NEXT, REPORT_TFC, REPORT_MUS from GROUPS where NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($groupname) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -511,7 +531,7 @@ sub get_group_reports sub set_group_reports { - my ($dbh, $groupname, $now_next, $traffic, $music) = @_; + my ($ctx, $groupname, $now_next, $traffic, $music) = @_; if(!defined $now_next) { $now_next = 'N'; } @@ -523,8 +543,8 @@ sub set_group_reports } my $sql = qq{update GROUPS set ENABLE_NOW_NEXT = ?, REPORT_TFC = ?, REPORT_MUS = ? where NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); my $cnt = $sth->execute($now_next, $traffic, $music, $groupname) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -536,11 +556,11 @@ sub set_group_reports sub get_group_members { - my ($dbh, $groupname) = @_; + my ($ctx, $groupname) = @_; my $sql = qq{select USER_NAME from USER_PERMS where GROUP_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($groupname) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -556,11 +576,11 @@ sub get_group_members sub is_group_member { - my ($dbh, $groupname, $username) = @_; + my ($ctx, $groupname, $username) = @_; my $sql = qq{select count(*) from USER_PERMS where GROUP_NAME = ? and USER_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($groupname, $username) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -573,11 +593,11 @@ sub is_group_member sub add_group_member { - my ($dbh, $groupname, $username) = @_; + my ($ctx, $groupname, $username) = @_; my $sql = qq{select count(*) from USERS where LOGIN_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($username) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -588,14 +608,14 @@ sub add_group_member return (undef, 'ERROR', "user '" . $username . "' does not exist"); } - ($cnt, my $result, my $errostring) = is_group_member($dbh, $groupname, $username); + ($cnt, my $result, my $errostring) = is_group_member($ctx, $groupname, $username); if($cnt > 0) { return (undef, 'ERROR', "already a member"); } $sql = qq{insert into USER_PERMS (GROUP_NAME, USER_NAME) values (?, ?);}; - $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $cnt = $sth->execute($groupname, $username) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -606,11 +626,11 @@ sub add_group_member sub remove_group_member { - my ($dbh, $groupname, $username) = @_; + my ($ctx, $groupname, $username) = @_; my $sql = qq{delete from USER_PERMS where GROUP_NAME = ? and USER_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); my $cnt = $sth->execute($groupname, $username) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -621,11 +641,11 @@ sub remove_group_member sub list_groups { - my ($dbh) = @_; + my ($ctx) = @_; my $sql = qq{select NAME from GROUPS order by DEFAULT_LOW_CART;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute() or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -643,21 +663,21 @@ sub list_groups sub get_dropboxes { - my ($dbh, $username, $groupname, $type) = @_; + my ($ctx, $username, $groupname, $type) = @_; 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 = ?;}; if(defined $groupname) { $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=? and GROUPS.NAME = ?;}; } - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); if(defined $groupname) { - $sth->execute($username, DROPBOX_PSEUDO_STATION_NAME, $groupname) + $sth->execute($username, RHRD_DROPBOX_PSEUDO_STATION_NAME, $groupname) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); } else { - $sth->execute($username, DROPBOX_PSEUDO_STATION_NAME) + $sth->execute($username, RHRD_DROPBOX_PSEUDO_STATION_NAME) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); } @@ -678,7 +698,7 @@ sub get_dropboxes $entry->{'TYPE'} = 'show'; $entry->{'SHOWID'} = $to_cart; - my ($title, $log, $status, $errorstring) = get_show_title_and_log($dbh, $to_cart); + my ($title, $log, $status, $errorstring) = get_show_title_and_log($ctx, $to_cart); unless (defined $title && defined $log) { return (undef, $status, $errorstring); } @@ -710,26 +730,26 @@ sub get_dropboxes sub get_shows_cart_range { - my ($dbh) = @_; - return get_cart_range($dbh, RHRD_ALLSHOWS_GROUP) + my ($ctx) = @_; + return get_cart_range($ctx, RHRD_ALLSHOWS_GROUP) } sub get_shows_next_free_slot { - my ($dbh) = @_; - return get_next_free_slot($dbh, RHRD_ALLSHOWS_GROUP) + my ($ctx) = @_; + return get_next_free_slot($ctx, RHRD_ALLSHOWS_GROUP) } sub list_shows { - my ($dbh) = @_; + my ($ctx) = @_; my $sql = qq{select TO_CART,SET_USER_DEFINED from DROPBOXES where STATION_NAME=?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); - $sth->execute(DROPBOX_PSEUDO_STATION_NAME) + $sth->execute(RHRD_DROPBOX_PSEUDO_STATION_NAME) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); my @show_dbs; @@ -739,7 +759,7 @@ sub list_shows my $entry = {}; $entry->{'ID'} = $to_cart; - my ($title, $log, $status, $errorstring) = get_show_title_and_log($dbh, $to_cart); + my ($title, $log, $status, $errorstring) = get_show_title_and_log($ctx, $to_cart); unless (defined $title && defined $log) { return (undef, $status, $errorstring); } @@ -761,13 +781,13 @@ sub list_shows sub get_show_group_carts { - my ($dbh, $showid) = @_; + my ($ctx, $showid) = @_; my $sql = qq{select GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART from DROPBOXES, GROUPS where DROPBOXES.TO_CART = ? and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); - $sth->execute($showid, DROPBOX_PSEUDO_STATION_NAME) + $sth->execute($showid, RHRD_DROPBOX_PSEUDO_STATION_NAME) or return (undef, undef, 'ERROR', "Database Error: " . $sth->errstr); my ($group_low_cart, $group_high_cart) = $sth->fetchrow_array(); @@ -779,11 +799,11 @@ sub get_show_group_carts sub get_show_title_and_log { - my ($dbh, $showid) = @_; + my ($ctx, $showid) = @_; my $sql = qq{select TITLE,MACROS from CART where NUMBER = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, undef, 'ERROR', "Database Error: " . $dbh->errstr); + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute($showid) or return (undef, undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -808,21 +828,21 @@ sub get_show_title_and_log sub get_show_carts { - my ($dbh, $showid) = @_; + my ($ctx, $showid) = @_; - my ($group_low_cart, $group_high_cart, $status, $errorstring) = get_show_group_carts($dbh, $showid); + my ($group_low_cart, $group_high_cart, $status, $errorstring) = get_show_group_carts($ctx, $showid); unless (defined $group_low_cart && defined $group_high_cart) { return (undef, $status, $errorstring); } - (undef, my $log, $status, $errorstring) = get_show_title_and_log($dbh, $showid); + (undef, my $log, $status, $errorstring) = get_show_title_and_log($ctx, $showid); unless (defined $log) { return (undef, $status, $errorstring); } my $sql = qq{select LOG_EXISTS from LOGS where NAME = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + 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); @@ -835,11 +855,11 @@ sub get_show_carts } $log=~s/ /_/g; - $log = $dbh->quote_identifier($log . '_LOG'); + $log = $ctx->{'dbh'}->quote_identifier($log . '_LOG'); $sql = qq{select COUNT,CART_NUMBER from $log order by COUNT;}; - $sth = $dbh->prepare($sql) - or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); $sth->execute() or return (undef, 'ERROR', "Database Error: " . $sth->errstr); @@ -859,28 +879,28 @@ sub get_show_carts sub get_musicpools_cart_range { - my ($dbh) = @_; - return get_cart_range($dbh, RHRD_ALLMUSICPOOLS_GROUP) + my ($ctx) = @_; + return get_cart_range($ctx, RHRD_ALLMUSICPOOLS_GROUP) } sub get_musicpools_next_free_slot { - my ($dbh) = @_; - return get_next_free_slot($dbh, RHRD_ALLMUSICPOOLS_GROUP) + my ($ctx) = @_; + return get_next_free_slot($ctx, RHRD_ALLMUSICPOOLS_GROUP) } ########################### JINGLES handling ########################### sub get_jingles_cart_range { - my ($dbh) = @_; - return get_cart_range($dbh, RHRD_ALLJINGLES_GROUP) + my ($ctx) = @_; + return get_cart_range($ctx, RHRD_ALLJINGLES_GROUP) } sub get_jingles_next_free_slot { - my ($dbh) = @_; - return get_next_free_slot($dbh, RHRD_ALLJINGLES_GROUP) + my ($ctx) = @_; + return get_next_free_slot($ctx, RHRD_ALLJINGLES_GROUP) } ################################# END #################################### |