toArray(); },$service->getAll()); $output = [ 'total' => count($attachments), 'attachments' => $attachments ]; return $this->withJson($response, $output); } public function grab(ServerRequestInterface $request, ResponseInterface $response, Service $service, \ProVM\Common\Service\Jobs $jobsService): ResponseInterface { $body = $request->getBody(); $json = \Safe\json_decode($body->getContents()); if (!isset($json->messages)) { throw new MissingArgument('messages', 'array', 'message UIDs'); } $output = [ 'messages' => $json->messages, 'total' => count($json->messages), 'saved' => [ 'attachments' => [], 'total' => 0 ] ]; foreach ($json->messages as $message_id) { if (!$jobsService->isPending($message_id)) { continue; } if ($service->grab($message_id)) { $job = $jobsService->find($message_id); $jobsService->execute($job->getId()); $output['saved']['attachments'] []= $job->toArray(); $output['saved']['total'] ++; } } return $this->withJson($response, $output); } public function get(ServerRequestInterface $request, ResponseInterface $response, Service $service, LoggerInterface $logger, int $attachment_id): ResponseInterface { $attachment = $service->getRepository()->fetchById($attachment_id); $response->withHeader('Content-Type', 'application/pdf'); $response->withHeader('Content-Disposition', "'attachment;filename='{$attachment->getFullFilename()}'"); $response->getBody()->write($service->getFile($attachment_id)); return $response; } }