Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ProcessDeleteQuick
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
2 / 2
10
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
5
 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        if ($process->hasId() && $process->scope && $process->status !== 'cancelled') {
36            (new \BO\Zmsdb\OverallCalendar())->unbook(
37                (int) $process->scope->id,
38                (int) $process->id
39            );
40        }
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}