public function testAppActionRendersView() { $templating = $this->getMockBuilder(EngineInterface::class)->getMock(); $templating->expects(self::once())->method('render'); $container = $this->getMockBuilder(Container::class)->getMock(); $container->expects(self::atLeastOnce())->method('get')->will(self::returnCallback(function ($name) use($templating) { if ($name == 'templating') { return $templating; } })); $controller = new AppController(); $controller->setContainer($container); $response = $controller->appAction(); self::assertInstanceOf(Response::class, $response); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->waitForGreen($output); /** @var EntityManager $em */ $em = $this->doctrine->getManager(); /** @var Client $client */ $client = $this->client; $name = $input->getArgument('name'); /** @var JobRepository $envRepo */ $envRepo = $em->getRepository('AppBundle:Environment'); /** @var Environment $environment */ $environment = $envRepo->findBy(['name' => $name, 'managed' => true]); if ($environment && count($environment) == 1) { $environment = $environment[0]; $indexName = $environment->getAlias() . AppController::getFormatedTimestamp(); /** @var \AppBundle\Repository\ContentTypeRepository $contentTypeRepository */ $contentTypeRepository = $em->getRepository('AppBundle:ContentType'); $contentTypes = $contentTypeRepository->findAll(); /** @var ContentType $contentType */ $client->indices()->create(['index' => $indexName, 'body' => ContentType::getIndexAnalysisConfiguration()]); $output->writeln('A new index ' . $indexName . ' has been created'); $this->waitForGreen($output); // create a new progress bar $progress = new ProgressBar($output, count($contentTypes)); // start and displays the progress bar $progress->start(); $progressMessage = " creating content type's mappings in " . $indexName; /** @var ContentType $contentType */ foreach ($contentTypes as $contentType) { if ($contentType->getEnvironment()->getManaged() && !$contentType->getDeleted()) { $this->contentTypeService->updateMapping($contentType, $indexName); } $progress->advance(); $output->write($progressMessage); } $progress->finish(); $output->writeln($progressMessage); $this->flushFlash($output); $command = $this->getReindexCommand(); $arguments = array('name' => $name, 'index' => $indexName); $reindexInput = new ArrayInput($arguments); $returnCode = $command->run($reindexInput, $output); if ($returnCode) { $output->writeln('Reindexed with return code: ' . $returnCode); } $this->waitForGreen($output); $this->switchAlias($environment->getAlias(), $indexName, true, $output); $output->writeln('The alias <info>' . $environment->getName() . '</info> is now pointing to ' . $indexName); } else { $output->writeln("WARNING: Environment named " . $name . " not found"); } $this->flushFlash($output); }
/** * Add a new environement * * @param Request $request * @Route("/environment/add", name="environment.add")) */ public function addAction(Request $request) { $environment = new Environment(); $form = $this->createFormBuilder($environment)->add('name', IconTextType::class, ['icon' => 'fa fa-database', 'required' => false])->add('color', ColorPickerType::class, ['required' => false])->add('save', SubmitEmsType::class, ['label' => 'Create', 'icon' => 'fa fa-plus', 'attr' => ['class' => 'btn btn-primary pull-right']])->getForm(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { /** @var Environment $environment */ $environment = $form->getData(); /** @var EntityManager $em */ $em = $this->getDoctrine()->getManager(); $environmetRepository = $em->getRepository('AppBundle:Environment'); $anotherObject = $environmetRepository->findBy(['name' => $environment->getName()]); if (count($anotherObject) != 0) { //TODO: test name format $form->get('name')->addError(new FormError('Another environment named ' . $environment->getName() . ' already exists')); } else { $environment->setAlias($this->getParameter('instance_id') . $environment->getName()); $environment->setManaged(true); $em = $this->getDoctrine()->getManager(); $em->persist($environment); $em->flush(); $indexName = $environment->getAlias() . AppController::getFormatedTimestamp(); $this->getElasticsearch()->indices()->create(['index' => $indexName, 'body' => ContentType::getIndexAnalysisConfiguration()]); foreach ($this->getContentTypeService()->getAll() as $contentType) { $this->getContentTypeService()->updateMapping($contentType, $indexName); } $this->getElasticsearch()->indices()->putAlias(['index' => $indexName, 'name' => $environment->getAlias()]); $this->addFlash('notice', 'A new environement ' . $environment->getName() . ' has been created'); return $this->redirectToRoute('environment.index'); } } return $this->render('environment/add.html.twig', ['form' => $form->createView()]); }