/** * Purify session learning material note * @param OutputInterface $output */ protected function purifySessionLearningMaterialNote(OutputInterface $output) { $cleaned = 0; $offset = 1; $limit = self::QUERY_LIMIT; $total = $this->sessionLearningMaterialManager->getTotalSessionLearningMaterialCount(); $progress = new ProgressBar($output, $total); $progress->setRedrawFrequency(208); $output->writeln("<info>Starting cleanup of session learning material notes...</info>"); $progress->start(); do { $materials = $this->sessionLearningMaterialManager->findBy(array(), array('id' => 'ASC'), $limit, $offset); foreach ($materials as $material) { $original = $material->getNotes(); $clean = $this->purifier->purify($original); if ($original != $clean) { $cleaned++; $material->setNotes($clean); $this->sessionLearningMaterialManager->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} Session Learning Material Notes updated.</info>"); }