public function onRawEventAdd(NewRawEventEvent $rawEventEvent)
 {
     $rawEvent = $rawEventEvent->getRawEvent();
     $tool = $this->doctrineManager->getRepository('KoalamonIncidentDashboardBundle:Tool')->findOneByIdentifier($rawEvent->getType(), $rawEventEvent->getProject());
     if (!$tool) {
         $tool = new Tool();
         $tool->setName($rawEvent->getType());
         $tool->setIdentifier($rawEvent->getType());
         $tool->setProject($rawEventEvent->getProject());
         $this->doctrineManager->persist($tool);
         $this->doctrineManager->flush();
         $this->eventDispatcher->dispatch('koalamon.tool.create', new NewToolEvent($tool, true));
     }
     $rawEventEvent->getEvent()->setType($rawEvent->getType());
     $rawEventEvent->getEvent()->getEventIdentifier()->setTool($tool);
 }
 public function findRecent(Tool $tool)
 {
     $this->getEntityManager()->createQueryBuilder();
     $qb = $this->createQueryBuilder('e');
     $qb->join('e.eventIdentifier', 'ei');
     $qb->where($qb->expr()->andX('e.type = :toolIdentifier', 'ei.project = :project'));
     $qb->setParameter('toolIdentifier', $tool->getIdentifier());
     $qb->setParameter('project', $tool->getProject());
     $qb->orderBy('e.created', 'DESC');
     $results = $qb->getQuery()->getResult();
     if (count($results) == 0) {
         return null;
     } else {
         return $results[0];
     }
 }
 private function addSystemTools(Project $project)
 {
     $healthStatus = new Tool();
     $healthStatus->setProject($project);
     $healthStatus->setActive(true);
     $healthStatus->setIdentifier('system_health_status');
     $healthStatus->setDescription('Every system hat its own health status that will be calculated using all failed checks.');
     $healthStatus->setName('System Health Status');
     $em = $this->getDoctrine()->getManager();
     $em->persist($healthStatus);
     $em->flush();
 }
 public function load(ObjectManager $manager)
 {
     foreach ($this->fixtures as $file) {
         /** @var SplFileInfo $file */
         $fixture = json_decode($file->getContents());
         $tool = new Tool();
         $tool->setIdentifier($fixture->identifier);
         $tool->setName($fixture->name);
         $tool->setImage($fixture->image);
         $tool->setNotify($fixture->notify);
         $tool->setDescription($fixture->description);
         /** @var Project $project */
         $project = $this->getReference('project-' . $fixture->project);
         $tool->setProject($project);
         $manager->persist($tool);
     }
     $manager->flush();
 }
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function storeAction(Request $request)
 {
     $this->assertUserRights(UserRole::ROLE_ADMIN);
     $tool = $request->get('tool');
     if (array_key_exists("id", $tool)) {
         $toolObject = $this->getDoctrine()->getRepository('KoalamonIncidentDashboardBundle:Tool')->find($tool["id"]);
     } else {
         $toolObject = new Tool();
         $toolObject->setProject($this->getProject());
     }
     if (array_key_exists('identifier', $tool)) {
         $existingTool = $this->getDoctrine()->getRepository('KoalamonIncidentDashboardBundle:Tool')->findOneBy(['identifier' => $tool["identifier"], 'project' => $this->getProject()]);
         if ($existingTool) {
             if (!array_key_exists('id', $tool) || $existingTool->getId() != $tool['id']) {
                 $this->addFlash('notice', 'The parameter "identifier" already exists.');
                 return $this->redirect($this->generateUrl('koalamon_default_tool_admin', ['project' => $this->getProject()->getIdentifier()]));
             }
         }
     }
     if ($tool["identifier"] != "") {
         $toolObject->setIdentifier($tool["identifier"]);
     } else {
         $this->addFlash('notice', 'The parameter "identifier" is required');
         return $this->redirect($this->generateUrl('koalamon_default_tool_admin', ['project' => $this->getProject()->getIdentifier()]));
     }
     if ($tool["name"] != "") {
         $toolObject->setName($tool["name"]);
     } else {
         $this->addFlash('notice', 'The parameter "name" is required');
         return $this->redirect($this->generateUrl('koalamon_default_tool_admin', ['project' => $this->getProject()->getIdentifier()]));
     }
     $toolObject->setDescription($tool["description"]);
     if (array_key_exists('active', $tool)) {
         $toolObject->setActive(true);
     } else {
         $toolObject->setActive(false);
     }
     if (array_key_exists('notify', $tool)) {
         $toolObject->setNotify(true);
     } else {
         $toolObject->setNotify(false);
     }
     if (array_key_exists('systemSpecific', $tool)) {
         $toolObject->setSystemSpecific(true);
     } else {
         $toolObject->setSystemSpecific(false);
     }
     $em = $this->getDoctrine()->getManager();
     $em->persist($toolObject);
     $em->flush();
     $this->addFlash('success', 'Tool "' . $toolObject->getName() . '" successfully saved.');
     return $this->redirect($this->generateUrl('koalamon_default_tool_admin', ['project' => $this->getProject()->getIdentifier()]));
 }