Make manual reprocess command trigger the normal sync task instead.

This commit is contained in:
Buster "Silver Eagle" Neece 2020-11-30 20:43:29 -06:00
parent f8acefbcd7
commit 1b0449c392
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
2 changed files with 21 additions and 25 deletions

View File

@ -10,6 +10,8 @@ These changes have not yet been incorporated into a stable release, but if you a
- New installations won't see warnings about backups and sync tasks immediately after installation.
- Various issues with processing some types of media have been resolved.
---
# AzuraCast 0.11 (Nov 28, 2020)

View File

@ -6,7 +6,6 @@ use App\Entity;
use App\Entity\Repository\StationRepository;
use App\Entity\Station;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Component\Console\Style\SymfonyStyle;
class ReprocessMediaCommand extends CommandAbstract
@ -15,44 +14,39 @@ class ReprocessMediaCommand extends CommandAbstract
SymfonyStyle $io,
EntityManagerInterface $em,
StationRepository $stationRepo,
Entity\Repository\StationMediaRepository $media_repo,
?string $stationName = null
): int {
if (!empty($stationName)) {
$station = $stationRepo->findByIdentifier($stationName);
$io->title('Manually Reprocess Media');
if (empty($stationName)) {
$io->section('Reprocessing media for all stations...');
$storageLocation = null;
} else {
$station = $stationRepo->findByIdentifier($stationName);
if (!$station instanceof Station) {
$io->error('Station not found.');
return 1;
}
$stations = [$station];
} else {
$io->section('Restarting all radio stations...');
$storageLocation = $station->getMediaStorageLocation();
/** @var Station[] $stations */
$stations = $stationRepo->fetchAll();
$io->writeln(sprintf('Reprocessing media for station: %s', $station->getName()));
}
foreach ($stations as $station) {
$io->writeln('Processing media for station: ' . $station->getName());
$reprocessMediaQueue = $em->createQueryBuilder()
->update(Entity\StationMedia::class, 'sm')
->set('sm.mtime', 'NULL');
foreach ($station->getMedia() as $media) {
/** @var Entity\StationMedia $media */
try {
$media_repo->processMedia($media, true);
$io->writeln('Processed: ' . $media->getPath());
} catch (Exception $e) {
$io->writeln('Could not read source file for: ' . $media->getPath() . ' - ' . $e->getMessage());
continue;
}
}
$em->flush();
$io->writeln('Station media reprocessed.');
if (null !== $storageLocation) {
$reprocessMediaQueue = $reprocessMediaQueue->where('sm.storage_location = :storageLocation')
->setParameter('storageLocation', $storageLocation);
}
$recordsAffected = $reprocessMediaQueue->getQuery()->getSingleScalarResult();
$io->writeln(sprintf('Marked %d records for reprocessing.', $recordsAffected));
return 0;
}
}