rebuild() 공개 메소드

The end result will be: - new inverse indices will be created - changes to serialisation will be updated on all entities - added/removed fields will be updated on all entities
public rebuild ( string $class_name, integer $batch_size = 100 )
$class_name string
$batch_size integer
예제 #1
0
 /**
  * @dataProvider entityManagerDataProvider
  * @param EntityManager $em
  */
 public function testRebuildIndex(EntityManager $em)
 {
     // Create an article with a slug
     $article = new SluggedArticle();
     $article->setId(8343)->setName('foo')->setSlug('bar');
     $em->persist($article)->flush();
     // Confirm slug works
     /** @var SluggedArticle $article */
     $article = $em->retrieveByIndex(SluggedArticle::class, 'slug', 'bar', false);
     $this->assertEquals('foo', $article->getName());
     $index = $em->getMapper()->getEntityMetadata($article)->getIndexByName('slug');
     // Corrupt the slug, two steps required:
     // 1. Set a new slug
     $em->getDriver()->setSingleValueIndex($em->getKeyScheme()->getIndexKey($index, 'evil'), $article->getId());
     // 2. Remove the correct slug
     $em->getDriver()->clearSingleValueIndex($em->getKeyScheme()->getIndexKey($index, 'bar'));
     $em->getDriver()->flush();
     // Confirm old slug no longer works
     try {
         $em->retrieveByIndex(SluggedArticle::class, 'slug', 'bar', false);
         $this->fail('Old index succeeded');
     } catch (NotFoundException $e) {
     }
     // Confirm new slug does work
     $article = $em->retrieveByIndex(SluggedArticle::class, 'slug', 'evil', false);
     $this->assertEquals('foo', $article->getName());
     // Run maintenance over the table, this should correct the slug
     $maintenance = new Maintenance($em);
     $maintenance->rebuild(SluggedArticle::class);
     // Confirm correct slug works
     $article = $em->retrieveByIndex(SluggedArticle::class, 'slug', 'bar', false);
     $this->assertEquals('foo', $article->getName());
     // The corrupted slug should still work, this is unideal, but there is no reference to it for the maintenance
     // service to know to remove it
     $article = $em->retrieveByIndex(SluggedArticle::class, 'slug', 'evil', false);
     $this->assertEquals('foo', $article->getName());
 }
예제 #2
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $maintenance = new Maintenance($this->getContainer()->get('orm.em'), new OutputLogger($output));
     $maintenance->rebuild(str_replace('/', '\\', $input->getArgument('class')));
 }