/** * {@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>"); }