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