audiorecordings.pm: connect locally to detect permissions
This commit is contained in:
@@ -31,7 +31,6 @@ sub get($$) {
|
|||||||
if ( defined $condition->{date_range_include} ) && ( $condition->{date_range_include} == 1 );
|
if ( defined $condition->{date_range_include} ) && ( $condition->{date_range_include} == 1 );
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my $conditions = [];
|
my $conditions = [];
|
||||||
my $bind_values = [];
|
my $bind_values = [];
|
||||||
|
|
||||||
@@ -93,12 +92,45 @@ sub get($$) {
|
|||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub update_active($$) {
|
||||||
|
my ($config, $entry) = @_;
|
||||||
|
|
||||||
|
return undef unless defined $entry->{project_id};
|
||||||
|
return undef unless defined $entry->{studio_id};
|
||||||
|
return undef unless defined $entry->{event_id};
|
||||||
|
|
||||||
|
my $dbh = db::connect($config);
|
||||||
|
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id} ];
|
||||||
|
my $query = qq{
|
||||||
|
update calcms_audio_recordings
|
||||||
|
set active=0
|
||||||
|
where project_id=? and studio_id=? and event_id=? and active=1
|
||||||
|
};
|
||||||
|
db::put( $dbh, $query, $bind_values );
|
||||||
|
|
||||||
|
$query = qq{
|
||||||
|
select max(id) id from calcms_audio_recordings
|
||||||
|
where project_id=? and studio_id=? and event_id=?
|
||||||
|
};
|
||||||
|
my $entries = db::get( $dbh, $query, $bind_values );
|
||||||
|
my $max = $entries->[0];
|
||||||
|
return undef unless defined $max->{id};
|
||||||
|
|
||||||
|
$query = qq{
|
||||||
|
update calcms_audio_recordings
|
||||||
|
set active=1
|
||||||
|
where id=?
|
||||||
|
};
|
||||||
|
return db::put( $dbh, $query, [$max->{id}] );
|
||||||
|
}
|
||||||
|
|
||||||
# update playout entry if differs to old values
|
# update playout entry if differs to old values
|
||||||
sub update($$$) {
|
sub update($$) {
|
||||||
my ($config, $dbh, $entry) = @_;
|
my ($config, $entry) = @_;
|
||||||
|
|
||||||
my $day_start = $config->{date}->{day_starting_hour};
|
my $day_start = $config->{date}->{day_starting_hour};
|
||||||
|
|
||||||
|
my $dbh = db::connect($config);
|
||||||
my $bind_values = [
|
my $bind_values = [
|
||||||
$entry->{path}, $entry->{size},
|
$entry->{path}, $entry->{size},
|
||||||
$entry->{created_by}, $entry->{created_at},
|
$entry->{created_by}, $entry->{created_at},
|
||||||
@@ -124,19 +156,20 @@ sub update($$$) {
|
|||||||
push @$bind_values, $entry->{id};
|
push @$bind_values, $entry->{id};
|
||||||
}
|
}
|
||||||
my $result = db::put( $dbh, $query, $bind_values );
|
my $result = db::put( $dbh, $query, $bind_values );
|
||||||
update_active($config, $dbh, $entry);
|
update_active($config, $entry);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
# insert playout entry
|
# insert playout entry
|
||||||
sub insert ($$$) {
|
sub insert ($$) {
|
||||||
my ($config, $dbh, $entry) = @_;
|
my ($config, $entry) = @_;
|
||||||
|
|
||||||
return undef unless defined $entry->{project_id};
|
return undef unless defined $entry->{project_id};
|
||||||
return undef unless defined $entry->{studio_id};
|
return undef unless defined $entry->{studio_id};
|
||||||
return undef unless defined $entry->{event_id};
|
return undef unless defined $entry->{event_id};
|
||||||
return undef unless defined $entry->{path};
|
return undef unless defined $entry->{path};
|
||||||
|
|
||||||
|
my $dbh = db::connect($config);
|
||||||
$entry = {
|
$entry = {
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
@@ -153,19 +186,20 @@ sub insert ($$$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
my $result = db::insert( $dbh, 'calcms_audio_recordings', $entry );
|
my $result = db::insert( $dbh, 'calcms_audio_recordings', $entry );
|
||||||
update_active($config, $dbh, $entry);
|
update_active($config, $entry);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
# delete playout entry
|
# delete playout entry
|
||||||
sub delete ($$$) {
|
sub delete ($$) {
|
||||||
my ($config, $dbh, $entry) = @_;
|
my ($config, $entry) = @_;
|
||||||
|
|
||||||
return undef unless defined $entry->{project_id};
|
return undef unless defined $entry->{project_id};
|
||||||
return undef unless defined $entry->{studio_id};
|
return undef unless defined $entry->{studio_id};
|
||||||
return undef unless defined $entry->{event_id};
|
return undef unless defined $entry->{event_id};
|
||||||
return undef unless defined $entry->{path};
|
return undef unless defined $entry->{path};
|
||||||
|
|
||||||
|
my $dbh = db::connect($config);
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
delete
|
delete
|
||||||
from calcms_audio_recordings
|
from calcms_audio_recordings
|
||||||
@@ -174,41 +208,10 @@ sub delete ($$$) {
|
|||||||
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id}, $entry->{path} ];
|
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id}, $entry->{path} ];
|
||||||
my $result = db::put( $dbh, $query, $bind_values );
|
my $result = db::put( $dbh, $query, $bind_values );
|
||||||
|
|
||||||
update_active($config, $dbh, $entry);
|
update_active($config, $entry);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub update_active($$$) {
|
|
||||||
my ($config, $dbh, $entry) = @_;
|
|
||||||
|
|
||||||
return undef unless defined $entry->{project_id};
|
|
||||||
return undef unless defined $entry->{studio_id};
|
|
||||||
return undef unless defined $entry->{event_id};
|
|
||||||
|
|
||||||
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id} ];
|
|
||||||
my $query = qq{
|
|
||||||
update calcms_audio_recordings
|
|
||||||
set active=0
|
|
||||||
where project_id=? and studio_id=? and event_id=? and active=1
|
|
||||||
};
|
|
||||||
db::put( $dbh, $query, $bind_values );
|
|
||||||
|
|
||||||
$query = qq{
|
|
||||||
select max(id) id from calcms_audio_recordings
|
|
||||||
where project_id=? and studio_id=? and event_id=?
|
|
||||||
};
|
|
||||||
my $entries = db::get( $dbh, $query, $bind_values );
|
|
||||||
my $max = $entries->[0];
|
|
||||||
return undef unless defined $max->{id};
|
|
||||||
|
|
||||||
$query = qq{
|
|
||||||
update calcms_audio_recordings
|
|
||||||
set active=1
|
|
||||||
where id=?
|
|
||||||
};
|
|
||||||
return db::put( $dbh, $query, [$max->{id}] );
|
|
||||||
}
|
|
||||||
|
|
||||||
sub error($) {
|
sub error($) {
|
||||||
my $msg = shift;
|
my $msg = shift;
|
||||||
print "ERROR: $msg<br/>\n";
|
print "ERROR: $msg<br/>\n";
|
||||||
|
|||||||
@@ -209,7 +209,6 @@ sub deleteRecording {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
|
||||||
$config->{access}->{write} = 0;
|
$config->{access}->{write} = 0;
|
||||||
|
|
||||||
my $audioRecordings = audio_recordings::get(
|
my $audioRecordings = audio_recordings::get(
|
||||||
@@ -245,7 +244,7 @@ sub deleteRecording {
|
|||||||
|
|
||||||
$config->{access}->{write} = 1;
|
$config->{access}->{write} = 1;
|
||||||
$audioRecordings = audio_recordings::delete(
|
$audioRecordings = audio_recordings::delete(
|
||||||
$config, $dbh,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $params->{project_id},
|
project_id => $params->{project_id},
|
||||||
studio_id => $params->{studio_id},
|
studio_id => $params->{studio_id},
|
||||||
@@ -410,8 +409,6 @@ sub updateDatabase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#connect
|
#connect
|
||||||
my $dbh = db::connect($config);
|
|
||||||
|
|
||||||
my $entries = audio_recordings::get(
|
my $entries = audio_recordings::get(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
@@ -424,7 +421,7 @@ sub updateDatabase {
|
|||||||
|
|
||||||
if ( ( defined $entries ) && ( scalar @$entries > 0 ) ) {
|
if ( ( defined $entries ) && ( scalar @$entries > 0 ) ) {
|
||||||
print STDERR "update\n";
|
print STDERR "update\n";
|
||||||
audio_recordings::update( $config, $dbh, $entry );
|
audio_recordings::update( $config, $entry );
|
||||||
my $entry = $entries->[0];
|
my $entry = $entries->[0];
|
||||||
$params->{id} = $entry->{id};
|
$params->{id} = $entry->{id};
|
||||||
} else {
|
} else {
|
||||||
@@ -436,7 +433,7 @@ sub updateDatabase {
|
|||||||
$entry->{rmsRight} = 0.0;
|
$entry->{rmsRight} = 0.0;
|
||||||
$entry->{audioDuration} = 0.0;
|
$entry->{audioDuration} = 0.0;
|
||||||
$entry->{modified_at} = time();
|
$entry->{modified_at} = time();
|
||||||
$entry->{id} = audio_recordings::insert( $config, $dbh, $entry );
|
$entry->{id} = audio_recordings::insert( $config, $entry );
|
||||||
$params->{id} = $entry->{id};
|
$params->{id} = $entry->{id};
|
||||||
}
|
}
|
||||||
call_hooks($config, $entry, $params);
|
call_hooks($config, $entry, $params);
|
||||||
@@ -448,7 +445,6 @@ sub updateDatabase {
|
|||||||
sub call_hooks {
|
sub call_hooks {
|
||||||
my ($config, $entry, $params) = @_;
|
my ($config, $entry, $params) = @_;
|
||||||
print STDERR Dumper($config->{"audio-upload-hooks"});
|
print STDERR Dumper($config->{"audio-upload-hooks"});
|
||||||
my $dbh = db::connect($config);
|
|
||||||
|
|
||||||
$entry = audio_recordings::get(
|
$entry = audio_recordings::get(
|
||||||
$config, {
|
$config, {
|
||||||
@@ -468,7 +464,7 @@ sub call_hooks {
|
|||||||
$entry->{$key} = $value;
|
$entry->{$key} = $value;
|
||||||
die "invalid column $key for table calcms_audio_recordings"
|
die "invalid column $key for table calcms_audio_recordings"
|
||||||
unless exists audio_recordings::get_columns($config)->{$key};
|
unless exists audio_recordings::get_columns($config)->{$key};
|
||||||
audio_recordings::update( $config, $dbh, $entry );
|
audio_recordings::update( $config, $entry );
|
||||||
} elsif ($line =~ m/^calcms_events\.([a-zA-Z0-9_-]+)\s*=\s*(\S+)/) {
|
} elsif ($line =~ m/^calcms_events\.([a-zA-Z0-9_-]+)\s*=\s*(\S+)/) {
|
||||||
my ($key, $value) = ($1, $2);
|
my ($key, $value) = ($1, $2);
|
||||||
die "invalid column $key for calcms_events\n"
|
die "invalid column $key for calcms_events\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user