2017-04-14 23:52:30 +02:00
|
|
|
<?php
|
2020-10-15 00:19:31 +02:00
|
|
|
|
2021-07-19 07:53:45 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-08-05 00:05:14 +02:00
|
|
|
namespace App\Console\Command;
|
2017-04-14 23:52:30 +02:00
|
|
|
|
2019-08-07 06:33:55 +02:00
|
|
|
use App\Entity;
|
2019-12-15 09:53:04 +01:00
|
|
|
use App\Entity\Repository\StationRepository;
|
|
|
|
use App\Entity\Station;
|
2020-06-26 22:22:53 +02:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2019-09-11 01:10:57 +02:00
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2017-04-14 23:52:30 +02:00
|
|
|
|
2019-09-11 01:10:57 +02:00
|
|
|
class ReprocessMediaCommand extends CommandAbstract
|
2017-04-14 23:52:30 +02:00
|
|
|
{
|
2019-09-11 01:10:57 +02:00
|
|
|
public function __invoke(
|
|
|
|
SymfonyStyle $io,
|
2020-06-26 22:22:53 +02:00
|
|
|
EntityManagerInterface $em,
|
2019-12-15 09:53:04 +01:00
|
|
|
StationRepository $stationRepo,
|
|
|
|
?string $stationName = null
|
2020-10-15 00:19:31 +02:00
|
|
|
): int {
|
2020-12-01 03:43:29 +01:00
|
|
|
$io->title('Manually Reprocess Media');
|
|
|
|
|
|
|
|
if (empty($stationName)) {
|
|
|
|
$io->section('Reprocessing media for all stations...');
|
2017-04-15 01:44:31 +02:00
|
|
|
|
2020-12-01 03:43:29 +01:00
|
|
|
$storageLocation = null;
|
|
|
|
} else {
|
|
|
|
$station = $stationRepo->findByIdentifier($stationName);
|
2019-12-15 09:53:04 +01:00
|
|
|
if (!$station instanceof Station) {
|
|
|
|
$io->error('Station not found.');
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-12-01 03:43:29 +01:00
|
|
|
$storageLocation = $station->getMediaStorageLocation();
|
2019-12-15 09:53:04 +01:00
|
|
|
|
2020-12-01 03:43:29 +01:00
|
|
|
$io->writeln(sprintf('Reprocessing media for station: %s', $station->getName()));
|
2019-12-15 09:53:04 +01:00
|
|
|
}
|
2018-12-05 08:15:51 +01:00
|
|
|
|
2020-12-01 03:43:29 +01:00
|
|
|
$reprocessMediaQueue = $em->createQueryBuilder()
|
|
|
|
->update(Entity\StationMedia::class, 'sm')
|
|
|
|
->set('sm.mtime', 'NULL');
|
2017-04-14 23:52:30 +02:00
|
|
|
|
2020-12-01 03:43:29 +01:00
|
|
|
if (null !== $storageLocation) {
|
|
|
|
$reprocessMediaQueue = $reprocessMediaQueue->where('sm.storage_location = :storageLocation')
|
|
|
|
->setParameter('storageLocation', $storageLocation);
|
2017-04-14 23:52:30 +02:00
|
|
|
}
|
2018-05-07 03:57:06 +02:00
|
|
|
|
2020-12-01 03:43:29 +01:00
|
|
|
$recordsAffected = $reprocessMediaQueue->getQuery()->getSingleScalarResult();
|
|
|
|
|
|
|
|
$io->writeln(sprintf('Marked %d records for reprocessing.', $recordsAffected));
|
|
|
|
|
2018-05-07 03:57:06 +02:00
|
|
|
return 0;
|
2017-04-14 23:52:30 +02:00
|
|
|
}
|
2018-08-05 00:05:14 +02:00
|
|
|
}
|