Skip to content

Commit ae4c908

Browse files
committed
Validate the email option of the batch command
1 parent 73e7d09 commit ae4c908

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Command/BatchCommand.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Symfony\Component\Console\Output\OutputInterface;
1010
use Symfony\Component\Validator\ConstraintViolationList;
1111
use Symfony\Component\Validator\Validator;
12+
use Symfony\Component\Validator\Constraints as Assert;
1213
use Monolog\Handler\StreamHandler;
1314
use Doctrine\ORM\EntityManager;
1415
use Oro\Bundle\BatchBundle\Entity\JobExecution;
@@ -75,16 +76,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
7576
);
7677
}
7778

79+
$validator = $this->getValidator();
80+
7881
// Override mail notifier recipient email
7982
if ($email = $input->getOption('email')) {
83+
if ($errors = $validator->validateValue($email, new Assert\Email())) {
84+
throw new \RuntimeException(
85+
sprintf('Email "%s" is invalid: %s', $email, $this->getErrorMessages($errors))
86+
);
87+
}
8088
$this
8189
->getMailNotifier()
8290
->setRecipientEmail($email);
8391
}
8492

85-
$errors = $this->getValidator()->validate($jobInstance, array('Default', 'Execution'));
86-
if (count($errors) > 0) {
87-
throw new \RuntimeException(sprintf('Job "%s" is invalid: %s', $code, $this->getErrorMessages($errors)));
93+
if ($errors = $validator->validate($jobInstance, array('Default', 'Execution'))) {
94+
throw new \RuntimeException(
95+
sprintf('Job "%s" is invalid: %s', $code, $this->getErrorMessages($errors))
96+
);
8897
}
8998

9099
$executionId = $input->getArgument('execution');

0 commit comments

Comments
 (0)