builder = $builder; $this->logger = $logger; } /** * @return void */ protected function configure() { $this->setName('mail:thread'); $this->setDescription('Build threads from the exported data of an account'); $this->addArgument(self::ARGUMENT_INPUT_FILE, InputArgument::REQUIRED); } protected function execute(InputInterface $input, OutputInterface $output): int { $consoleLogger = new ConsoleLoggerDecorator( $this->logger, $output ); $inputFile = $input->getArgument(self::ARGUMENT_INPUT_FILE); if (!file_exists($inputFile)) { $output->writeln("File $inputFile does not exist"); return 1; } $json = file_get_contents($inputFile); if ($json === false) { $output->writeln('Could not read thread data'); return 2; } $consoleLogger->debug(strlen($json) . 'B read'); $parsed = json_decode($json, true, 512, JSON_THROW_ON_ERROR); $consoleLogger->debug(count($parsed) . ' data sets loaded'); $threadData = array_map(static fn ($serialized) => new DatabaseMessage( $serialized['databaseId'], $serialized['subject'], $serialized['id'], $serialized['references'], $serialized['threadRootId'] ?? null ), $parsed); $threads = $this->builder->build($threadData, $consoleLogger); $output->writeln(count($threads) . ' threads built from ' . count($threadData) . ' messages'); $mbs = (int)(memory_get_peak_usage() / 1024 / 1024); $output->writeln('' . $mbs . 'MB of memory used'); return 0; } }