accountService = $service;
$this->mailboxSync = $mailboxSync;
$this->syncService = $messageSync;
$this->logger = $logger;
}
/**
* @return void
*/
protected function configure() {
$this->setName('mail:account:sync');
$this->setDescription('Synchronize an IMAP account');
$this->addArgument(self::ARGUMENT_ACCOUNT_ID, InputArgument::REQUIRED);
$this->addOption(self::OPTION_FORCE, 'f', InputOption::VALUE_NONE);
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$accountId = (int)$input->getArgument(self::ARGUMENT_ACCOUNT_ID);
$force = $input->getOption(self::OPTION_FORCE);
try {
$account = $this->accountService->findById($accountId);
} catch (DoesNotExistException $e) {
$output->writeln("Account $accountId does not exist");
return 1;
}
$this->sync($account, $force, $output);
$mbs = (int)(memory_get_peak_usage() / 1024 / 1024);
$output->writeln('' . $mbs . 'MB of memory used');
return 0;
}
private function sync(Account $account, bool $force, OutputInterface $output): void {
$consoleLogger = new ConsoleLoggerDecorator(
$this->logger,
$output
);
try {
$this->mailboxSync->sync($account, $consoleLogger, $force);
$this->syncService->syncAccount($account, $consoleLogger, $force);
} catch (ServiceException $e) {
if (!($e instanceof IncompleteSyncException)) {
throw $e;
}
$mbs = (int)(memory_get_usage() / 1024 / 1024);
$output->writeln("Batch of new messages sync'ed. " . $mbs . 'MB of memory in use');
$this->sync($account, $force, $output);
}
}
}