mirror of
https://github.com/AzuraCast/AzuraCast.git
synced 2024-06-15 05:36:37 +00:00
a6ec36b21c
- Make the Analytics table in the database the primary one for handling statistics for all stations, removing the InfluxDB dependency entirely - Expand the Analytics table to also track unique listeners per hour and day - Properly clean up the Listeners table according to each installation's history retention settings - Implement a cute new animated "waiting for services" startup message that avoids previous wait messages that looked more like errors
37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
namespace App\Sync\Task;
|
|
|
|
use App\Entity;
|
|
use Carbon\CarbonImmutable;
|
|
|
|
class HistoryCleanup extends AbstractTask
|
|
{
|
|
public function run(bool $force = false): void
|
|
{
|
|
$days_to_keep = (int)$this->settingsRepo->getSetting(Entity\Settings::HISTORY_KEEP_DAYS,
|
|
Entity\SongHistory::DEFAULT_DAYS_TO_KEEP);
|
|
|
|
if ($days_to_keep !== 0) {
|
|
$threshold = (new CarbonImmutable())
|
|
->subDays($days_to_keep)
|
|
->getTimestamp();
|
|
|
|
// Clear Song History
|
|
$this->em->createQuery(/** @lang DQL */ 'DELETE
|
|
FROM App\Entity\SongHistory sh
|
|
WHERE sh.timestamp_start != 0
|
|
AND sh.timestamp_start <= :threshold')
|
|
->setParameter('threshold', $threshold)
|
|
->execute();
|
|
|
|
// Clear Listeners
|
|
$this->em->createQuery(/** @lang DQL */ 'DELETE
|
|
FROM App\Entity\Listener l
|
|
WHERE l.timestamp_start <= :threshold
|
|
AND l.timestamp_end IS NOT NULL')
|
|
->setParameter('threshold', $threshold)
|
|
->execute();
|
|
}
|
|
}
|
|
}
|