Lines
86.20%
25 / 29
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ProcessDeleteQuick | 86.20% | 25 / 29 | 50.00% | 1 / 2 | 10.26 | 0.00% | 0 / 1 | |||
| readResponse | 78.94% | 15 / 19 | 0.00% | 0 / 1 | 5.23 | |||||
| testProcess | 100.00% | 10 / 10 | 100.00% | 1 / 1 | 5 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package ZMS API | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsbackend\Process\Api; | |
| 9 | ||
| 10 | use BO\Slim\Render; | |
| 11 | use BO\Zmsbackend\Process\Service\Process; | |
| 12 | use BO\Zmsbackend\Process\Service\ProcessStatusArchived; | |
| 13 | use BO\Zmsbackend\ProcessSearchHistory\Service\ProcessSearchHistory as HistoryService; | |
| 14 | use BO\Zmsbackend\Mail\Service\Mail; | |
| 15 | use BO\Zmsbackend\Config\Service\Config; | |
| 16 | use BO\Mellon\Validator; | |
| 17 | ||
| 18 | class ProcessDeleteQuick extends ProcessDelete | |
| 19 | { | |
| 20 | /** | |
| 21 | * @SuppressWarnings(Param) | |
| 22 | * @return \Psr\Http\Message\ResponseInterface | |
| 23 | */ | |
| 24 | #[\Override] | |
| 25 | public function readResponse( | |
| 26 | \Psr\Http\Message\RequestInterface $request, | |
| 27 | \Psr\Http\Message\ResponseInterface $response, | |
| 28 | array $args | |
| 29 | ) { | |
| 30 | $workstation = (new \BO\Zmsbackend\Helper\User($request, 2))->checkPermissions('appointment'); | |
| 31 | \BO\Zmsbackend\Connection\Select::getWriteConnection(); | |
| 32 | $process = (new \BO\Zmsbackend\Process\Service\Process())->readEntity($args['id'], new \BO\Zmsbackend\Helper\NoAuth(), 2); | |
| 33 | ||
| 34 | $this->testProcess($workstation, $process); | |
| 35 | $this->writeCancelSearchHistory($process, HistoryService::STATUS_CANCELLED_BY_STAFF); | |
| 36 | ||
| 37 | if ($process->hasId() && $process->scope && $process->status == 'confirmed') { | |
| 38 | (new \BO\Zmsbackend\OverviewCalendar\Service\OverviewCalendar())->perform( | |
| 39 | \BO\Zmsbackend\Calendar\Repository\OverviewCalendar::CANCEL_BY_PROCESS, | |
| 40 | ['process_id' => (int)$process->id] | |
| 41 | ); | |
| 42 | } | |
| 43 | $process->status = 'blocked'; | |
| 44 | $this->writeMails($request, $process); | |
| 45 | $status = (new \BO\Zmsbackend\Process\Service\Process())->writeBlockedEntity($process, false, $workstation->getUseraccount()); | |
| 46 | if (!$status) { | |
| 47 | throw new \BO\Zmsbackend\Process\Exception\ProcessDeleteFailed(); // @codeCoverageIgnore | |
| 48 | } | |
| 49 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 50 | $message->data = $process; | |
| 51 | ||
| 52 | $response = Render::withLastModified($response, time(), '0'); | |
| 53 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 54 | return $response; | |
| 55 | } | |
| 56 | ||
| 57 | /** | |
| 58 | * @return void | |
| 59 | */ | |
| 60 | protected function testProcess($workstation, \BO\Zmsentities\Process|null $process) | |
| 61 | { | |
| 62 | if (!$process->hasId()) { | |
| 63 | throw new \BO\Zmsbackend\Process\Exception\ProcessNotFound(); | |
| 64 | } | |
| 65 | ||
| 66 | if ( | |
| 67 | !in_array( | |
| 68 | $process->getCurrentScope()->getId(), | |
| 69 | $workstation->getScopeListFromAssignedDepartments()->getIds() | |
| 70 | ) | |
| 71 | ) { | |
| 72 | throw new \BO\Zmsbackend\Process\Exception\ProcessNoAccess(); | |
| 73 | } | |
| 74 | ||
| 75 | if ('called' == $process->status || 'processing' == $process->status) { | |
| 76 | throw new \BO\Zmsbackend\Process\Exception\ProcessAlreadyCalled(); | |
| 77 | } | |
| 78 | $process->testValid(); | |
| 79 | } | |
| 80 | } |