mirror of
https://github.com/AzuraCast/AzuraCast.git
synced 2024-06-17 14:37:07 +00:00
Make "minutes until a song is re-requestable" a per-station configurable variable.
This commit is contained in:
parent
c97662787b
commit
1188529a5f
|
@ -173,6 +173,15 @@ return [
|
|||
]
|
||||
],
|
||||
|
||||
'request_threshold' => [
|
||||
'text',
|
||||
[
|
||||
'label' => _('Request Last Played Threshold (Minutes)'),
|
||||
'description' => _('If requests are enabled, this specifies the minimum time (in minutes) between a song playing on the radio and being available to request again. Set to 0 for no threshold.'),
|
||||
'default' => '15',
|
||||
]
|
||||
],
|
||||
|
||||
'crossfade' => [
|
||||
'text',
|
||||
[
|
||||
|
|
43
app/models/Migration/Version20170414205418.php
Normal file
43
app/models/Migration/Version20170414205418.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Migration;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Add request threshold to Station entity.
|
||||
*/
|
||||
class Version20170414205418 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE station ADD request_threshold INT DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function postUp(Schema $schema)
|
||||
{
|
||||
$this->connection->update('station', [
|
||||
'request_threshold' => 15,
|
||||
], [
|
||||
'enable_requests' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE station DROP request_threshold');
|
||||
}
|
||||
}
|
|
@ -58,27 +58,32 @@ class StationRequestRepository extends \App\Doctrine\Repository
|
|||
}
|
||||
|
||||
// Check the most recent song history.
|
||||
$last_play_threshold = time() - (60 * 60);
|
||||
$last_play_threshold_mins = (int)($station->request_threshold ?? 15);
|
||||
|
||||
try {
|
||||
$last_play_time = $this->_em->createQuery('SELECT sh.timestamp_start
|
||||
if ($last_play_threshold_mins > 0)
|
||||
{
|
||||
$last_play_threshold = time() - ($last_play_threshold_mins * 60);
|
||||
|
||||
try {
|
||||
$last_play_time = $this->_em->createQuery('SELECT sh.timestamp_start
|
||||
FROM Entity\SongHistory sh
|
||||
WHERE sh.song_id = :song_id
|
||||
AND sh.station_id = :station_id
|
||||
AND sh.timestamp_start >= :threshold
|
||||
ORDER BY sh.timestamp_start DESC')
|
||||
->setParameter('song_id', $media_item->song_id)
|
||||
->setParameter('station_id', $station->id)
|
||||
->setParameter('threshold', $last_play_threshold)
|
||||
->setMaxResults(1)
|
||||
->getSingleScalarResult();
|
||||
} catch (\Exception $e) {
|
||||
$last_play_time = 0;
|
||||
}
|
||||
->setParameter('song_id', $media_item->song_id)
|
||||
->setParameter('station_id', $station->id)
|
||||
->setParameter('threshold', $last_play_threshold)
|
||||
->setMaxResults(1)
|
||||
->getSingleScalarResult();
|
||||
} catch (\Exception $e) {
|
||||
$last_play_time = 0;
|
||||
}
|
||||
|
||||
if ($last_play_time > 0) {
|
||||
$threshold_text = \App\Utilities::timeDifferenceText(time(), $last_play_time);
|
||||
throw new \App\Exception('This song was already played '.$threshold_text.' ago! Wait a while before requesting it again.');
|
||||
if ($last_play_time > 0) {
|
||||
$threshold_text = \App\Utilities::timeDifferenceText(time(), $last_play_time);
|
||||
throw new \App\Exception('This song was already played '.$threshold_text.' ago! Wait a while before requesting it again.');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$is_authenticated) {
|
||||
|
|
|
@ -16,7 +16,9 @@ class Station extends \App\Doctrine\Entity
|
|||
$this->automation_timestamp = 0;
|
||||
$this->enable_streamers = false;
|
||||
$this->enable_requests = false;
|
||||
|
||||
$this->request_delay = 5;
|
||||
$this->request_threshold = 15;
|
||||
|
||||
$this->needs_restart = false;
|
||||
|
||||
|
@ -146,6 +148,9 @@ class Station extends \App\Doctrine\Entity
|
|||
/** @Column(name="request_delay", type="integer", nullable=true) */
|
||||
protected $request_delay;
|
||||
|
||||
/** @Column(name="request_threshold", type="integer", nullable=true) */
|
||||
protected $request_threshold;
|
||||
|
||||
/** @Column(name="enable_streamers", type="boolean", nullable=false) */
|
||||
protected $enable_streamers;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user