accountService = $service; $this->classifier = $classifier; $this->logger = $logger; $this->classificationSettingsService = $classificationSettingsService; } protected function configure(): void { $this->setName('mail:account:train'); $this->setDescription('Train the classifier of new messages'); $this->addArgument(self::ARGUMENT_ACCOUNT_ID, InputArgument::REQUIRED); $this->addOption(self::ARGUMENT_SHUFFLE, null, null, 'Shuffle data set before training'); $this->addOption( self::ARGUMENT_DRY_RUN, null, null, 'Don\'t persist classifier after training' ); $this->addOption( self::ARGUMENT_FORCE, null, null, 'Train an estimator even if the classification is disabled by the user' ); } protected function execute(InputInterface $input, OutputInterface $output): int { $accountId = (int)$input->getArgument(self::ARGUMENT_ACCOUNT_ID); $shuffle = (bool)$input->getOption(self::ARGUMENT_SHUFFLE); $dryRun = (bool)$input->getOption(self::ARGUMENT_DRY_RUN); $force = (bool)$input->getOption(self::ARGUMENT_FORCE); try { $account = $this->accountService->findById($accountId); } catch (DoesNotExistException $e) { $output->writeln("account $accountId does not exist"); return 1; } if (!$force && !$this->classificationSettingsService->isClassificationEnabled($account->getUserId())) { $output->writeln("classification is turned off for account $accountId"); return 2; } $consoleLogger = new ConsoleLoggerDecorator( $this->logger, $output ); $this->classifier->train( $account, $consoleLogger, null, $shuffle, !$dryRun ); $mbs = (int)(memory_get_peak_usage() / 1024 / 1024); $output->writeln('' . $mbs . 'MB of memory used'); return 0; } }