refactoring

optimize imports
reformat source code
remove unused cpu and memory log functionality
This commit is contained in:
Milan
2018-08-29 00:10:15 +02:00
parent c37c71f29e
commit 05b1251c1a
81 changed files with 9242 additions and 9962 deletions

View File

@@ -1,142 +1,145 @@
package studio_timeslot_schedule;
package studio_timeslot_schedule;
use warnings "all";
use strict;
use Data::Dumper;
use studio_timeslot_dates;
use studio_timeslot_dates();
# table: calcms_studio_timeslot_schedule
# columns: id, project_id, studio_id, start(datetime), end(datetime), end_date(date),
# columns: id, project_id, studio_id, start(datetime), end(datetime), end_date(date),
# frequency(days), duration(minutes), create_events(days), publish_events(days)
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(get_columns get insert update delete);
our %EXPORT_TAGS = ( 'all' => [ @EXPORT_OK ] );
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(get_columns get insert update delete);
our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
sub debug;
sub get_columns{
my $config=shift;
sub get_columns {
my $config = shift;
my $dbh=db::connect($config);
my $cols=db::get_columns($dbh, 'calcms_studio_timeslot_schedule');
my $columns={};
for my $col (@$cols){
$columns->{$col}=1;
my $dbh = db::connect($config);
my $cols = db::get_columns( $dbh, 'calcms_studio_timeslot_schedule' );
my $columns = {};
for my $col (@$cols) {
$columns->{$col} = 1;
}
return $columns;
}
#map schedule id to id
sub get{
my $config=shift;
my $condition=shift;
sub get {
my $config = shift;
my $condition = shift;
my $dbh=db::connect($config);
my $dbh = db::connect($config);
my @conditions=();
my @bind_values=();
my @conditions = ();
my @bind_values = ();
if ((defined $condition->{project_id}) && ($condition->{project_id} ne '')){
push @conditions, 'project_id=?';
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
push @conditions, 'project_id=?';
push @bind_values, $condition->{project_id};
}
if ((defined $condition->{studio_id}) && ($condition->{studio_id} ne '')){
push @conditions, 'studio_id=?';
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
push @conditions, 'studio_id=?';
push @bind_values, $condition->{studio_id};
}
if ((defined $condition->{schedule_id}) && ($condition->{schedule_id} ne '')){
push @conditions, 'id=?';
if ( ( defined $condition->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) {
push @conditions, 'id=?';
push @bind_values, $condition->{schedule_id};
}
my $conditions='';
$conditions=" where ".join(" and ",@conditions) if (@conditions>0);
my $conditions = '';
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
my $query=qq{
my $query = qq{
select *
from calcms_studio_timeslot_schedule
$conditions
order by start
};
#print $query."\n";
#print Dumper(\@bind_values);
my $entries=db::get($dbh, $query, \@bind_values);
for my $entry (@$entries){
$entry->{schedule_id}=$entry->{id};
my $entries = db::get( $dbh, $query, \@bind_values );
for my $entry (@$entries) {
$entry->{schedule_id} = $entry->{id};
delete $entry->{id};
}
return $entries;
}
sub insert{
my $config=shift;
my $entry=shift;
sub insert {
my $config = shift;
my $entry = shift;
return unless(defined $entry->{project_id});
return unless(defined $entry->{studio_id});
return unless(defined $entry->{start});
return unless(defined $entry->{end});
return unless(defined $entry->{frequency});
return unless ( defined $entry->{project_id} );
return unless ( defined $entry->{studio_id} );
return unless ( defined $entry->{start} );
return unless ( defined $entry->{end} );
return unless ( defined $entry->{frequency} );
my $dbh=db::connect($config);
return db::insert($dbh, 'calcms_studio_timeslot_schedule', $entry);
my $dbh = db::connect($config);
return db::insert( $dbh, 'calcms_studio_timeslot_schedule', $entry );
}
#schedule id to id
sub update{
my $config=shift;
my $entry=shift;
sub update {
my $config = shift;
my $entry = shift;
return unless(defined $entry->{project_id});
return unless(defined $entry->{studio_id});
return unless(defined $entry->{schedule_id});
return unless(defined $entry->{start});
return unless(defined $entry->{end});
return unless(defined $entry->{frequency});
return unless ( defined $entry->{project_id} );
return unless ( defined $entry->{studio_id} );
return unless ( defined $entry->{schedule_id} );
return unless ( defined $entry->{start} );
return unless ( defined $entry->{end} );
return unless ( defined $entry->{frequency} );
$entry->{id}=$entry->{schedule_id};
$entry->{id} = $entry->{schedule_id};
delete $entry->{schedule_id};
my $dbh=db::connect($config);
my $values =join(",", map {$_.'=?'} (keys %$entry));
my @bind_values =map {$entry->{$_}} (keys %$entry);
push @bind_values,$entry->{id};
my $dbh = db::connect($config);
my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) );
my @bind_values = map { $entry->{$_} } ( keys %$entry );
push @bind_values, $entry->{id};
my $query=qq{
my $query = qq{
update calcms_studio_timeslot_schedule
set $values
where id=?
};
db::put($dbh, $query, \@bind_values);
db::put( $dbh, $query, \@bind_values );
#print "done\n";
$entry->{schedule_id}=$entry->{id};
$entry->{schedule_id} = $entry->{id};
delete $entry->{id};
}
#map schedule id to id
sub delete{
my $config=shift;
my $entry=shift;
return unless(defined $entry->{schedule_id});
sub delete {
my $config = shift;
my $entry = shift;
my $dbh=db::connect($config);
return unless ( defined $entry->{schedule_id} );
my $query=qq{
my $dbh = db::connect($config);
my $query = qq{
delete
from calcms_studio_timeslot_schedule
where id=?
};
my $bind_values=[$entry->{schedule_id}];
my $bind_values = [ $entry->{schedule_id} ];
#print '<pre>$query'.$query.Dumper($bind_values).'</pre>';
db::put($dbh, $query, $bind_values);
db::put( $dbh, $query, $bind_values );
}
sub error{
my $msg=shift;
sub error {
my $msg = shift;
print "ERROR: $msg<br/>\n";
}