tmgmt_smartling-8.x-4.11/src/Controller/PushCallbackController.php
src/Controller/PushCallbackController.php
<?php
namespace Drupal\tmgmt_smartling\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\tmgmt\Entity\Job;
use Drupal\tmgmt_extension_suit\Utils\FlowScheduler;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Response;
class PushCallbackController extends ControllerBase {
/**
* @var FlowScheduler
*/
protected $flowScheduler;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('tmgmt_extension_suit.utils.flow_scheduler')
);
}
public function __construct(FlowScheduler $flow_scheduler) {
$this->flowScheduler = $flow_scheduler;
}
public function callback(Request $request) {
$job_id = $request->get('job');
// Check if we have a job.
if (!$job_id) {
throw new NotFoundHttpException();
}
if (!Job::load($job_id)) {
throw new NotFoundHttpException();
}
// Check if we have fileUri and locale.
if (!($request->get('fileUri')) || !($request->get('locale'))) {
throw new NotFoundHttpException();
}
$this->flowScheduler->scheduleDownload($job_id);
return new Response('OK');
}
}
