Changed way to connect to api

This commit is contained in:
2022-11-30 10:40:36 -03:00
parent f8500e061c
commit a5d97729dc
12 changed files with 129 additions and 43 deletions

View File

@ -83,16 +83,25 @@ class Mailboxes
$body = $request->getBody();
$json = \Safe\json_decode($body->getContents());
if (!isset($json->mailboxes)) {
throw new MissingArgument('mailboxes', 'array', 'mailboxes names');
throw new MissingArgument('mailboxes', 'array', 'mailboxes ids');
}
$output = [
'mailboxes' => $json->mailboxes,
'total' => count($json->mailboxes),
'unregistered' => 0
'unregistered' => [
'total' => 0,
'mailboxes' => []
]
];
foreach ($json->mailboxes as $mailbox_name) {
if ($service->unregister($mailbox_name)) {
$output['unregistered'] ++;
foreach ($json->mailboxes as $mailbox_id) {
$mailbox = $service->getRepository()->fetchById($mailbox_id);
if ($service->unregister($mailbox->getName())) {
$output['unregistered']['total'] ++;
$output['unregistered']['mailboxes'] []= [
'id' => $mailbox->getId(),
'name' => $mailbox->getName(),
'unregistered' => true
];
}
}
return $this->withJson($response, $output);