/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $pathToIlios2 = $input->getArgument('pathToIlios2'); if (!$this->symfonyFileSystem->exists($pathToIlios2)) { throw new \Exception("'{$pathToIlios2}' does not exist."); } $learningMaterials = $this->learningMaterialManager->findFileLearningMaterials(); $helper = $this->getHelper('question'); $output->writeln(''); $question = new ConfirmationQuestion('<question>Ready to copy ' . count($learningMaterials) . ' learning materials. Shall we continue? </question>' . "\n", true); if ($helper->ask($input, $output, $question)) { $migrated = 0; foreach ($learningMaterials as $lm) { $fullPath = $pathToIlios2 . $lm->getRelativePath(); if (!$this->symfonyFileSystem->exists($fullPath)) { throw new \Exception('Unable to migrated learning material #' . $lm->getId() . ". No file found at '{$fullPath}'."); } $file = $this->iliosFileSystem->getSymfonyFileForPath($fullPath); $newPath = $this->iliosFileSystem->storeLearningMaterialFile($file); $lm->setRelativePath($newPath); $this->learningMaterialManager->updateLearningMaterial($lm, false); $migrated++; if ($migrated % 500) { $this->learningMaterialManager->flushAndClear(); } } $this->learningMaterialManager->flushAndClear(); $output->writeln("<info>Migrated {$migrated} learning materials successfully!</info>"); } else { $output->writeln('<comment>Migration canceled.</comment>'); } }
/** * {@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>'); } }
/** * {@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(); } }
public function testGetSymfonyFileForPath() { $fs = new SymfonyFileSystem(); $someJunk = 'whatever dude'; $hash = md5($someJunk); $hashDirectory = substr($hash, 0, 2); $parts = [$this->fakeTestFileDir, 'learning_materials', 'lm', $hashDirectory]; $dir = implode($parts, '/'); $fs->mkdir($dir); $testFilePath = $dir . '/' . $hash; file_put_contents($testFilePath, $someJunk); $file = $this->iliosFileSystem->getSymfonyFileForPath($testFilePath); $this->assertTrue($file instanceof File); $this->assertSame($testFilePath, $file->getPathname()); $this->assertSame(file_get_contents($file->getPathname()), $someJunk); $fs->remove($this->fakeTestFileDir . '/learning_materials'); }