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 \Psr\Http\Message\ResponseInterface
22     */
23    #[\Override]
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, 2))->checkPermissions('appointment');
30        \BO\Zmsdb\Connection\Select::getWriteConnection();
31        $process = (new Process())->readEntity($args['id'], new \BO\Zmsdb\Helper\NoAuth(), 2);
32
33        $this->testProcess($workstation, $process);
34
35        if ($process->hasId() && $process->scope && $process->status == 'confirmed') {
36            (new \BO\Zmsdb\OverviewCalendar())->perform(
37                \BO\Zmsdb\Query\OverviewCalendar::CANCEL_BY_PROCESS,
38                ['process_id' => (int)$process->id]
39            );
40        }
41        $process->status = 'blocked';
42        $this->writeMails($request, $process);
43        $status = (new Process())->writeBlockedEntity($process, false, $workstation->getUseraccount());
44        if (!$status) {
45            throw new Exception\Process\ProcessDeleteFailed(); // @codeCoverageIgnore
46        }
47        $message = Response\Message::create($request);
48        $message->data = $process;
49
50        $response = Render::withLastModified($response, time(), '0');
51        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
52        return $response;
53    }
54
55    protected function testProcess($workstation, $process)
56    {
57        if (!$process->hasId()) {
58            throw new Exception\Process\ProcessNotFound();
59        }
60
61        if (
62            !in_array(
63                $process->getCurrentScope()->getId(),
64                $workstation->getScopeListFromAssignedDepartments()->getIds()
65            )
66        ) {
67            throw new Exception\Process\ProcessNoAccess();
68        }
69
70        if ('called' == $process->status || 'processing' == $process->status) {
71            throw new Exception\Process\ProcessAlreadyCalled();
72        }
73        $process->testValid();
74    }
75}