51 lines
1.3 KiB
PHP
51 lines
1.3 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\Entity\Mailing;
|
||
|
|
||
|
class MailingNewCommand extends Command
|
||
|
{
|
||
|
protected static $defaultName = 'mailing:new';
|
||
|
|
||
|
protected EntityManagerInterface $em;
|
||
|
|
||
|
public function __construct(EntityManagerInterface $em)
|
||
|
{
|
||
|
parent::__construct();
|
||
|
|
||
|
$this->em = $em;
|
||
|
}
|
||
|
|
||
|
protected function configure()
|
||
|
{
|
||
|
$this
|
||
|
->setDescription('Create a new mailing')
|
||
|
->addArgument('label', InputArgument::REQUIRED, 'Label of the mailing')
|
||
|
;
|
||
|
}
|
||
|
|
||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||
|
{
|
||
|
$io = new SymfonyStyle($input, $output);
|
||
|
$label = $input->getArgument('label');
|
||
|
|
||
|
$entity = new Mailing();
|
||
|
$entity->setLabel($label);
|
||
|
|
||
|
$this->em->persist($entity);
|
||
|
$this->em->flush();
|
||
|
|
||
|
$io->success(sprintf('"%s" was created with id "%s"', $label, $entity->getId()));
|
||
|
|
||
|
return Command::SUCCESS;
|
||
|
}
|
||
|
}
|