protected function refreshTerms(AdapterInterface $console, $percentile)
 {
     $filter = new NotTrashedCollectionFilter();
     $terms = $this->taxonomyManager->findAllTerms(true);
     $terms = $filter->filter($terms);
     foreach ($terms as $term) {
         if (rand(0, 100) > $percentile) {
             continue;
         }
         $instance = $term->getInstance();
         $normalizer = $this->normalizer->normalize($term);
         $routeName = $normalizer->getRouteName();
         $routeParams = $normalizer->getRouteParams();
         $router = $this->aliasManager->getRouter();
         $url = $router->assemble($routeParams, ['name' => $routeName]);
         $alias = $this->aliasManager->autoAlias('taxonomyTerm', $url, $term, $instance);
         $console->writeLine('Updated taxonomy term ' . $term->getName() . ' (' . $term->getId() . '): ' . $alias->getAlias());
     }
 }
 protected function process(TaxonomyTermInterface $term)
 {
     if (!$term->hasParent()) {
         return;
     }
     if ($term->getId() === null) {
         $this->getAliasManager()->flush($term);
     }
     $instance = $term->getInstance();
     $normalizer = $this->normalizer->normalize($term);
     $routeName = $normalizer->getRouteName();
     $routeParams = $normalizer->getRouteParams();
     $router = $this->getAliasManager()->getRouter();
     $url = $router->assemble($routeParams, ['name' => $routeName]);
     $this->getAliasManager()->autoAlias('taxonomyTerm', $url, $term, $instance);
     foreach ($term->getChildren() as $child) {
         $this->process($child);
     }
 }
 protected function normalize(Collection $collection)
 {
     $data = [];
     foreach ($collection as $entity) {
         $normalized = $this->normalizer->normalize($entity);
         $description = $normalized->getMetadata()->getDescription();
         try {
             $description = $this->renderService->render($description);
         } catch (RuntimeException $e) {
             // nothing to do
         }
         $authors = $entity->getRevisions()->map(function ($revision) {
             return $revision->getAuthor()->getId();
         });
         $description = $this->descriptionFilter->filter($description);
         $item = ['title' => $normalized->getTitle(), 'description' => $description, 'guid' => (string) $entity->getId(), 'keywords' => $normalized->getMetadata()->getKeywords(), 'categories' => $this->getCategories($entity), 'link' => $this->url()->fromRoute($normalized->getRouteName(), $normalized->getRouteParams()), 'lastModified' => $normalized->getMetadata()->getLastModified(), 'authorsCount' => count(array_unique($authors->toArray())), 'revisionsCount' => $entity->getRevisions()->count()];
         $data[] = $item;
     }
     return $data;
 }
 /**
  * {@inheritDoc}
  */
 public function toDocument($object)
 {
     if (!$object instanceof EntityInterface) {
         throw new InvalidArgumentException(sprintf('Expected TaxonomyTermInterface but got %s', is_object($object) ? get_class($object) : gettype($object)));
     }
     $normalized = $this->normalizer->normalize($object);
     $id = $object->getId();
     $instance = $object->getInstance()->getId();
     $title = $normalized->getTitle();
     $content = $normalized->getContent();
     $keywords = $normalized->getMetadata()->getKeywords();
     $type = $object->getType()->getName();
     $link = $this->router->assemble($normalized->getRouteParams(), ['name' => $normalized->getRouteName()]);
     try {
         $content = $this->renderService->render($content);
     } catch (RuntimeException $e) {
         // Could not render -> nothing to do.
     }
     $content = $this->stripTags->filter($content);
     return new Document($id, $title, $content, $type, $link, $keywords, $instance);
 }