Lines
94.87%
37 / 39
Methods
60.00%
3 / 5
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| readResponse | 93.75% | 15 / 16 | 0.00% | 0 / 1 | 2.00 | ||
| writeMail | 100.00% | 12 / 12 | 100.00% | 1 / 1 | 3 | ||
| testProcessAccess | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | ||
| testEmailRequired | 66.66% | 2 / 3 | 0.00% | 0 / 1 | 3.33 | ||
| [BO\Zmsbackend\Api\BaseController] __invoke | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| 21 | class ProcessDeleteMail extends \BO\Zmsbackend\Api\BaseController | |
| 22 | { | |
| 23 | /** | |
| 24 | * @SuppressWarnings(Param) | |
| 25 | * @return string | |
| 26 | */ | |
| 27 | #[\Override] | |
| 28 | public function readResponse( | |
| 29 | \Psr\Http\Message\RequestInterface $request, | |
| 30 | \Psr\Http\Message\ResponseInterface $response, | |
| 31 | array $args | |
| 32 | ) { | |
| 33 | $input = Validator::input()->isJson()->assertValid()->getValue(); | |
| 34 | $process = new Process($input); | |
| 35 | $initiator = Validator::param('initiator')->isString()->getValue(); | |
| 36 | ||
| 37 | $process->testValid(); | |
| 38 | $this->testProcessAccess($process); | |
| 39 | $process = (new ProcessRepository())->readEntity($process->id, $process->authKey); | |
| 40 | if (!$process instanceof Process) { | |
| 41 | throw new \BO\Zmsbackend\Process\Exception\ProcessNotFound(); | |
| 42 | } | |
| 43 | $this->testEmailRequired($process); | |
| 44 | ||
| 45 | \BO\Zmsbackend\Connection\Select::getWriteConnection(); | |
| 46 | ||
| 47 | $mail = $this->writeMail($process, $initiator); | |
| 48 | ||
| 49 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 50 | $message->data = $mail; | |
| 51 | ||
| 52 | $response = Render::withLastModified($response, time(), '0'); | |
| 53 | $response = Render::withJson($response, $message, 200); | |
| 54 | return $response; | |
| 55 | } | |
| 56 | ||
| 57 | protected static function writeMail(Process $process, $initiator = null) | |
| 58 | { | |
| 59 | $config = (new \BO\Zmsbackend\Config\Service\Config())->readEntity(); | |
| 60 | $department = (new DepartmentRepository())->readByScopeId($process->scope->id); | |
| 61 | $collection = ProcessConfirmationMail::getProcessListOverview($process, $config); | |
| 62 | ||
| 63 | $mail = (new \BO\Zmsentities\Mail()) | |
| 64 | ->setTemplateProvider(new \BO\Zmsbackend\Helper\MailTemplateProvider($process)) | |
| 65 | ->toResolvedEntity($collection, $config, 'deleted', $initiator) | |
| 66 | ->withDepartment($department); | |
| 67 | $mail->testValid(); | |
| 68 | if ($process->getFirstClient()->hasEmail() && $process->scope->hasEmailFrom()) { | |
| 69 | $mail = (new \BO\Zmsbackend\Mail\Service\Mail())->writeInQueue($mail, \App::$now, false); | |
| 70 | \App::$log->debug("Send mail", [$mail]); | |
| 71 | } | |
| 72 | return $mail; | |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * @return void | |
| 77 | */ | |
| 78 | protected function testProcessAccess(Process $process) | |
| 79 | { | |
| 80 | $authCheck = (new ProcessRepository())->readAuthKeyByProcessId($process->getId()); | |
| 81 | if (! $authCheck) { | |
| 82 | throw new \BO\Zmsbackend\Process\Exception\ProcessNotFound(); | |
| 83 | } | |
| 84 | if ($authCheck['authKey'] !== $process->authKey) { | |
| 85 | throw new \BO\Zmsbackend\Process\Exception\AuthKeyMatchFailed(); | |
| 86 | } | |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * @return void | |
| 91 | */ | |
| 92 | protected function testEmailRequired(Process $process) | |
| 93 | { | |
| 94 | if ( | |
| 95 | $process->toProperty()->scope->preferences->client->emailRequired->get() && | |
| 96 | ! $process->getFirstClient()->hasEmail() | |
| 97 | ) { | |
| 98 | throw new \BO\Zmsbackend\Process\Exception\EmailRequired(); | |
| 99 | } | |
| 100 | } | |
| 101 | } |
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 | } |