コード例 #1
0
 private function createEnvironment($name, $color, $managed)
 {
     $environment = new Environment();
     $environment->setName($name);
     $environment->setColor($color);
     $environment->setManaged($managed);
     return $environment;
 }
コード例 #2
0
 /**
  * Attach a external index as a new referenced environment
  *
  * @param string $name
  *        	alias name
  * @param Request $request
  * 
  * @Route("/environment/attach/{name}", name="environment.attach"))
  * @Method({"POST"})
  */
 public function attachAction($name, Request $request)
 {
     /** @var  Client $client */
     $client = $this->get('app.elasticsearch');
     try {
         $indexes = $client->indices()->get(['index' => $name]);
         if (strcmp($name, array_keys($indexes)[0]) != 0) {
             /** @var EntityManager $em */
             $em = $this->getDoctrine()->getManager();
             $environmetRepository = $em->getRepository('AppBundle:Environment');
             $anotherObject = $environmetRepository->findBy(['name' => $name]);
             if (count($anotherObject) == 0) {
                 $environment = new Environment();
                 $environment->setName($name);
                 $environment->setAlias($name);
                 //TODO: setCircles
                 $environment->setManaged(false);
                 $em->persist($environment);
                 $em->flush();
                 $this->addFlash('notice', 'Alias ' . $name . ' has been attached.');
                 return $this->redirectToRoute('environment.edit', ['id' => $environment->getId()]);
             }
         }
     } catch (Missing404Exception $e) {
         $this->addFlash('error', 'Something went wrong with Elasticsearch: ' . $e->getMessage() . '!');
     }
     return $this->redirectToRoute('environment.index');
 }