1010use Doctrine \ORM \OptimisticLockException ;
1111use Symfony \Bundle \SecurityBundle \Security ;
1212use Symfony \Component \Messenger \Envelope ;
13+ use Symfony \Component \Messenger \Exception \ExceptionInterface ;
1314use Symfony \Component \Messenger \MessageBusInterface ;
1415use Symfony \Component \Messenger \Stamp \DelayStamp ;
1516use Symfony \Contracts \Translation \TranslatorInterface ;
@@ -31,22 +32,29 @@ public function __construct(
3132 }
3233
3334 /**
34- * @param string $commandName - Command name
35- * @param array $commandParams - Command params
36- * @param int|null $entityId - Entity ID
37- * @param string|null $entityClassName - Entity class name
38- * @param Job|null $parentJob - Parent Job entity
39- * @param JobRecurring|null $parentJobRecurring - Recurring job from which was created
40- * @param DateTimeImmutable|null $postponedStartAt - Postponed job start time
35+ * @param string $commandName Command name
36+ * @param array $commandParams Command params
37+ * @param int|null $entityId Entity ID
38+ * @param string|null $entityClassName Entity class name
39+ * @param Job|null $parentJob Parent Job entity
40+ * @param JobRecurring|null $parentJobRecurring Recurring job from which was created
41+ * @param DateTimeImmutable|null $postponedStartAt Postponed job start time
42+ * @param bool $checkUserRole Check if user has a role with granted job creation
4143 * @return Job
4244 * @throws CommandJobException
43- * @throws ORMException
44- * @throws OptimisticLockException
45+ * @throws ExceptionInterface
4546 */
46- public function createCommandJob (string $ commandName , array $ commandParams , ?int $ entityId = null , ?string $ entityClassName = null , ?Job $ parentJob = null , ?JobRecurring $ parentJobRecurring = null , ?DateTimeImmutable $ postponedStartAt = null ): Job
47+ public function createCommandJob (string $ commandName ,
48+ array $ commandParams ,
49+ ?int $ entityId = null ,
50+ ?string $ entityClassName = null ,
51+ ?Job $ parentJob = null ,
52+ ?JobRecurring $ parentJobRecurring = null ,
53+ ?DateTimeImmutable $ postponedStartAt = null ,
54+ ?bool $ checkUserRole = true ): Job
4755 {
4856 // Check if user is loaded and is granted job creation
49- if ($ this ->security ->getUser () && !$ this ->security ->isGranted (JobQueuePermissions::ROLE_JOB_CREATE )) {
57+ if ($ checkUserRole && $ this ->security ->getUser () && !$ this ->security ->isGranted (JobQueuePermissions::ROLE_JOB_CREATE )) {
5058 throw new CommandJobException ($ this ->translator ->trans ('job.creation.error_security ' ));
5159 }
5260
0 commit comments