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); } }