Lines
100.00%
23 / 23
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ProcessAddLog | 100.00% | 23 / 23 | 100.00% | 1 / 1 | 2 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 23 / 23 | 100.00% | 1 / 1 | 2 | |||||
| 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\Mellon\Validator; | |
| 12 | use BO\Zmsbackend\Log\Service\Log as Query; | |
| 13 | use BO\Zmsbackend\Process\Service\Process; | |
| 14 | use BO\Zmsentities\Process as ProcessEntity; | |
| 15 | ||
| 16 | class ProcessAddLog extends \BO\Zmsbackend\Api\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 | (new \BO\Zmsbackend\Helper\User($request))->checkPermissions('superuser'); | |
| 29 | ||
| 30 | $processId = Validator::value($args['id'])->isNumber()->getValue(); | |
| 31 | ||
| 32 | /** @var ProcessEntity $process */ | |
| 33 | $process = (new \BO\Zmsbackend\Process\Service\Process())->readById($processId); | |
| 34 | $input = Validator::input()->isJson()->assertValid()->getValue(); | |
| 35 | $mimepart = new \BO\Zmsentities\Mimepart($input); | |
| 36 | $mimepart->testValid(); | |
| 37 | ||
| 38 | $isError = Validator::param('error')->isNumber()->setDefault(0)->getValue(); | |
| 39 | if ($isError) { | |
| 40 | Query::writeProcessLog( | |
| 41 | "MTA failed, message=" . $mimepart->content, | |
| 42 | Query::ACTION_MAIL_FAIL, | |
| 43 | $process | |
| 44 | ); | |
| 45 | } else { | |
| 46 | Query::writeProcessLog( | |
| 47 | "MTA successful, subject=" . $mimepart->content, | |
| 48 | Query::ACTION_MAIL_SUCCESS, | |
| 49 | $process | |
| 50 | ); | |
| 51 | } | |
| 52 | ||
| 53 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 54 | $message->data = $mimepart; | |
| 55 | ||
| 56 | $response = Render::withLastModified($response, time(), '0'); | |
| 57 | $response = Render::withJson($response, $message, 200); | |
| 58 | return $response; | |
| 59 | } | |
| 60 | } |