entityManager ->getRepository(Upload::class) ->findBy([ 'type' => [Upload::TYPE_INVOICE, Upload::TYPE_CONTRACT], ]); $progressBar = new ProgressBar($output, count($uploads)); $progressBar->start(); foreach ($uploads as $upload) { /** @var Upload $upload */ $filepath = $this->uploadHandler->getUploadFilepath($upload); try { $targetFilepath = $this->sanitizer->sanitizeFile($filepath); $upload ->setFilename(basename($targetFilepath)) ->setMimeType('application/pdf') ; } catch (\Throwable $e) { $output->writeln(''.$e->getMessage().''); } $progressBar->advance(); } $this->entityManager->flush(); $progressBar->finish(); return Command::SUCCESS; } }