Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
93.10% |
27 / 29 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ProcessDeleteMail | |
93.10% |
27 / 29 |
|
66.67% |
2 / 3 |
8.02 | |
0.00% |
0 / 1 |
readResponse | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
writeMail | |
83.33% |
10 / 12 |
|
0.00% |
0 / 1 |
3.04 | |||
testProcessData | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 |
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\Mail as Query; |
13 | use BO\Zmsdb\Config; |
14 | use BO\Zmsdb\Process as ProcessRepository; |
15 | use BO\Zmsdb\Department as DepartmentRepository; |
16 | use BO\Zmsentities\Process; |
17 | |
18 | /** |
19 | * @SuppressWarnings(Coupling) |
20 | */ |
21 | class ProcessDeleteMail extends BaseController |
22 | { |
23 | /** |
24 | * @SuppressWarnings(Param) |
25 | * @return string |
26 | */ |
27 | public function readResponse( |
28 | \Psr\Http\Message\RequestInterface $request, |
29 | \Psr\Http\Message\ResponseInterface $response, |
30 | array $args |
31 | ) { |
32 | $input = Validator::input()->isJson()->assertValid()->getValue(); |
33 | $process = new Process($input); |
34 | |
35 | $process->testValid(); |
36 | $this->testProcessData($process); |
37 | |
38 | \BO\Zmsdb\Connection\Select::getWriteConnection(); |
39 | |
40 | $mail = $this->writeMail($process); |
41 | |
42 | $message = Response\Message::create($request); |
43 | $message->data = $mail; |
44 | |
45 | $response = Render::withLastModified($response, time(), '0'); |
46 | $response = Render::withJson($response, $message, 200); |
47 | return $response; |
48 | } |
49 | |
50 | protected static function writeMail(Process $process) |
51 | { |
52 | $config = (new Config())->readEntity(); |
53 | $department = (new DepartmentRepository())->readByScopeId($process->scope['id']); |
54 | $collection = ProcessConfirmationMail::getProcessListOverview($process, $config); |
55 | |
56 | $mail = (new \BO\Zmsentities\Mail()) |
57 | ->setTemplateProvider(new \BO\Zmsdb\Helper\MailTemplateProvider($process)) |
58 | ->toResolvedEntity($collection, $config, 'deleted') |
59 | ->withDepartment($department); |
60 | $mail->testValid(); |
61 | if ($process->getFirstClient()->hasEmail() && $process->scope->hasEmailFrom()) { |
62 | $mail = (new \BO\Zmsdb\Mail())->writeInQueue($mail, \App::$now, false); |
63 | \App::$log->debug("Send mail", [$mail]); |
64 | } |
65 | return $mail; |
66 | } |
67 | |
68 | protected function testProcessData($process) |
69 | { |
70 | $authCheck = (new ProcessRepository())->readAuthKeyByProcessId($process->getId()); |
71 | if (! $authCheck) { |
72 | throw new Exception\Process\ProcessNotFound(); |
73 | } elseif ( |
74 | $process->toProperty()->scope->preferences->client->emailRequired->get() && |
75 | ! $process->getFirstClient()->hasEmail() |
76 | ) { |
77 | throw new Exception\Process\EmailRequired(); |
78 | } |
79 | } |
80 | } |