Ejemplo n.º 1
0
 /**
  * List all unreferenced content types (from external sources)
  *
  * @param Request $request
  *        	@Route("/content-type/unreferenced", name="contenttype.unreferenced"))
  */
 public function unreferencedAction(Request $request)
 {
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     /** @var EnvironmentRepository $environmetRepository */
     $environmetRepository = $em->getRepository('AppBundle:Environment');
     $contentTypeRepository = $em->getRepository('AppBundle:ContentType');
     if ($request->isMethod('POST')) {
         if (null != $request->get('envId') && null != $request->get('name')) {
             $defaultEnvironment = $environmetRepository->find($request->get('envId'));
             if ($defaultEnvironment) {
                 $contentType = new ContentType();
                 $contentType->setName($request->get('name'));
                 $contentType->setPluralName($contentType->getName());
                 $contentType->setEnvironment($defaultEnvironment);
                 $contentType->setActive(true);
                 $contentType->setDirty(false);
                 $contentType->setOrderKey($contentTypeRepository->countContentType());
                 $em->persist($contentType);
                 $em->flush();
                 $this->addFlash('notice', 'The content type ' . $contentType->getName() . ' is now referenced');
                 return $this->redirectToRoute('contenttype.edit', ['id' => $contentType->getId()]);
             }
         }
         $this->addFlash('warning', 'Unreferenced content type not found.');
         return $this->redirectToRoute('contenttype.unreferenced');
     }
     /** @var ContentTypeRepository $contenttypeRepository */
     $contenttypeRepository = $em->getRepository('AppBundle:ContentType');
     $environments = $environmetRepository->findBy(['managed' => false]);
     /** @var  Client $client */
     $client = $this->get('app.elasticsearch');
     $referencedContentTypes = [];
     /** @var Environment $environment */
     foreach ($environments as $environment) {
         $alias = $environment->getAlias();
         $mapping = $client->indices()->getMapping(['index' => $alias]);
         foreach ($mapping as $indexName => $index) {
             foreach ($index['mappings'] as $name => $type) {
                 $already = $contenttypeRepository->findBy(['name' => $name]);
                 if (!$already || $already[0]->getDeleted()) {
                     $referencedContentTypes[] = ['name' => $name, 'alias' => $alias, 'envId' => $environment->getId()];
                 }
             }
         }
     }
     return $this->render('contenttype/unreferenced.html.twig', ['referencedContentTypes' => $referencedContentTypes]);
 }
Ejemplo n.º 2
0
 private function createContentType($name, $pluralName, $icon, $description, $indexTwig, $extra, $color, $orderKey, $rootContentType, $active, $environment, $labelField, $locationField)
 {
     $contentType = new ContentType();
     $contentType->setName($name);
     $contentType->setPluralName($pluralName);
     $contentType->setIcon($icon);
     $contentType->setDescription($description);
     $contentType->setIndexTwig($indexTwig);
     $contentType->setExtra($extra);
     $contentType->setColor($color);
     $contentType->setOrderKey($orderKey);
     $contentType->setRootContentType($rootContentType);
     $contentType->setActive($active);
     $contentType->setEnvironment($this->getReference($environment));
     $contentType->setLabelField($labelField);
     $contentType->setLocationField($locationField);
     return $contentType;
 }