4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-15 05:36:37 +00:00
AzuraCast/src/Sync/Task/HistoryCleanup.php
Buster "Silver Eagle" Neece a6ec36b21c
Analytics Overhaul and InfluxDB Removal (#3243)
- 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
2020-10-07 18:50:30 -05:00

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();
}
}
}