Lines
70.68%
41 / 58
Methods
50.00%
3 / 6
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| readResponse | 78.94% | 15 / 19 | 0.00% | 0 / 1 | 5.23 | ||
| testProcess | 100.00% | 10 / 10 | 100.00% | 1 / 1 | 5 | ||
| [BO\Zmsbackend\Process\Api\ProcessDelete] writeMails | 8.33% | 1 / 12 | 0.00% | 0 / 1 | 16.32 | ||
| [BO\Zmsbackend\Process\Api\ProcessDelete] writeCancelSearchHistory | 80.00% | 8 / 10 | 0.00% | 0 / 1 | 4.13 | ||
| [BO\Zmsbackend\Process\Api\ProcessDelete] testProcessData | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 3 | ||
| [BO\Zmsbackend\Api\BaseController] __invoke | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| 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 | } |
Inherited from BO\Zmsbackend\Process\Api\ProcessDelete
| 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 | } |
| 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 | } |
| 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 | } |
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 | } |