/
processes.php
75 lines (62 loc) · 2 KB
/
processes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Concrete\Controller\Backend;
use Concrete\Core\Command\Process\ProcessConfigurationResponseFactory;
use Concrete\Core\Command\Process\ProcessResponseFactory;
use Concrete\Core\Controller\AbstractController;
use Concrete\Core\Entity\Command\Process;
use Concrete\Core\Validation\CSRF\Token;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\JsonResponse;
class Processes extends AbstractController
{
/**
* @var Token
*/
protected $token;
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var
*/
protected $responseFactory;
/**
* @var ProcessConfigurationResponseFactory
*/
protected $configurationResponseFactory;
public function __construct(
Token $token,
EntityManager $entityManager,
ProcessResponseFactory $responseFactory,
ProcessConfigurationResponseFactory $configurationResponseFactory
) {
$this->token = $token;
$this->entityManager = $entityManager;
$this->responseFactory = $responseFactory;
$this->configurationResponseFactory = $configurationResponseFactory;
parent::__construct();
}
public function getConfiguration()
{
if ($this->token->validate()) {
return $this->configurationResponseFactory->createResponse();
}
throw new \Exception(t('Access Denied'));
}
public function poll()
{
if ($this->token->validate('poll', $this->request->request->get('token'))) {
session_write_close();
$processes = [];
foreach ((array) $this->request->request->get('watchedProcessIds') as $processId) {
$process = $this->entityManager->find(Process::class, $processId);
if ($process) {
$processes[] = $process;
}
}
return $this->responseFactory->createResponse($processes);
}
throw new \Exception(t('Access Denied'));
}
}