Lines
75.92%
41 / 54
Methods
60.00%
3 / 5
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| readResponse | 100.00% | 25 / 25 | 100.00% | 1 / 1 | 5 | ||
| writeMails | 8.33% | 1 / 12 | 0.00% | 0 / 1 | 16.32 | ||
| writeCancelSearchHistory | 80.00% | 8 / 10 | 0.00% | 0 / 1 | 4.13 | ||
| testProcessData | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 3 | ||
| [BO\Zmsbackend\Api\BaseController] __invoke | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| 20 | class ProcessDelete extends \BO\Zmsbackend\Api\BaseController | |
| 21 | { | |
| 22 | /** | |
| 23 | * @SuppressWarnings(Param) | |
| 24 | * @return \Psr\Http\Message\ResponseInterface | |
| 25 | */ | |
| 26 | #[\Override] | |
| 27 | public function readResponse( | |
| 28 | \Psr\Http\Message\RequestInterface $request, | |
| 29 | \Psr\Http\Message\ResponseInterface $response, | |
| 30 | array $args | |
| 31 | ) { | |
| 32 | $workstation = (new \BO\Zmsbackend\Helper\User($request))->readWorkstation(); | |
| 33 | \BO\Zmsbackend\Connection\Select::getWriteConnection(); | |
| 34 | $process = (new \BO\Zmsbackend\Process\Service\Process())->readEntity($args['id'], new \BO\Zmsbackend\Helper\NoAuth(), 2); | |
| 35 | $this->testProcessData($process, $args['authKey']); | |
| 36 | $this->writeCancelSearchHistory($process, HistoryService::STATUS_CANCELLED_BY_CITIZEN); | |
| 37 | if ('reserved' == $process->status) { | |
| 38 | if (!(new \BO\Zmsbackend\Process\Service\Process())->writeBlockedEntity($process, false, $workstation->getUseraccount())) { | |
| 39 | throw new \BO\Zmsbackend\Process\Exception\ProcessDeleteFailed(); // @codeCoverageIgnore | |
| 40 | } | |
| 41 | $processDeleted = $process; | |
| 42 | } else { | |
| 43 | (new \BO\Zmsbackend\OverviewCalendar\Service\OverviewCalendar())->perform( | |
| 44 | \BO\Zmsbackend\Calendar\Repository\OverviewCalendar::CANCEL_BY_PROCESS, | |
| 45 | ['process_id' => (int)$process->id] | |
| 46 | ); | |
| 47 | ||
| 48 | $processDeleted = (new \BO\Zmsbackend\Process\Service\Process())->writeCanceledEntity( | |
| 49 | $args['id'], | |
| 50 | $args['authKey'], | |
| 51 | null, | |
| 52 | $workstation->getUseraccount() | |
| 53 | ); | |
| 54 | if (!$processDeleted || !$processDeleted->hasId()) { | |
| 55 | throw new \BO\Zmsbackend\Process\Exception\ProcessDeleteFailed(); // @codeCoverageIgnore | |
| 56 | } | |
| 57 | } | |
| 58 | $this->writeMails($request, $process); | |
| 59 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 60 | $message->data = $processDeleted; | |
| 61 | ||
| 62 | $response = Render::withLastModified($response, time(), '0'); | |
| 63 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 64 | return $response; | |
| 65 | } | |
| 66 | ||
| 67 | protected function writeMails(\Psr\Http\Message\RequestInterface $request, \BO\Zmsentities\Process|null $process): void | |
| 68 | { | |
| 69 | if ($process->hasScopeAdmin() && $process->sendAdminMailOnDeleted() && $process->getStatus() !== 'blocked') { | |
| 70 | $authority = $request->getUri()->getAuthority(); | |
| 71 | $validator = $request->getAttribute('validator'); | |
| 72 | $initiator = $validator->getParameter('initiator') | |
| 73 | ->isString() | |
| 74 | ->setDefault("$authority API-User") | |
| 75 | ->getValue(); | |
| 76 | $config = (new \BO\Zmsbackend\Config\Service\Config())->readEntity(); | |
| 77 | $mail = (new \BO\Zmsentities\Mail()) | |
| 78 | ->setTemplateProvider(new \BO\Zmsbackend\Helper\MailTemplateProvider($process)) | |
| 79 | ->toResolvedEntity($process, $config, 'deleted', $initiator); | |
| 80 | (new \BO\Zmsbackend\Mail\Service\Mail())->writeInQueueWithAdmin($mail, \App::$now); | |
| 81 | } | |
| 82 | } | |
| 83 | ||
| 84 | protected function writeCancelSearchHistory( | |
| 85 | \BO\Zmsentities\Process $process, | |
| 86 | string $historyStatus | |
| 87 | ): void { | |
| 88 | if (!$process->hasProcessCredentials()) { | |
| 89 | return; | |
| 90 | } | |
| 91 | ||
| 92 | $now = class_exists('\App') && isset(\App::$now) | |
| 93 | ? \App::$now | |
| 94 | : new \DateTimeImmutable(); | |
| 95 | ||
| 96 | (new HistoryService())->writeHistoryEntry( | |
| 97 | $process, | |
| 98 | $historyStatus, | |
| 99 | $now | |
| 100 | ); | |
| 101 | } | |
| 102 | ||
| 103 | /** | |
| 104 | * @return void | |
| 105 | */ | |
| 106 | protected function testProcessData(\BO\Zmsentities\Process|null $process, $authKey) | |
| 107 | { | |
| 108 | if (!$process) { | |
| 109 | throw new \BO\Zmsbackend\Process\Exception\ProcessNotFound(); | |
| 110 | } | |
| 111 | if ($process['authKey'] !== $authKey) { | |
| 112 | throw new \BO\Zmsbackend\Process\Exception\AuthKeyMatchFailed(); | |
| 113 | } | |
| 114 | } | |
| 115 | } |
Inherited from BO\Zmsbackend\Api\BaseController
| 20 | public function __invoke(RequestInterface $request, ResponseInterface $response, array $args) | |
| 21 | { | |
| 22 | $request = $this->initRequest($request); | |
| 23 | $noCacheResponse = \BO\Slim\Render::withLastModified($response, time(), '0'); | |
| 24 | return $this->readResponse($request, $noCacheResponse, $args); | |
| 25 | } |