config cache issues

By default the configuration cached by the mod_perl2 instance.
You can disable cache by setting cache/config=0.
You should disable cache only if you have multiple calcms instances
running on the same mod_perl2 server with different configuration.

The Location of the configuration will be determined by config module
now.
This commit is contained in:
Milan
2018-09-22 21:39:20 +02:00
parent e043493847
commit afa56e9e1e
12 changed files with 303 additions and 293 deletions

View File

@@ -3,6 +3,7 @@ package config;
use warnings; use warnings;
use strict; use strict;
use FindBin();
use Config::General(); use Config::General();
use base 'Exporter'; use base 'Exporter';
@@ -19,7 +20,7 @@ sub set {
sub get { sub get {
my $filename = shift; my $filename = shift;
return $config if defined $config;; return $config if ( defined $config ) && ( $config->{cache}->{cache_config} == 1 );
my $configuration = Config::General->new( my $configuration = Config::General->new(
-ConfigFile => $filename, -ConfigFile => $filename,
@@ -29,5 +30,11 @@ sub get {
return $config; return $config;
} }
sub getFromScriptLocation() {
FindBin::again();
my $configFile = $FindBin::Bin . '/config/config.cgi';
return config::get($configFile);
}
#do not delete last line #do not delete last line
1; 1;

View File

@@ -23,7 +23,7 @@ binmode STDOUT, ":utf8";
my $r=shift; my $r=shift;
(my $cgi, my $params, my $error)=params::get($r); (my $cgi, my $params, my $error)=params::get($r);
my $config = config::get('./config/config.cgi'); my $config = config::getFromScriptLocation();
my $debug = $config->{system}->{debug}; my $debug = $config->{system}->{debug};
my $request={ my $request={

View File

@@ -21,7 +21,8 @@ if ( $0 =~ /aggregate.*?\.cgi$/ ) {
my %params = $cgi->Vars(); my %params = $cgi->Vars();
my $params = \%params; my $params = \%params;
my $config = config::get('config/config.cgi'); my $config = config::getFromScriptLocation();
my $debug = $config->{system}->{debug}; my $debug = $config->{system}->{debug};
my $mem_debug = $config->{system}->{debug_memory}; my $mem_debug = $config->{system}->{debug_memory};
my $base_dir = $config->{locations}->{base_dir}; my $base_dir = $config->{locations}->{base_dir};
@@ -32,9 +33,9 @@ if ( $0 =~ /aggregate.*?\.cgi$/ ) {
$output_header .= "Content-type:text/html; charset=UTF-8;\n\n"; $output_header .= "Content-type:text/html; charset=UTF-8;\n\n";
} }
$params->{exclude_locations} = 1; $params->{exclude_locations} = 1;
$params->{exclude_projects} = 1; $params->{exclude_projects} = 1;
$params->{exclude_event_images} = 1; $params->{exclude_event_images} = 1;
# $output_header.='<!DOCTYPE html>'."\n"; # $output_header.='<!DOCTYPE html>'."\n";
my $request = { my $request = {
@@ -71,9 +72,9 @@ if ( $0 =~ /aggregate.*?\.cgi$/ ) {
my $menu = { content => '' }; my $menu = { content => '' };
$list->{day} = '' unless defined $list->{day}; $list->{day} = '' unless defined $list->{day};
$list->{day} = $params->{date} if (defined $params->{date}) && ($params->{date} ne ''); $list->{day} = $params->{date} if ( defined $params->{date} ) && ( $params->{date} ne '' );
$list->{day} = $params->{from_date} if (defined $params->{from_date}) && ($params->{from_date} ne ''); $list->{day} = $params->{from_date} if ( defined $params->{from_date} ) && ( $params->{from_date} ne '' );
$list->{day} = 'today' if $list->{day} eq ''; $list->{day} = 'today' if $list->{day} eq '';
$menu = aggregator::get_menu( $config, $request, $list->{day}, $list->{results} ); $menu = aggregator::get_menu( $config, $request, $list->{day}, $list->{results} );
@@ -121,15 +122,15 @@ if ( $0 =~ /aggregate.*?\.cgi$/ ) {
$content =~ s/(<(div|span)\s+id="calcms_title".*?>).*?(<\/(div|span)>)/$list->{project_title}/g; $content =~ s/(<(div|span)\s+id="calcms_title".*?>).*?(<\/(div|span)>)/$list->{project_title}/g;
my $values = []; my $values = [];
for my $value ($list->{'program'}, $list->{'series_name'}, $list->{'title'}, $list->{'location'}, $list->{'project_title'}){ for my $value ( $list->{'program'}, $list->{'series_name'}, $list->{'title'}, $list->{'location'}, $list->{'project_title'} ) {
next unless defined $value; next unless defined $value;
next if $value eq ''; next if $value eq '';
push @$values, $value; push @$values, $value;
} }
my $title = join (' - ', @$values); my $title = join( ' - ', @$values );
$content=~s/(<title>)(.*?)(<\/title>)/$1$title$3/; $content =~ s/(<title>)(.*?)(<\/title>)/$1$title$3/;
$js = ''; $js = '';
if ( ( defined $list->{event_id} ) && ( $list->{event_id} ne '' ) ) { if ( ( defined $list->{event_id} ) && ( $list->{event_id} ne '' ) ) {

View File

@@ -22,7 +22,7 @@ binmode STDOUT, ":encoding(UTF-8)";
if ( $0 =~ /cal.*?\.cgi$/ ) { if ( $0 =~ /cal.*?\.cgi$/ ) {
( my $cgi, my $params, my $error ) = params::get($r); ( my $cgi, my $params, my $error ) = params::get($r);
my $config = config::get('config/config.cgi'); my $config = config::getFromScriptLocation();
my $debug = $config->{system}->{debug}; my $debug = $config->{system}->{debug};
my $request = { my $request = {

View File

@@ -21,27 +21,26 @@ binmode STDOUT, ":utf8";
my $r = shift; my $r = shift;
( my $cgi, my $params, my $error ) = params::get($r); ( my $cgi, my $params, my $error ) = params::get($r);
my $config = config::get('config/config.cgi'); my $config = config::getFromScriptLocation();
my $debug = $config->{system}->{debug}; my $debug = $config->{system}->{debug};
my $request = { my $request = {
url => $ENV{QUERY_STRING}, url => $ENV{QUERY_STRING},
params => { params => {
original => $params, original => $params,
checked => check_params( $config, $params ), checked => check_params( $config, $params ),
}, },
}; };
$params = $request->{params}->{checked}; $params = $request->{params}->{checked};
my $cache = {}; my $cache = {};
if ( $config->{cache}->{use_cache} eq '1' ) { if ( $config->{cache}->{use_cache} eq '1' ) {
cache::configure('categories.html'); cache::configure('categories.html');
$cache = cache::load( $config, $params ); $cache = cache::load( $config, $params );
if ( defined $cache->{content} ) { if ( defined $cache->{content} ) {
print $cache->{content}; print $cache->{content};
return; return;
} }
} }
my $dbh = db::connect($config); my $dbh = db::connect($config);
@@ -56,87 +55,87 @@ $template_parameters->{use_client_cache} = $config->{cache}->{use_client_cache}
my $template = $params->{template}; my $template = $params->{template};
my $out = ''; my $out = '';
template::process($config, $out, $params->{template}, $template_parameters ); template::process( $config, $out, $params->{template}, $template_parameters );
print $out; print $out;
#write to cache #write to cache
if ( $config->{cache}->{use_cache} eq '1' ) { if ( $config->{cache}->{use_cache} eq '1' ) {
$cache->{content} = $out; $cache->{content} = $out;
cache::save($cache); cache::save($cache);
} }
sub getProjects { sub getProjects {
my $dbh = shift; my $dbh = shift;
my $config = shift; my $config = shift;
my $excludedProjects = {}; my $excludedProjects = {};
if ( defined $config->{filter}->{projects_to_exclude} ) { if ( defined $config->{filter}->{projects_to_exclude} ) {
for my $project ( split( /\,/, $config->{filter}->{projects_to_exclude} ) ) { for my $project ( split( /\,/, $config->{filter}->{projects_to_exclude} ) ) {
$project =~ s/^\s+//g; $project =~ s/^\s+//g;
$project =~ s/\s+$//g; $project =~ s/\s+$//g;
$excludedProjects->{$project} = 1; $excludedProjects->{$project} = 1;
} }
} }
my $projects = project::get_sorted($config); my $projects = project::get_sorted($config);
my $results = []; my $results = [];
for my $project (@$projects) { for my $project (@$projects) {
next if defined $excludedProjects->{ $project->{name} }; next if defined $excludedProjects->{ $project->{name} };
my $categories = getCategories( $dbh, $config, $project->{name} ); my $categories = getCategories( $dbh, $config, $project->{name} );
$project->{isEmpty} = 1 if scalar(@$categories) == 0; $project->{isEmpty} = 1 if scalar(@$categories) == 0;
$project->{categories} = $categories; $project->{categories} = $categories;
$project->{js_name} = $project->{name}; $project->{js_name} = $project->{name};
$project->{js_name} =~ s/[^a-zA-Z\_0-9]/\_/g; $project->{js_name} =~ s/[^a-zA-Z\_0-9]/\_/g;
$project->{js_name} =~ s/\_+/\_/g; $project->{js_name} =~ s/\_+/\_/g;
push @$results, $project; push @$results, $project;
} }
return $results; return $results;
} }
sub getCategories { sub getCategories {
my $dbh = shift; my $dbh = shift;
my $config = shift; my $config = shift;
my $project = shift; my $project = shift;
my $cond = ''; my $cond = '';
my $bind_values = []; my $bind_values = [];
if ( ( $project ne '' ) && ( $project ne 'all' ) ) { if ( ( $project ne '' ) && ( $project ne 'all' ) ) {
$cond = 'where project=?'; $cond = 'where project=?';
$bind_values = [$project]; $bind_values = [$project];
} }
my $query = qq{ my $query = qq{
select name, count(name) sum select name, count(name) sum
from calcms_categories from calcms_categories
$cond $cond
group by name group by name
order by sum desc, name order by sum desc, name
}; };
my $categories = db::get( $dbh, $query, $bind_values ); my $categories = db::get( $dbh, $query, $bind_values );
my $results = []; my $results = [];
for my $category (@$categories) { for my $category (@$categories) {
push @$results, $category if $category->{sum} > 1; push @$results, $category if $category->{sum} > 1;
} }
return $results; return $results;
} }
sub check_params { sub check_params {
my $config = $_[0]; my $config = $_[0];
my $params = $_[1]; my $params = $_[1];
my $template = template::check($config, $params->{template}, 'categories.html' ); my $template = template::check( $config, $params->{template}, 'categories.html' );
my $debug = $params->{debug} || ''; my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) { if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1; $debug = $1;
} }
return { return {
template => $template, template => $template,
debug => $debug debug => $debug
}; };
} }

View File

@@ -6,7 +6,6 @@ no warnings 'redefine';
use Data::Dumper; use Data::Dumper;
#use utf8;
use DBI; use DBI;
use CGI qw(header param Vars); use CGI qw(header param Vars);
$CGI::POST_MAX = 1000; $CGI::POST_MAX = 1000;
@@ -18,35 +17,32 @@ use log();
use events(); use events();
use time(); use time();
#binmode STDOUT, ":utf8";
binmode STDOUT, ":encoding(UTF-8)"; binmode STDOUT, ":encoding(UTF-8)";
my $r = shift; my $r = shift;
( my $cgi, my $params, my $error ) = params::get($r); ( my $cgi, my $params, my $error ) = params::get($r);
if ( $0 =~ /events.*?\.cgi$/ ) { if ( $0 =~ /events.*?\.cgi$/ ) {
#my $cgi=new CGI(); my $config = config::getFromScriptLocation();
#my %params=$cgi->Vars();
our $config = config::get('config/config.cgi');
$params->{template} = '' unless defined $params->{template}; $params->{template} = '' unless defined $params->{template};
$params->{recordings} = 1 if $params->{template} =~ /events_playout/; $params->{recordings} = 1 if $params->{template} =~ /events_playout/;
$params->{exclude_locations} = 1; $params->{exclude_locations} = 1;
$params->{exclude_projects} = 1; $params->{exclude_projects} = 1;
$params->{exclude_event_images} = 1; $params->{exclude_event_images} = 1;
my $request = { my $request = {
url => $ENV{QUERY_STRING}, url => $ENV{QUERY_STRING},
params => { params => {
original => $params, original => $params,
checked => events::check_params( $config, $params ), checked => events::check_params( $config, $params ),
}, },
}; };
my $output = ''; my $output = '';
events::get_cached_or_render( $output, $config, $request ); events::get_cached_or_render( $output, $config, $request );
print $output. "\n"; print $output. "\n";
} }
1; 1;

View File

@@ -1417,6 +1417,7 @@ sub print_event {
my $attr = ''; my $attr = '';
if ( $class =~ /play/ ) { if ( $class =~ /play/ ) {
#$event->{rms_image}=~s/\.png/.svg/;
$attr .= ' rms="' . $event->{rms_image} . '"' if defined $event->{rms_image}; $attr .= ' rms="' . $event->{rms_image} . '"' if defined $event->{rms_image};
$attr .= ' start="' . $event->{start} . '"' if defined $event->{start}; $attr .= ' start="' . $event->{start} . '"' if defined $event->{start};
} }

View File

@@ -39,9 +39,9 @@ my $user_presets = uac::get_user_presets(
); );
$params->{default_studio_id} = $user_presets->{studio_id}; $params->{default_studio_id} = $user_presets->{studio_id};
$params->{studio_id} = $params->{default_studio_id} $params->{studio_id} = $params->{default_studio_id}
if ( ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' ) ); if ( !defined $params->{action} ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' );
$params->{project_id} = $user_presets->{project_id} $params->{project_id} = $user_presets->{project_id}
if ( ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' ) ); if ( !defined $params->{action} ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' );
#print STDERR $params->{project_id}."\n"; #print STDERR $params->{project_id}."\n";
my $request = { my $request = {
@@ -87,9 +87,14 @@ sub show_events {
my $params = $request->{params}->{checked}; my $params = $request->{params}->{checked};
my $permissions = $request->{permissions}; my $permissions = $request->{permissions};
unless ( $permissions->{assign_series_events} == 1 ) { unless ( $permissions->{assign_series_events} == 1 ) {
uac::permissions_denied('assign_series_events'); uac::permissions_denied('read_events');
return; return;
} }
my $events = getDates( $config, $request );
$params->{events} = $events;
$params->{total} = scalar(@$events);
$params->{action} = 'show';
template::process( $config, 'print', $params->{template}, $params ); template::process( $config, 'print', $params->{template}, $params );
} }
@@ -106,6 +111,31 @@ sub create_events {
} }
print STDERR "create events\n"; print STDERR "create events\n";
my $dates = getDates( $config, $request );
print STDERR "<pre>found " . ( scalar @$dates ) . " dates\n";
my $events = [];
for my $date (@$dates) {
#print STDERR $date->{start}."\n";
push @$events, createEvent( $config, $request, $date );
}
$params->{events} = $events;
$params->{total} = scalar(@$events);
$params->{action} = 'created';
template::process( $config, 'print', $params->{template}, $params );
}
sub getDates {
my $config = shift;
my $request = shift;
my $params = $request->{params}->{checked};
my $permissions = $request->{permissions};
unless ( $permissions->{read_event} == 1 ) {
uac::permissions_denied('read_event');
return;
}
my $project_id = $params->{project_id}; my $project_id = $params->{project_id};
my $studio_id = $params->{studio_id}; my $studio_id = $params->{studio_id};
@@ -126,8 +156,7 @@ sub create_events {
} }
$params->{from_date} = $from_date; $params->{from_date} = $from_date;
$params->{till_date} = $till_date; $params->{till_date} = $till_date;
print STDERR "$0: get events from $from_date to $till_date\n";
print STDERR "create events from $from_date to $till_date\n";
my $dates = series_dates::getDatesWithoutEvent( my $dates = series_dates::getDatesWithoutEvent(
$config, $config,
@@ -138,16 +167,8 @@ sub create_events {
till => $till_date till => $till_date
} }
); );
print STDERR "<pre>found " . ( scalar @$dates ) . " dates\n";
my $events = [];
for my $date (@$dates) {
#print STDERR $date->{start}."\n"; return $dates;
push @$events, createEvent( $config, $request, $date );
}
$params->{created_events} = $events;
$params->{created_total} = scalar(@$events);
template::process( $config, 'print', $params->{template}, $params );
} }
sub createEvent { sub createEvent {
@@ -191,7 +212,7 @@ sub check_params {
#actions and roles #actions and roles
$checked->{action} = ''; $checked->{action} = '';
if ( defined $params->{action} ) { if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(create_events)$/ ) { if ( $params->{action} =~ /^(create_events|show_events)$/ ) {
$checked->{action} = $params->{action}; $checked->{action} = $params->{action};
} }
} }

View File

@@ -1,33 +1,17 @@
<TMPL_IF .allow.scan_series_events> <TMPL_IF .allow.read_event> <script type="text/javascript">
<TMPL_IF .getBack>
<script type="text/javascript"> $(document).ready(function() {
<TMPL_IF .getBack> getBack()
$(document).ready( });
function(){ </TMPL_IF>
getBack()
}
);
</TMPL_IF>
function assign_series(project_id, studio_id){
if (project_id == '') return false;
if (studio_id == '') return false;
var url="create_events.cgi?project_id="+project_id+'&studio_id='+studio_id+'&action=create_events';
$('#create_event_form').submit();
return false;
}
</script> </script>
<h1>create events from schedule</h1> <h1>create events from schedule</h1>
<form id="create_event_form"> <form id="create_event_form" method="post">
<input type="hidden" name="project_id" value="<TMPL_VAR .project_id>"> <input type="hidden" name="project_id"
<input type="hidden" name="studio_id" value="<TMPL_VAR .studio_id>"> value="<TMPL_VAR .project_id>"> <input type="hidden"
<input type="hidden" name="action" value="create_events"> name="studio_id" value="<TMPL_VAR .studio_id>"> duration
duration
<select name="duration"> <select name="duration">
<option value="7">1 week</option> <option value="7">1 week</option>
<option value="14">2 weeks</option> <option value="14">2 weeks</option>
@@ -35,20 +19,25 @@ function assign_series(project_id, studio_id){
<option value="28">4 weeks</option> <option value="28">4 weeks</option>
</select> </select>
<button target="_blank" <TMPL_IF .allow.read_event>
onclick="assign_series('<TMPL_VAR .project_id>', '<TMPL_VAR .studio_id>');return false;" <button target="_blank" type='submit' name="action" value="show">show</button>
>create</button> </TMPL_IF>
<TMPL_IF .allow.assign_series_events>
<button target="_blank" type='submit' name="action"
value="create_events">create</button>
</TMPL_IF>
</form> </form>
<div class="view" style="clear:both"> <div class="view" style="clear: both">
created <TMPL_VAR created_total> events from <TMPL_VAR from_date> till <TMPL_VAR till_date><br> <TMPL_VAR action> <TMPL_VAR created_total>
<TMPL_LOOP created_events> events created events from <TMPL_VAR from_date> till <TMPL_VAR till_date>
<TMPL_var start><TMPL_var full_title><br> <br>
</TMPL_LOOP>
</view> <TMPL_LOOP events> <TMPL_var start> <TMPL_var
full_title> <br></TMPL_LOOP> </view>
</body> </body>
</html> </html>
<TMPL_ELSE> missing permission to read events
</TMPL_IF> </TMPL_IF>

View File

@@ -16,8 +16,7 @@ print "Content-Type: text/html; charset=utf-8\n\n";
my $r = shift; my $r = shift;
( my $cgi, my $params, my $error ) = params::get($r); ( my $cgi, my $params, my $error ) = params::get($r);
my $config = config::get('config/config.cgi'); my $config = config::getFromScriptLocation();
$params = check_params( $config, $params ); $params = check_params( $config, $params );
list_series( $config, $params ); list_series( $config, $params );

View File

@@ -2,6 +2,7 @@
#use utf8; #use utf8;
use warnings "all"; use warnings "all";
#use diagnostics; #use diagnostics;
use strict; use strict;
use Data::Dumper; use Data::Dumper;
@@ -23,17 +24,16 @@ binmode STDOUT, ":utf8";
my $r = shift; my $r = shift;
( my $cgi, my $params, my $error ) = params::get($r); ( my $cgi, my $params, my $error ) = params::get($r);
my $config = config::get('config/config.cgi'); my $config = config::getFromScriptLocation();
my $debug = $config->{system}->{debug}; my $debug = $config->{system}->{debug};
#get request #get request
my $request = { my $request = {
url => $ENV{QUERY_STRING}, url => $ENV{QUERY_STRING},
params => { params => {
original => $params, original => $params,
checked => check_params( $config, $params ) checked => check_params( $config, $params )
}, },
}; };
$params = $request->{params}->{checked}; $params = $request->{params}->{checked};
@@ -41,12 +41,12 @@ $params = $request->{params}->{checked};
#read cache #read cache
my $cache = {}; my $cache = {};
if ( $config->{cache}->{use_cache} eq '1' ) { if ( $config->{cache}->{use_cache} eq '1' ) {
cache::configure('series_names.html'); cache::configure('series_names.html');
$cache = cache::load( $config, $params ); $cache = cache::load( $config, $params );
if ( defined $cache->{content} ) { if ( defined $cache->{content} ) {
print $cache->{content}; print $cache->{content};
return; return;
} }
} }
#connect #connect
@@ -56,111 +56,111 @@ my $dbh = db::connect($config);
my $template_parameters = {}; my $template_parameters = {};
$template_parameters->{projects} = getProjects( $dbh, $config, $params ); $template_parameters->{projects} = getProjects( $dbh, $config, $params );
$template_parameters->{debug} = $config->{system}->{debug}; $template_parameters->{debug} = $config->{system}->{debug};
$template_parameters->{server_cache} = $config->{cache}->{server_cache} if $config->{cache}->{server_cache} ; $template_parameters->{server_cache} = $config->{cache}->{server_cache} if $config->{cache}->{server_cache};
$template_parameters->{use_client_cache} = $config->{cache}->{use_client_cache} if $config->{cache}->{use_client_cache} ; $template_parameters->{use_client_cache} = $config->{cache}->{use_client_cache} if $config->{cache}->{use_client_cache};
#output template #output template
my $template = $params->{template}; my $template = $params->{template};
my $out = ''; my $out = '';
template::process($config, $out, $params->{template}, $template_parameters ); template::process( $config, $out, $params->{template}, $template_parameters );
print $out; print $out;
#write to cache #write to cache
if ( $config->{cache}->{use_cache} eq '1' ) { if ( $config->{cache}->{use_cache} eq '1' ) {
$cache->{content} = $out; $cache->{content} = $out;
cache::save($cache); cache::save($cache);
} }
$cache = undef; $cache = undef;
$out = undef; $out = undef;
sub getProjects { sub getProjects {
my $dbh = shift; my $dbh = shift;
my $config = shift; my $config = shift;
my $params = shift; my $params = shift;
my $prev_series_names = undef; my $prev_series_names = undef;
my $projects = project::get_sorted($config); my $projects = project::get_sorted($config);
my $excludedProjects = {}; my $excludedProjects = {};
if ( defined $config->{filter}->{projects_to_exclude} ) { if ( defined $config->{filter}->{projects_to_exclude} ) {
for my $project ( split( /\,/, $config->{filter}->{projects_to_exclude} ) ) { for my $project ( split( /\,/, $config->{filter}->{projects_to_exclude} ) ) {
$project =~ s/^\s+//g; $project =~ s/^\s+//g;
$project =~ s/\s+$//g; $project =~ s/\s+$//g;
$excludedProjects->{$project} = 1; $excludedProjects->{$project} = 1;
} }
} }
my $results = []; my $results = [];
for my $project (@$projects) { for my $project (@$projects) {
next if defined $excludedProjects->{ $project->{name} }; next if defined $excludedProjects->{ $project->{name} };
my $series_names = getSeriesNames( $dbh, $config, $project->{name}, $params ); my $series_names = getSeriesNames( $dbh, $config, $project->{name}, $params );
$project->{isEmpty} = 1 if scalar(@$series_names) == 0; $project->{isEmpty} = 1 if scalar(@$series_names) == 0;
$project->{series_names} = $series_names; $project->{series_names} = $series_names;
$project->{js_name} = $project->{name}; $project->{js_name} = $project->{name};
$project->{js_name} =~ s/[^a-zA-Z\_0-9]/\_/g; $project->{js_name} =~ s/[^a-zA-Z\_0-9]/\_/g;
$project->{js_name} =~ s/\_+/\_/g; $project->{js_name} =~ s/\_+/\_/g;
#mark last series_name entry of all non empty projects #mark last series_name entry of all non empty projects
if ( ( defined $series_names ) && ( scalar @$series_names > 0 ) ) { if ( ( defined $series_names ) && ( scalar @$series_names > 0 ) ) {
$series_names->[-1]->{last} = 1; $series_names->[-1]->{last} = 1;
$prev_series_names->[-1]->{last} = 0 if ( defined $prev_series_names ) && ( sclar @$prev_series_names > 0 ) ; $prev_series_names->[-1]->{last} = 0 if ( defined $prev_series_names ) && ( sclar @$prev_series_names > 0 );
$prev_series_names = $series_names; $prev_series_names = $series_names;
} }
push @$results, $project; push @$results, $project;
} }
return $results; return $results;
} }
sub getSeriesNames { sub getSeriesNames {
my $dbh = shift; my $dbh = shift;
my $config = shift; my $config = shift;
my $project = shift; my $project = shift;
my $params = shift; my $params = shift;
my $debug = $config->{system}->{debug}; my $debug = $config->{system}->{debug};
my $bind_values = []; my $bind_values = [];
my @conds = (); my @conds = ();
if ( defined $config->{filter}->{locations_to_exclude} ) { if ( defined $config->{filter}->{locations_to_exclude} ) {
my @exclude = (); my @exclude = ();
for my $location ( split( /\,/, $config->{filter}->{locations_to_exclude} ) ) { for my $location ( split( /\,/, $config->{filter}->{locations_to_exclude} ) ) {
$location =~ s/^\s+//g; $location =~ s/^\s+//g;
$location =~ s/\s+$//g; $location =~ s/\s+$//g;
push @exclude, '?'; push @exclude, '?';
push @$bind_values, $location; push @$bind_values, $location;
} }
push @conds, 'location not in (' . join( ',', @exclude ) . ')'; push @conds, 'location not in (' . join( ',', @exclude ) . ')';
} }
if ( defined $config->{filter}->{projects_to_exclude} ) { if ( defined $config->{filter}->{projects_to_exclude} ) {
my @exclude = (); my @exclude = ();
for my $project ( split( /\,/, $config->{filter}->{projects_to_exclude} ) ) { for my $project ( split( /\,/, $config->{filter}->{projects_to_exclude} ) ) {
$project =~ s/^\s+//g; $project =~ s/^\s+//g;
$project =~ s/\s+$//g; $project =~ s/\s+$//g;
push @exclude, '?'; push @exclude, '?';
push @$bind_values, $project; push @$bind_values, $project;
} }
push @conds, 'project not in (' . join( ',', @exclude ) . ')'; push @conds, 'project not in (' . join( ',', @exclude ) . ')';
} }
if ( ( $project ne '' ) && ( $project ne 'all' ) ) { if ( ( $project ne '' ) && ( $project ne 'all' ) ) {
push @conds, 'project=?'; push @conds, 'project=?';
push @$bind_values, $project; push @$bind_values, $project;
} }
if ( ( $params->{search} ne '' ) ) { if ( ( $params->{search} ne '' ) ) {
push @conds, 'series_name like ?'; push @conds, 'series_name like ?';
push @$bind_values, '%' . $params->{search} . '%'; push @$bind_values, '%' . $params->{search} . '%';
} }
my $where = ''; my $where = '';
if ( @conds > 0 ) { if ( @conds > 0 ) {
$where = 'where ' . join( ' and ', @conds ); $where = 'where ' . join( ' and ', @conds );
} }
my $query = qq{ my $query = qq{
select series_name, count(series_name) sum select series_name, count(series_name) sum
from calcms_events from calcms_events
$where $where
@@ -168,38 +168,38 @@ sub getSeriesNames {
order by series_name order by series_name
}; };
my $series_names = db::get( $dbh, $query, $bind_values ); my $series_names = db::get( $dbh, $query, $bind_values );
for my $series (@$series_names) { for my $series (@$series_names) {
$series->{series_name} = '' unless defined $series->{series_name}; $series->{series_name} = '' unless defined $series->{series_name};
$series->{series_name} =~ s/\"//g; $series->{series_name} =~ s/\"//g;
$series->{series_name} = 'ohne' if $series->{series_name} eq ''; $series->{series_name} = 'ohne' if $series->{series_name} eq '';
$series->{series_name} = 'Einzelsendung' if $series->{series_name} eq '_single_'; $series->{series_name} = 'Einzelsendung' if $series->{series_name} eq '_single_';
} }
return $series_names; return $series_names;
} }
sub check_params { sub check_params {
my $config = shift; my $config = shift;
my $params = shift; my $params = shift;
my $template = template::check($config, $params->{template}, 'series_names.html' ); my $template = template::check( $config, $params->{template}, 'series_names.html' );
my $debug = $params->{debug} || ''; my $debug = $params->{debug} || '';
if ( $debug =~ /([a-z\_\,]+)/ ) { if ( $debug =~ /([a-z\_\,]+)/ ) {
$debug = $1; $debug = $1;
} }
my $search = $params->{q} || $params->{search} || $params->{term} || ''; my $search = $params->{q} || $params->{search} || $params->{term} || '';
if ( $search =~ /([a-z0-9A-Z\_\,]+)/ ) { if ( $search =~ /([a-z0-9A-Z\_\,]+)/ ) {
$search = $1; $search = $1;
} }
return { return {
template => $template, template => $template,
debug => $debug, debug => $debug,
search => $search, search => $search,
}; };
} }

View File

@@ -1,6 +1,5 @@
#! /usr/bin/perl -w #! /usr/bin/perl -w
#use utf8;
use warnings "all"; use warnings "all";
use strict; use strict;
@@ -10,7 +9,6 @@ $CGI::DISABLE_UPLOADS = 1;
use Data::Dumper; use Data::Dumper;
#use Apache2::Request;
use JSON(); use JSON();
use params(); use params();
use config(); use config();
@@ -19,37 +17,36 @@ use playout();
my $r = shift; my $r = shift;
#binmode STDOUT, ":utf8";
binmode STDOUT, ":encoding(UTF-8)"; binmode STDOUT, ":encoding(UTF-8)";
if ( $0 =~ /upload_playout.*?\.cgi$/ ) { if ( $0 =~ /upload_playout.*?\.cgi$/ ) {
# read POST content # read POST content
my ( $buf, $content ); my ( $buf, $content );
while ( $r->read( $buf, 8192 ) ) { while ( $r->read( $buf, 8192 ) ) {
$content .= $buf; $content .= $buf;
} }
$content = "{}" unless $content; $content = "{}" unless $content;
# parse GET content # parse GET content
( my $cgi, my $params, my $error ) = params::get($r); ( my $cgi, my $params, my $error ) = params::get($r);
my $config = config::get('config/config.cgi'); my $config = config::getFromScriptLocation();
my $debug = $config->{system}->{debug}; my $debug = $config->{system}->{debug};
my $len = $r->headers_in()->get('Content-Length'); my $len = $r->headers_in()->get('Content-Length');
print "Content-type:text/plain\n\n"; print "Content-type:text/plain\n\n";
my $json = JSON::decode_json($content); my $json = JSON::decode_json($content);
$json->{project_id} = $params->{project_id} if defined $params->{project_id}; $json->{project_id} = $params->{project_id} if defined $params->{project_id};
$json->{studio_id} = $params->{studio_id} if defined $params->{studio_id}; $json->{studio_id} = $params->{studio_id} if defined $params->{studio_id};
$config->{access}->{write} = 1; $config->{access}->{write} = 1;
my $result = playout::sync( $config, $json ); my $result = playout::sync( $config, $json );
$config->{access}->{write} = 0; $config->{access}->{write} = 0;
#print Dumper($content)."\n"; #print Dumper($content)."\n";
#print Dumper($r); #print Dumper($r);
#print Dumper($json); #print Dumper($json);
print "upload playout result:" . Dumper($result); print "upload playout result:" . Dumper($result);
} }
1; 1;