Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
35 / 35 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ProcessQueued | |
100.00% |
35 / 35 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
| readResponse | |
100.00% |
29 / 29 |
|
100.00% |
1 / 1 |
3 | |||
| testProcessData | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @package ZMS API |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
| 6 | **/ |
| 7 | |
| 8 | namespace BO\Zmsapi; |
| 9 | |
| 10 | use BO\Slim\Render; |
| 11 | use BO\Mellon\Validator; |
| 12 | use BO\Zmsdb\Process as Query; |
| 13 | use BO\Zmsdb\ProcessStatusQueued; |
| 14 | |
| 15 | /** |
| 16 | * @SuppressWarnings(Coupling) |
| 17 | */ |
| 18 | class ProcessQueued extends BaseController |
| 19 | { |
| 20 | /** |
| 21 | * @SuppressWarnings(Param) |
| 22 | * @return String |
| 23 | */ |
| 24 | public function readResponse( |
| 25 | \Psr\Http\Message\RequestInterface $request, |
| 26 | \Psr\Http\Message\ResponseInterface $response, |
| 27 | array $args |
| 28 | ) { |
| 29 | $workstation = (new Helper\User($request))->checkRights(); |
| 30 | $input = Validator::input()->isJson()->assertValid()->getValue(); |
| 31 | $entity = new \BO\Zmsentities\Process($input); |
| 32 | $entity->testValid(); |
| 33 | $this->testProcessData($entity); |
| 34 | $process = (new Query())->readEntity($entity['id'], $entity['authKey'], 1); |
| 35 | $previousStatus = $process->status; |
| 36 | if (isset($entity->queue['waitingTime'])) { |
| 37 | $process->queue['waitingTime'] = $entity->queue['waitingTime']; |
| 38 | } |
| 39 | if (isset($entity->queue['arrivalTime'])) { |
| 40 | $process->queue['arrivalTime'] = $entity->queue['arrivalTime']; |
| 41 | } |
| 42 | $process->status = 'queued'; |
| 43 | $process->queue['callCount'] = 0; |
| 44 | $process->queue['lastCallTime'] = 0; |
| 45 | $process->queue['priority'] = $entity->getPriority(); |
| 46 | $cluster = (new \BO\Zmsdb\Cluster())->readByScopeId($workstation->scope['id'], 1); |
| 47 | $workstation->validateProcessScopeAccess($workstation->getScopeList($cluster), $process); |
| 48 | $process = (new Query())->updateEntity( |
| 49 | $process, |
| 50 | \App::$now, |
| 51 | 0, |
| 52 | $previousStatus, |
| 53 | $workstation->getUseraccount() |
| 54 | ); |
| 55 | $message = Response\Message::create($request); |
| 56 | $message->data = $process; |
| 57 | |
| 58 | $response = Render::withLastModified($response, time(), '0'); |
| 59 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); |
| 60 | return $response; |
| 61 | } |
| 62 | |
| 63 | protected function testProcessData($entity) |
| 64 | { |
| 65 | $authCheck = (new Query())->readAuthKeyByProcessId($entity->id); |
| 66 | if (! $authCheck) { |
| 67 | throw new Exception\Process\ProcessNotFound(); |
| 68 | } elseif ($authCheck['authKey'] != $entity->authKey && $authCheck['authName'] != $entity->authKey) { |
| 69 | throw new Exception\Process\AuthKeyMatchFailed(); |
| 70 | } |
| 71 | Helper\Matching::testCurrentScopeHasRequest($entity); |
| 72 | } |
| 73 | } |