Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
WorkstationDelete
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
4
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\Mellon\Validator;
12use BO\Zmsdb\Log;
13use BO\Zmsdb\Workstation;
14use BO\Zmsdb\Useraccount;
15
16class WorkstationDelete extends BaseController
17{
18    /**
19     * @SuppressWarnings(Param)
20     * @return \Psr\Http\Message\ResponseInterface
21     */
22    #[\Override]
23    public function readResponse(
24        \Psr\Http\Message\RequestInterface $request,
25        \Psr\Http\Message\ResponseInterface $response,
26        array $args
27    ) {
28        \BO\Zmsdb\Connection\Select::getWriteConnection();
29        $workstation = (new Helper\User($request, 1))->checkPermissions();
30        $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(2)->getValue();
31        if (! (new Useraccount())->readIsUserExisting($args['loginname'])) {
32            throw new Exception\Useraccount\UseraccountNotFound();
33        }
34        if ($workstation->process && $workstation->process->hasId()) {
35            throw new Exception\Workstation\WorkstationHasCalledProcess();
36        }
37
38        $message = Response\Message::create($request);
39        $message->data = (new Workstation())->writeEntityLogoutByName($args['loginname'], $resolveReferences);
40
41        $response = Render::withLastModified($response, time(), '0');
42        $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode());
43
44        \BO\Zmsdb\Log::writeLogEntry(
45            "LOGOUT (WorkstattionDelete::readResponse) " . $args['loginname'],
46            0,
47            Log::PROCESS,
48            $workstation->getScope()->getId(),
49            $workstation->getUseraccount()->getId()
50        );
51
52        return $response;
53    }
54}