77use CodeRhapsodie \DataflowBundle \Entity \Job ;
88use CodeRhapsodie \EzDataflowBundle \Form \CreateOneshotType ;
99use CodeRhapsodie \EzDataflowBundle \Gateway \JobGateway ;
10+ use CodeRhapsodie \EzDataflowBundle \Gateway \ScheduledDataflowGateway ;
1011use Ibexa \Contracts \AdminUi \Controller \Controller ;
1112use Ibexa \Contracts \AdminUi \Notification \NotificationHandlerInterface ;
1213use Ibexa \Core \MVC \Symfony \Security \Authorization \Attribute ;
1314use Symfony \Component \HttpFoundation \JsonResponse ;
1415use Symfony \Component \HttpFoundation \Request ;
1516use Symfony \Component \HttpFoundation \Response ;
17+ use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
1618use Symfony \Component \Routing \Annotation \Route ;
1719use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
1820use Symfony \Contracts \Translation \TranslatorInterface ;
@@ -28,15 +30,19 @@ class JobController extends Controller
2830 private $ notificationHandler ;
2931 /** @var \Symfony\Contracts\Translation\TranslatorInterface */
3032 private $ translator ;
33+ /** @var \CodeRhapsodie\EzDataflowBundle\Gateway\ScheduledDataflowGateway */
34+ private $ scheduledDataflowGateway ;
3135
3236 public function __construct (
3337 JobGateway $ jobGateway ,
3438 NotificationHandlerInterface $ notificationHandler ,
35- TranslatorInterface $ translator
39+ TranslatorInterface $ translator ,
40+ ScheduledDataflowGateway $ scheduledDataflowGateway
3641 ) {
3742 $ this ->jobGateway = $ jobGateway ;
3843 $ this ->notificationHandler = $ notificationHandler ;
3944 $ this ->translator = $ translator ;
45+ $ this ->scheduledDataflowGateway = $ scheduledDataflowGateway ;
4046 }
4147
4248 /**
@@ -104,4 +110,37 @@ public function create(Request $request): Response
104110 ]),
105111 ]);
106112 }
113+
114+ /**
115+ * @Route("/run-oneshot/{id}", name="coderhapsodie.ezdataflow.job.run-oneshot", methods={"GET"})
116+ */
117+ public function runOneShot (int $ id ): Response
118+ {
119+ $ this ->denyAccessUnlessGranted (new Attribute ('ezdataflow ' , 'view ' ));
120+
121+ $ scheduledDataflow = $ this ->scheduledDataflowGateway ->find ($ id );
122+
123+ if ($ scheduledDataflow === null ) {
124+ throw new NotFoundHttpException ();
125+ }
126+
127+ $ newOneshotJob = new Job ();
128+ $ newOneshotJob ->setOptions ($ scheduledDataflow ->getOptions ());
129+ $ newOneshotJob ->setLabel ("Manual " . $ scheduledDataflow ->getLabel ());
130+ $ newOneshotJob ->setScheduledDataflowId ($ scheduledDataflow ->getId ());
131+ $ newOneshotJob ->setRequestedDate ((new \DateTime ())->add (new \DateInterval ('PT1H ' )));
132+ $ newOneshotJob ->setDataflowType ($ scheduledDataflow ->getDataflowType ());
133+
134+ $ form = $ this ->createForm (CreateOneshotType::class, $ newOneshotJob , [
135+ 'action ' => $ this ->generateUrl ('coderhapsodie.ezdataflow.job.create ' ),
136+ ]);
137+
138+ return new JsonResponse ([
139+ 'form ' => $ this ->renderView ('@ibexadesign/ezdataflow/parts/form_modal.html.twig ' , [
140+ 'form ' => $ form ->createView (),
141+ 'id ' => 'modal-new-oneshot ' ,
142+ 'mode ' => 'oneshot ' ,
143+ ]),
144+ ]);
145+ }
107146}
0 commit comments