getBody(); $json = \Safe\json_decode($body->getContents()); if (!isset($json->messages)) { throw new MissingArgument('messages', 'array', 'messages ids'); } $output = [ 'messages' => $json->messages, 'total' => count($json->messages), 'scheduled' => 0 ]; foreach ($json->messages as $message_id) { if ($service->schedule($message_id)) { $message = $messagesService->getRepository()->fetchById($message_id); $message->doesHaveScheduledDownloads(); $messagesService->getRepository()->save($message); $output['scheduled'] ++; } } return $this->withJson($response, $output); } public function pending(ServerRequestInterface $request, ResponseInterface $response, Service $service): ResponseInterface { $pending = array_map(function(Job $job) { return $job->toArray(); }, $service->getPending()); $output = [ 'total' => count($pending), 'pending' => $pending ]; return $this->withJson($response, $output); } }