generated from Nodarx/template
feat: add cache harmonize command
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -98,6 +98,33 @@ class HarmonizationService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Harmonize the mailbox list, then the messages of every selectable mailbox.
|
||||
*
|
||||
* A failing mailbox does not stop the others; its error is reported instead.
|
||||
*
|
||||
* @return array{mailboxes: array{added: string[], updated: string[], removed: string[]}, messages: array<string, array|string>}
|
||||
*/
|
||||
public function harmonizeAll(): array
|
||||
{
|
||||
[$service] = $this->bound();
|
||||
$mailboxes = $this->harmonizeMailboxes();
|
||||
|
||||
$messages = [];
|
||||
foreach ($this->mailboxStore->list((string) $service->identifier()) as $name => $document) {
|
||||
if (!self::isSelectable($document)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$messages[$name] = $this->harmonizeMessages((string) $name);
|
||||
} catch (\Throwable $e) {
|
||||
$messages[$name] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
return ['mailboxes' => $mailboxes, 'messages' => $messages];
|
||||
}
|
||||
|
||||
/**
|
||||
* Harmonize the messages of one mailbox with the server.
|
||||
*
|
||||
@@ -252,6 +279,20 @@ class HarmonizationService
|
||||
return [$this->service, $this->live];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a cached mailbox document describes a mailbox that can be selected.
|
||||
*/
|
||||
private static function isSelectable(array $document): bool
|
||||
{
|
||||
foreach ((array) ($document['properties']['attributes'] ?? []) as $attribute) {
|
||||
if (in_array(strtolower((string) $attribute), ['\\noselect', '\\nonexistent'], true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $names
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user