chore: remove obsolete commands
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Service\Pdf\Sanitizer;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
#[AsCommand(name: 'app:uploads:convert', description: 'Converts all uploads to sanitized PDFs')]
|
||||
class ConvertUploadsCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly UploadHandler $uploadHandler,
|
||||
private readonly Sanitizer $sanitizer,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$uploads = $this
|
||||
->entityManager
|
||||
->getRepository(Upload::class)
|
||||
->findBy([
|
||||
'type' => [Upload::TYPE_INVOICE, Upload::TYPE_CONTRACT],
|
||||
]);
|
||||
|
||||
$progressBar = new ProgressBar($output, count($uploads));
|
||||
$progressBar->start();
|
||||
|
||||
foreach ($uploads as $upload) {
|
||||
/** @var Upload $upload */
|
||||
$filepath = $this->uploadHandler->getUploadFilepath($upload);
|
||||
try {
|
||||
$targetFilepath = $this->sanitizer->sanitizeFile($filepath);
|
||||
$upload
|
||||
->setFilename(basename($targetFilepath))
|
||||
->setMimeType('application/pdf')
|
||||
;
|
||||
} catch (\Throwable $e) {
|
||||
$output->writeln('<error>'.$e->getMessage().'</error>');
|
||||
}
|
||||
|
||||
$progressBar->advance();
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
$progressBar->finish();
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Email;
|
||||
|
||||
#[AsCommand(name: 'app:mail-test', description: 'Testing SMTP Transport')]
|
||||
class MailTestCommand extends Command
|
||||
{
|
||||
public function __construct(private readonly MailerInterface $mailer)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->addArgument('to', InputArgument::REQUIRED, 'Recipient email')
|
||||
->addArgument('from', InputArgument::OPTIONAL, 'Sender email', '[email protected]')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$email = (new Email())
|
||||
->to($input->getArgument('to'))
|
||||
->from($input->getArgument('from'))
|
||||
->subject('Testing SMTP Transport')
|
||||
->text('Testing SMTP Transport');
|
||||
|
||||
$this->mailer->send($email);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\Repository\DestinationRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:destination:update-cost-units',
|
||||
description: 'One-time command to update cost units for destinations from their assigned hotels',
|
||||
)]
|
||||
class UpdateDestinationCostUnitsCommand extends Command
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DestinationRepository $destinationRepository,
|
||||
private readonly HotelDataProvider $hotelDataProvider,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->addOption(
|
||||
'dry-run',
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Run without persisting changes to the database'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$isDryRun = true === $input->getOption('dry-run');
|
||||
|
||||
if ($isDryRun) {
|
||||
$io->note('Running in dry-run mode. No changes will be persisted.');
|
||||
}
|
||||
|
||||
$qb = $this->destinationRepository->createQueryBuilder('d');
|
||||
$destinations = $qb
|
||||
->where($qb->expr()->isNotNull('d.hotelBusProId'))
|
||||
->andWhere($qb->expr()->orX(
|
||||
$qb->expr()->isNull('d.costUnit'),
|
||||
$qb->expr()->eq('d.costUnit', ':emptyString')
|
||||
))
|
||||
->andWhere($qb->expr()->isNull('d.deletedAt'))
|
||||
->setParameter('emptyString', '')
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
$totalCount = count($destinations);
|
||||
|
||||
if (0 === $totalCount) {
|
||||
$io->success('No destinations found that need cost unit updates.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$io->info(sprintf('Found %d destination(s) with assigned hotels and empty cost units.', $totalCount));
|
||||
|
||||
$updatedCount = 0;
|
||||
$skippedCount = 0;
|
||||
|
||||
foreach ($destinations as $destination) {
|
||||
$hotelBusProId = $destination->getHotelBusProId();
|
||||
$hotel = $this->hotelDataProvider->get($hotelBusProId);
|
||||
|
||||
if (null === $hotel) {
|
||||
$io->warning(sprintf(
|
||||
'Hotel with BusProId %d not found for destination #%d',
|
||||
$hotelBusProId,
|
||||
$destination->getId()
|
||||
));
|
||||
++$skippedCount;
|
||||
continue;
|
||||
}
|
||||
|
||||
$costUnit = $hotel->getCostUnit();
|
||||
|
||||
if (null === $costUnit || '' === $costUnit) {
|
||||
$io->warning(sprintf(
|
||||
'Hotel "%s" (BusProId: %d) has no cost unit. Skipping destination #%d',
|
||||
$hotel->getName(),
|
||||
$hotelBusProId,
|
||||
$destination->getId()
|
||||
));
|
||||
++$skippedCount;
|
||||
continue;
|
||||
}
|
||||
|
||||
$destination->setCostUnit($costUnit);
|
||||
++$updatedCount;
|
||||
|
||||
$io->writeln(sprintf(
|
||||
'Updated destination #%d (%s) with cost unit "%s" from hotel "%s"',
|
||||
$destination->getId(),
|
||||
$destination->getProduct(),
|
||||
$costUnit,
|
||||
$hotel->getName()
|
||||
));
|
||||
}
|
||||
|
||||
if (false === $isDryRun && $updatedCount > 0) {
|
||||
$this->entityManager->flush();
|
||||
$io->success(sprintf(
|
||||
'Successfully updated %d destination(s). Skipped %d destination(s).',
|
||||
$updatedCount,
|
||||
$skippedCount
|
||||
));
|
||||
} elseif ($isDryRun && $updatedCount > 0) {
|
||||
$io->success(sprintf(
|
||||
'Dry-run complete. Would update %d destination(s). Would skip %d destination(s).',
|
||||
$updatedCount,
|
||||
$skippedCount
|
||||
));
|
||||
} else {
|
||||
$io->info(sprintf('No destinations updated. Skipped %d destination(s).', $skippedCount));
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user