|
7 | 7 | use CodeRhapsodie\DataflowBundle\Entity\Job; |
8 | 8 | use CodeRhapsodie\IbexaDataflowBundle\Form\CreateOneshotType; |
9 | 9 | use CodeRhapsodie\IbexaDataflowBundle\Gateway\JobGateway; |
| 10 | +use CodeRhapsodie\IbexaDataflowBundle\Gateway\ScheduledDataflowGateway; |
10 | 11 | use Ibexa\Contracts\AdminUi\Controller\Controller; |
11 | 12 | use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface; |
12 | 13 | use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute; |
13 | 14 | use Symfony\Component\HttpFoundation\JsonResponse; |
14 | 15 | use Symfony\Component\HttpFoundation\Request; |
15 | 16 | use Symfony\Component\HttpFoundation\Response; |
| 17 | +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
16 | 18 | use Symfony\Component\Routing\Annotation\Route; |
17 | 19 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
18 | 20 | use Symfony\Contracts\Translation\TranslatorInterface; |
19 | 21 |
|
20 | 22 | #[Route(path: '/ibexa_dataflow/job')] |
21 | 23 | class JobController extends Controller |
22 | 24 | { |
23 | | - public function __construct(private readonly JobGateway $jobGateway, private readonly NotificationHandlerInterface $notificationHandler, private readonly TranslatorInterface $translator) |
| 25 | + public function __construct(private readonly JobGateway $jobGateway, private readonly NotificationHandlerInterface $notificationHandler, private readonly TranslatorInterface $translator, private readonly ScheduledDataflowGateway $scheduledDataflowGateway) |
24 | 26 | { |
25 | 27 | } |
26 | 28 |
|
@@ -81,4 +83,35 @@ public function create(Request $request): Response |
81 | 83 | ]), |
82 | 84 | ]); |
83 | 85 | } |
| 86 | + |
| 87 | + #[Route(path: '/run-oneshot/{id}', name: 'coderhapsodie.ibexa_dataflow.job.run-oneshot', methods: ['GET'])] |
| 88 | + public function runOneShot(int $id): Response |
| 89 | + { |
| 90 | + $this->denyAccessUnlessGranted(new Attribute('ibexa_dataflow', 'view')); |
| 91 | + |
| 92 | + $scheduledDataflow = $this->scheduledDataflowGateway->find($id); |
| 93 | + |
| 94 | + if ($scheduledDataflow === null) { |
| 95 | + throw new NotFoundHttpException(); |
| 96 | + } |
| 97 | + |
| 98 | + $newOneshotJob = new Job(); |
| 99 | + $newOneshotJob->setOptions($scheduledDataflow->getOptions()); |
| 100 | + $newOneshotJob->setLabel("Manual " . $scheduledDataflow->getLabel()); |
| 101 | + $newOneshotJob->setScheduledDataflowId($scheduledDataflow->getId()); |
| 102 | + $newOneshotJob->setRequestedDate((new \DateTime())->add(new \DateInterval('PT1H'))); |
| 103 | + $newOneshotJob->setDataflowType($scheduledDataflow->getDataflowType()); |
| 104 | + |
| 105 | + $form = $this->createForm(CreateOneshotType::class, $newOneshotJob, [ |
| 106 | + 'action' => $this->generateUrl('coderhapsodie.ibexa_dataflow.job.create'), |
| 107 | + ]); |
| 108 | + |
| 109 | + return new JsonResponse([ |
| 110 | + 'form' => $this->renderView('@ibexadesign/ibexa_dataflow/parts/form_modal.html.twig', [ |
| 111 | + 'form' => $form->createView(), |
| 112 | + 'id' => 'modal-new-oneshot', |
| 113 | + 'mode' => 'oneshot', |
| 114 | + ]), |
| 115 | + ]); |
| 116 | + } |
84 | 117 | } |
0 commit comments