audio_recordings.pm: active audio uploads
If audio files become inactive because a new file is uploaded, the new file is marked as active and the old file is marked as not active. This allows fastly querying events and their active upload file. Before this change all event's audio files were found and needed to be filtered afterwards to get a set of unique events.
This commit is contained in:
@@ -270,3 +270,10 @@ ADD COLUMN `update_event_field_content_format` TINYINT(1) UNSIGNED NOT NULL AFTE
|
||||
|
||||
ALTER TABLE `calcms_events`
|
||||
ADD COLUMN `listen_key` VARCHAR(100) NULL;
|
||||
|
||||
ALTER TABLE `calcms_audio_recordings`
|
||||
ADD COLUMN `active` TINYINT(1) NOT NULL DEFAULT 0 AFTER `event_id`;
|
||||
|
||||
ALTER TABLE `calcms`.`calcms_audio_recordings`
|
||||
ADD INDEX `active_index` (`active`);
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ sub get($$) {
|
||||
,project_id
|
||||
,studio_id
|
||||
,event_id
|
||||
,active
|
||||
,path
|
||||
,size
|
||||
,created_by
|
||||
@@ -128,7 +129,9 @@ sub update($$$) {
|
||||
$query .= ' and id=?';
|
||||
push @$bind_values, $entry->{id};
|
||||
}
|
||||
return db::put( $dbh, $query, $bind_values );
|
||||
my $result = db::put( $dbh, $query, $bind_values );
|
||||
update_active($config, $dbh, $entry);
|
||||
return $result;
|
||||
}
|
||||
|
||||
# insert playout entry
|
||||
@@ -142,25 +145,24 @@ sub insert ($$$) {
|
||||
return undef unless defined $entry->{event_id};
|
||||
return undef unless defined $entry->{path};
|
||||
|
||||
return db::insert(
|
||||
$dbh,
|
||||
'calcms_audio_recordings',
|
||||
{
|
||||
project_id => $entry->{project_id},
|
||||
studio_id => $entry->{studio_id},
|
||||
event_id => $entry->{event_id},
|
||||
path => $entry->{path},
|
||||
size => $entry->{size},
|
||||
created_by => $entry->{created_by},
|
||||
eventDuration => $entry->{eventDuration},
|
||||
audioDuration => $entry->{audioDuration},
|
||||
rmsLeft => $entry->{rmsLeft},
|
||||
rmsRight => $entry->{rmsRight},
|
||||
processed => $entry->{processed},
|
||||
mastered => $entry->{mastered} || '0',
|
||||
}
|
||||
);
|
||||
$entry = {
|
||||
project_id => $entry->{project_id},
|
||||
studio_id => $entry->{studio_id},
|
||||
event_id => $entry->{event_id},
|
||||
path => $entry->{path},
|
||||
size => $entry->{size},
|
||||
created_by => $entry->{created_by},
|
||||
eventDuration => $entry->{eventDuration},
|
||||
audioDuration => $entry->{audioDuration},
|
||||
rmsLeft => $entry->{rmsLeft},
|
||||
rmsRight => $entry->{rmsRight},
|
||||
processed => $entry->{processed},
|
||||
mastered => $entry->{mastered} || '0',
|
||||
};
|
||||
|
||||
my $result = db::insert( $dbh, 'calcms_audio_recordings', $entry );
|
||||
update_active($config, $dbh, $entry);
|
||||
return $result;
|
||||
}
|
||||
|
||||
# delete playout entry
|
||||
@@ -175,12 +177,48 @@ sub delete ($$$) {
|
||||
return undef unless defined $entry->{path};
|
||||
|
||||
my $query = qq{
|
||||
delete
|
||||
delete
|
||||
from calcms_audio_recordings
|
||||
where project_id=? and studio_id=? and event_id=? and path=?
|
||||
};
|
||||
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id}, $entry->{path} ];
|
||||
return db::put( $dbh, $query, $bind_values );
|
||||
my $result = db::put( $dbh, $query, $bind_values );
|
||||
|
||||
update_active($config, $dbh, $entry);
|
||||
return $result;
|
||||
}
|
||||
|
||||
sub update_active($$$) {
|
||||
my $config = shift;
|
||||
my $dbh = shift;
|
||||
my $entry = shift;
|
||||
|
||||
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($) {
|
||||
|
||||
@@ -1148,7 +1148,7 @@ sub get_query($$$) {
|
||||
|
||||
# add recordings table
|
||||
if ( $params->{recordings} eq '1' ) {
|
||||
$query .= "\n left join calcms_audio_recordings ar on e.id=ar.event_id";
|
||||
$query .= "\n left join calcms_audio_recordings ar on e.id=ar.event_id and ar.active=1";
|
||||
}
|
||||
|
||||
if ( scalar @$where_cond > 0 ) {
|
||||
|
||||
@@ -495,7 +495,7 @@ sub get_events ($$) {
|
||||
|
||||
my $conditions = '';
|
||||
if ( @conditions > 0 ) {
|
||||
$conditions = ' and ' . join( ' and ', @conditions );
|
||||
$conditions = ' where ' . join( ' and ', @conditions );
|
||||
}
|
||||
|
||||
my $limit = '';
|
||||
@@ -504,17 +504,19 @@ sub get_events ($$) {
|
||||
}
|
||||
|
||||
my $query = qq{
|
||||
select *
|
||||
,date(start) start_date
|
||||
,date(end) end_date
|
||||
,weekday(start) weekday
|
||||
,weekofyear(start) week_of_year
|
||||
,dayofyear(start) day_of_year
|
||||
,start_date day
|
||||
,id event_id
|
||||
from calcms_series_events se, calcms_events e
|
||||
where se.event_id = e.id
|
||||
$conditions
|
||||
select se.*,e.*
|
||||
,date(start) start_date
|
||||
,date(end) end_date
|
||||
,weekday(start) weekday
|
||||
,weekofyear(start) week_of_year
|
||||
,dayofyear(start) day_of_year
|
||||
,start_date day
|
||||
,e.id event_id
|
||||
,ar.path path
|
||||
from calcms_series_events se
|
||||
inner join calcms_events e on se.event_id = e.id
|
||||
left join calcms_audio_recordings ar on se.event_id=ar.event_id and ar.active=1
|
||||
$conditions
|
||||
order by start_date desc
|
||||
$limit
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user