61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Command;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use App\Repository\MailingRepository;
|
|
|
|
class MailingUnpublishCommand extends Command
|
|
{
|
|
protected static $defaultName = 'mailing:unpublish';
|
|
|
|
protected EntityManagerInterface $em;
|
|
|
|
protected MailingRepository $repo;
|
|
|
|
public function __construct(EntityManagerInterface $em, MailingRepository $repo)
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->em = $em;
|
|
$this->repo = $repo;
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this
|
|
->setDescription('Unpublish a mailing')
|
|
->addArgument('id', InputArgument::OPTIONAL, 'ID of the mailing')
|
|
;
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$io = new SymfonyStyle($input, $output);
|
|
$id = $input->getArgument('id');
|
|
|
|
$entity = $this->repo->find(['id' => $id]);
|
|
|
|
if (null === $entity) {
|
|
$io->error(sprintf('"%s" is not found!', $id));
|
|
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
$entity->setIsPublic(false);
|
|
|
|
$this->em->persist($entity);
|
|
$this->em->flush();
|
|
|
|
$io->success(sprintf('"%s" is now private', $entity->getId()));
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|