Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ProcessQueued
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
1 / 1
1
 testProcessData
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsapi;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsdb\Process as Query;
13use BO\Zmsdb\ProcessStatusQueued;
14
15/**
16 * @SuppressWarnings(Coupling)
17 */
18class 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        $process->status = 'queued';
37        $process->queue['callCount'] = 0;
38        $process->queue['lastCallTime'] = 0;
39        $cluster = (new \BO\Zmsdb\Cluster())->readByScopeId($workstation->scope['id'], 1);
40        $workstation->testMatchingProcessScope($workstation->getScopeList($cluster), $process);
41        $process = (new Query())->updateEntity(
42            $process,
43            \App::$now,
44            0,
45            $previousStatus,
46            $workstation->getUseraccount()
47        );
48        $message = Response\Message::create($request);
49        $message->data = $process;
50
51        $response = Render::withLastModified($response, time(), '0');
52        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
53        return $response;
54    }
55
56    protected function testProcessData($entity)
57    {
58        $authCheck = (new Query())->readAuthKeyByProcessId($entity->id);
59        if (! $authCheck) {
60            throw new Exception\Process\ProcessNotFound();
61        } elseif ($authCheck['authKey'] != $entity->authKey && $authCheck['authName'] != $entity->authKey) {
62            throw new Exception\Process\AuthKeyMatchFailed();
63        }
64        Helper\Matching::testCurrentScopeHasRequest($entity);
65    }
66}