update_program.pl: refactor

This commit is contained in:
Milan
2020-04-09 23:00:40 +02:00
parent 90cd9b9620
commit b442bf0fc8

View File

@@ -7,7 +7,6 @@ use Data::Dumper;
use Date::Calc;
use config;
use template;
use projects;
my $perlPath='-I /home/calcms/lib/calcms';
my $configPath=$ARGV[0]||'/home/calcms/website/agenda/config/config.cgi';
@@ -19,19 +18,12 @@ clean_up_cache();
sub clean_up_cache{
my $base_dir =$config::config->{locations}->{base_dir}||'';
my $cache =$config::config->{cache}->{cache_dir}||'';
my $cache_dir=$base_dir.'/'.$cache.'/';
print_error("'base_dir' directory not configured! Please check config!") if($base_dir eq'');
print_error("invalid 'base_dir' directory '$base_dir'! Please check config!") unless ($base_dir=~/[a-zA-Z]\/[a-zA-Z]/);
print_error("'base_dir' directory '$base_dir' does not exist! Please check config!") unless (-e $base_dir);
print_error("cannot read 'base_dir' directory '$base_dir'! Please check permissions!") unless (-r $base_dir);
print_error("'cache_dir' directory $cache_dir not configured! Please check config!") if ($cache_dir eq '/');
print_error("invalid 'cache_dir' directory '$cache_dir'! Please check config!") unless ($cache_dir=~/[a-zA-Z]\/[a-zA-Z]/);
print_error("'cache_dir' directory '$cache_dir' does not exist! Please check filesystem!") unless (-e $cache_dir);
print_error("cannot write to 'cache_dir' directory '$cache_dir'! Please check filesystem!") unless (-w $cache_dir);
# update basic layout
print_header("update basic layout");
@@ -44,14 +36,6 @@ sub clean_up_cache{
execute($cmd);
}
# clear all files from cache
print_header("clear cache");
for my $controller (qw(sendung sendungen kalender kommentare)){
clear($cache_dir.'/'.$controller.'/*');
clear($cache_dir.'/programm/'.$controller.'/*');
}
# update start page
print_header("update agenda start page");
$file="$base_dir/programm.html";
@@ -63,22 +47,6 @@ sub clean_up_cache{
}
}
sub clear{
my $path=shift;
print_error("invalid path '$path' to delete!") unless ($path=~/cache/);
return if ($path=~/\.htaccess$/);
print_info("clear $path:");
for my $file (glob($path) ){
if (-f $file){
print_info($file);
unlink $file;
}
}
}
sub print_header{
print "\n# $_[0]\n";
}
@@ -100,5 +68,4 @@ sub print_error{
exit 1;
}
1;