Exemplo n.º 1
0
 public function testCheckLearningMaterialFilePath()
 {
     $goodLm = m::mock('Ilios\\CoreBundle\\Entity\\LearningMaterial')->shouldReceive('getRelativePath')->andReturn('goodfile')->mock();
     $badLm = m::mock('Ilios\\CoreBundle\\Entity\\LearningMaterial')->shouldReceive('getRelativePath')->andReturn('badfile')->mock();
     $this->mockFileSystem->shouldReceive('exists')->with($this->fakeTestFileDir . '/goodfile')->andReturn(true)->once();
     $this->mockFileSystem->shouldReceive('exists')->with($this->fakeTestFileDir . '/badfile')->andReturn(false)->once();
     $this->assertTrue($this->iliosFileSystem->checkLearningMaterialFilePath($goodLm));
     $this->assertFalse($this->iliosFileSystem->checkLearningMaterialFilePath($badLm));
 }
 /**
  * {@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();
     }
 }