Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
24 / 28
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProcessDeleteQuick
85.71% covered (warning)
85.71%
24 / 28
50.00% covered (danger)
50.00%
1 / 2
10.29
0.00% covered (danger)
0.00%
0 / 1
 readResponse
77.78% covered (warning)
77.78%
14 / 18
0.00% covered (danger)
0.00%
0 / 1
5.27
 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        if ($process->hasId() && $process->scope && $process->status == 'confirmed') {
35            (new \BO\Zmsdb\OverviewCalendar())->perform(
36                \BO\Zmsdb\Query\OverviewCalendar::CANCEL_BY_PROCESS,
37                ['process_id' => (int)$process->id]
38            );
39        }
40        $process->status = 'blocked';
41        $this->writeMails($request, $process);
42        $status = (new Process())->writeBlockedEntity($process, false, $workstation->getUseraccount());
43        if (!$status) {
44            throw new Exception\Process\ProcessDeleteFailed(); // @codeCoverageIgnore
45        }
46        $message = Response\Message::create($request);
47        $message->data = $process;
48
49        $response = Render::withLastModified($response, time(), '0');
50        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
51        return $response;
52    }
53
54    protected function testProcess($workstation, $process)
55    {
56        if (!$process->hasId()) {
57            throw new Exception\Process\ProcessNotFound();
58        }
59
60        if (
61            !in_array(
62                $process->getCurrentScope()->getId(),
63                $workstation->getScopeListFromAssignedDepartments()->getIds()
64            )
65        ) {
66            throw new Exception\Process\ProcessNoAccess();
67        }
68
69        if ('called' == $process->status || 'processing' == $process->status) {
70            throw new Exception\Process\ProcessAlreadyCalled();
71        }
72        $process->testValid();
73    }
74}