Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ProcessDeleteQuick
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
2 / 2
7
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
2
 testProcess
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
5
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\Zmsdb\Process;
12use BO\Zmsdb\ProcessStatusArchived;
13use BO\Zmsdb\Mail;
14use BO\Zmsdb\Config;
15use BO\Mellon\Validator;
16
17class ProcessDeleteQuick extends ProcessDelete
18{
19    /**
20     * @SuppressWarnings(Param)
21     * @return String
22     */
23    public function readResponse(
24        \Psr\Http\Message\RequestInterface $request,
25        \Psr\Http\Message\ResponseInterface $response,
26        array $args
27    ) {
28        $workstation = (new Helper\User($request, 2))->checkRights('basic');
29        \BO\Zmsdb\Connection\Select::getWriteConnection();
30        $process = (new Process())->readEntity($args['id'], new \BO\Zmsdb\Helper\NoAuth(), 2);
31
32        $this->testProcess($workstation, $process);
33
34        $process->status = 'blocked';
35        $this->writeMails($request, $process);
36        $status = (new Process())->writeBlockedEntity($process, false, $workstation->getUseraccount());
37        if (! $status) {
38            throw new Exception\Process\ProcessDeleteFailed(); // @codeCoverageIgnore
39        }
40        $message = Response\Message::create($request);
41        $message->data = $process;
42
43        $response = Render::withLastModified($response, time(), '0');
44        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
45        return $response;
46    }
47
48    protected function testProcess($workstation, $process)
49    {
50        if (!$process->hasId()) {
51            throw new Exception\Process\ProcessNotFound();
52        }
53
54        if (
55            ! in_array(
56                $process->getCurrentScope()->getId(),
57                $workstation->getScopeListFromAssignedDepartments()->getIds()
58            )
59        ) {
60            throw new Exception\Process\ProcessNoAccess();
61        }
62
63        if ('called' == $process->status || 'processing' == $process->status) {
64            throw new Exception\Process\ProcessAlreadyCalled();
65        }
66        $process->testValid();
67    }
68}