Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| 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\Zmsapi; |
| 9 | |
| 10 | use BO\Slim\Render; |
| 11 | use BO\Mellon\Validator; |
| 12 | use BO\Zmsdb\Log as Query; |
| 13 | use BO\Zmsdb\Process; |
| 14 | use BO\Zmsentities\Process as ProcessEntity; |
| 15 | |
| 16 | class ProcessAddLog extends BaseController |
| 17 | { |
| 18 | /** |
| 19 | * @SuppressWarnings(Param) |
| 20 | * @return String |
| 21 | */ |
| 22 | public function readResponse( |
| 23 | \Psr\Http\Message\RequestInterface $request, |
| 24 | \Psr\Http\Message\ResponseInterface $response, |
| 25 | array $args |
| 26 | ) { |
| 27 | (new Helper\User($request))->checkRights('superuser'); |
| 28 | $processId = Validator::value($args['id'])->isNumber()->getValue(); |
| 29 | |
| 30 | /** @var ProcessEntity $process */ |
| 31 | $process = (new Process())->readById($processId); |
| 32 | $input = Validator::input()->isJson()->assertValid()->getValue(); |
| 33 | $mimepart = new \BO\Zmsentities\Mimepart($input); |
| 34 | $mimepart->testValid(); |
| 35 | |
| 36 | $isError = Validator::param('error')->isNumber()->setDefault(0)->getValue(); |
| 37 | if ($isError) { |
| 38 | Query::writeProcessLog( |
| 39 | "MTA failed, message=" . $mimepart->content, |
| 40 | Query::ACTION_MAIL_FAIL, |
| 41 | $process |
| 42 | ); |
| 43 | } else { |
| 44 | Query::writeProcessLog( |
| 45 | "MTA successful, subject=" . $mimepart->content, |
| 46 | Query::ACTION_MAIL_SUCCESS, |
| 47 | $process |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | $message = Response\Message::create($request); |
| 52 | $message->data = $mimepart; |
| 53 | |
| 54 | $response = Render::withLastModified($response, time(), '0'); |
| 55 | $response = Render::withJson($response, $message, 200); |
| 56 | return $response; |
| 57 | } |
| 58 | } |