/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $pathToIlios2 = $input->getArgument('pathToIlios2'); if (!$this->symfonyFileSystem->exists($pathToIlios2)) { throw new \Exception("'{$pathToIlios2}' does not exist."); } $totalLearningMaterialsCount = $this->learningMaterialManager->getTotalFileLearningMaterialCount(); $helper = $this->getHelper('question'); $output->writeln(''); $question = new ConfirmationQuestion('<question>Ready to copy ' . $totalLearningMaterialsCount . ' learning materials. Shall we continue? </question>' . "\n", true); if ($helper->ask($input, $output, $question)) { $progress = new ProgressBar($output, $totalLearningMaterialsCount); $progress->setRedrawFrequency(208); $output->writeln("<info>Starting migration of learning materials...</info>"); $progress->start(); $migrated = 0; $skipped = 0; $offset = 0; $limit = 50; while ($migrated + $skipped < $totalLearningMaterialsCount) { $learningMaterials = $this->learningMaterialManager->findFileLearningMaterials($limit, $offset); foreach ($learningMaterials as $lm) { $fullPath = $pathToIlios2 . $lm->getRelativePath(); if (!$this->symfonyFileSystem->exists($fullPath)) { $skipped++; } else { $file = $this->iliosFileSystem->getSymfonyFileForPath($fullPath); $newPath = $this->iliosFileSystem->storeLearningMaterialFile($file); $lm->setRelativePath($newPath); $this->learningMaterialManager->update($lm, false); $migrated++; } $progress->advance(); } $this->learningMaterialManager->flushAndClear(); $offset += $limit; } $progress->finish(); $output->writeln(''); $output->writeln("<info>Migrated {$migrated} learning materials successfully!</info>"); if ($skipped) { $msg = "<comment>Skipped {$skipped} learning materials because they could not be located " . "or were already migrated.</comment>"; $output->writeln($msg); } } else { $output->writeln('<comment>Migration canceled.</comment>'); } }
/** * Purify learning material description * @param OutputInterface $output */ protected function purifyLearnignMaterialDescription(OutputInterface $output) { $cleaned = 0; $offset = 1; $limit = self::QUERY_LIMIT; $total = $this->learningMaterialManager->getTotalLearningMaterialCount(); $progress = new ProgressBar($output, $total); $progress->setRedrawFrequency(208); $output->writeln("<info>Starting cleanup of learning material description...</info>"); $progress->start(); do { $materials = $this->learningMaterialManager->findBy(array(), array('id' => 'ASC'), $limit, $offset); foreach ($materials as $material) { $original = $material->getDescription(); $clean = $this->purifier->purify($original); if ($original != $clean) { $cleaned++; $material->setDescription($clean); $this->learningMaterialManager->update($material, false); } $progress->advance(); } $offset += $limit; $this->em->flush(); $this->em->clear(); } while (count($materials) == $limit); $progress->finish(); $output->writeln(''); $output->writeln("<info>{$cleaned} Learning Material Descriptions updated.</info>"); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $totalLearningMaterialsCount = $this->learningMaterialManager->getTotalFileLearningMaterialCount(); $progress = new ProgressBar($output, $totalLearningMaterialsCount); $progress->setRedrawFrequency(208); $output->writeln("<info>Starting validate of learning materials...</info>"); $progress->start(); $valid = 0; $broken = []; $offset = 0; $limit = 500; while ($valid + count($broken) < $totalLearningMaterialsCount) { $learningMaterials = $this->learningMaterialManager->findFileLearningMaterials($limit, $offset); foreach ($learningMaterials as $lm) { if ($this->iliosFileSystem->checkLearningMaterialFilePath($lm)) { $valid++; } else { $broken[] = ['id' => $lm->getId(), 'path' => $lm->getRelativePath()]; } $progress->advance(); } $offset += $limit; } $progress->finish(); $output->writeln(''); $output->writeln("<info>Validated {$valid} learning materials file path.</info>"); if (count($broken)) { $msg = "<error>Unable to find the files for " . count($broken) . ' learning material.</error>'; $output->writeln($msg); $rows = array_map(function ($arr) { return [$arr['id'], $arr['path']]; }, $broken); $table = new Table($output); $table->setHeaders(array('Learning Material ID', 'Relative Path'))->setRows($rows); $table->render(); } }
/** * @param Registry $em * @param string $class * @param FormFactoryInterface $formFactory */ public function __construct(Registry $em, $class, FormFactoryInterface $formFactory) { $this->formFactory = $formFactory; parent::__construct($em, $class); }