accountService = $service;
$this->logger = $logger;
}
/**
* @return void
*/
protected function configure() {
$this->setName('mail:account:delete');
$this->setDescription('Delete an IMAP account');
$this->addArgument(self::ARGUMENT_ACCOUNT_ID, InputArgument::REQUIRED);
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$accountId = (int)$input->getArgument(self::ARGUMENT_ACCOUNT_ID);
try {
$account = $this->accountService->findById($accountId);
} catch (DoesNotExistException $e) {
$output->writeLn('This account does not exist');
return 1;
}
$output->writeLn('Found account with email: ' . $account->getEmail() . '');
if (!is_null($account->getMailAccount()->getProvisioningId())) {
$output->writeLn('This is a provisioned account which can not be deleted from CLI. Use the Provisioning UI instead.');
return 2;
}
$output->writeLn('Deleting ' . $account->getEmail() . '');
$this->delete($account, $output);
return 0;
}
private function delete(Account $account, OutputInterface $output): void {
$id = $account->getId();
try {
$this->accountService->deleteByAccountId($account->getId());
} catch (ClientException $e) {
throw $e;
}
$output->writeLn("Deleted account $id ");
}
}