Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.30% covered (success)
96.30%
26 / 27
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProcessDelete
96.30% covered (success)
96.30%
26 / 27
50.00% covered (danger)
50.00%
1 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 readResponse
94.44% covered (success)
94.44%
17 / 18
0.00% covered (danger)
0.00%
0 / 1
2.00
 writeDeleteMailNotifications
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3/**
4 *
5 * @package Zmsadmin
6 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
7 *
8 */
9
10namespace BO\Zmsadmin;
11
12use BO\Mellon\Validator;
13use BO\Slim\Render;
14use BO\Zmsentities\Process;
15
16/**
17 * Delete a process
18 */
19class ProcessDelete extends BaseController
20{
21    /**
22     * @SuppressWarnings(Param)
23     * @return \Psr\Http\Message\ResponseInterface
24     */
25    #[\Override]
26    public function readResponse(
27        \Psr\Http\Message\RequestInterface $request,
28        \Psr\Http\Message\ResponseInterface $response,
29        array $args
30    ): \Psr\Http\Message\ResponseInterface {
31        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 1])->getEntity();
32        $processId = Validator::value($args['id'])->isNumber()->getValue();
33        $initiator = Validator::param('initiator')->isString()->getValue();
34        $process = \App::$http->readGetResult('/process/' . $processId . '/')->getEntity();
35        if (!$process instanceof Process) {
36            throw new \BO\Zmsclient\Exception('Process not found');
37        }
38        $process->status = 'deleted';
39        $workstation->validateProcessScopeAccess((new Helper\ClusterHelper($workstation))->getScopeList(), $process);
40
41        static::writeDeleteMailNotifications($process);
42        \App::$http->readDeleteResult('/process/' . $process->getId() . '/', ['initiator' => $initiator]);
43
44        return \BO\Slim\Render::withHtml(
45            $response,
46            'element/helper/messageHandler.twig',
47            array(
48                'success' => 'process_deleted',
49                'selectedprocess' => $process,
50            )
51        );
52    }
53
54    public static function writeDeleteMailNotifications($process): void
55    {
56        #email only for clients with appointment if email address is given
57        if (
58            $process->getFirstClient()->hasEmail() &&
59            $process->isWithAppointment() &&
60            $process->scope->hasEmailFrom()
61        ) {
62            \App::$http
63                ->readPostResult(
64                    '/process/' . $process->getId() . '/' . $process->getAuthKey() . '/delete/mail/',
65                    $process,
66                    ['initiator' => 'admin']
67                )->getEntity();
68        }
69    }
70}