コード例 #1
0
 public function cloneSubsystemAction(System $system)
 {
     $clone = new System();
     $clone->setSystemType($system->getSystemType());
     $clone->setDescription($system->getDescription());
     $clone->setName('Copy of ' . $system->getName());
     $clone->setProject($system->getProject());
     $clone->setParent($system->getParent());
     $clone->setDomain($system->getDomain());
     $clone->setPath($system->getPath());
     $clone->setSubDomain($system->getSubDomain());
     $clone->setSchema($system->getSchema());
     $em = $this->getDoctrine()->getManager();
     $em->persist($clone);
     $em->flush();
     $clone->setIdentifier($clone->getId());
     $em->persist($clone);
     $em->flush();
     // integrations
     $integrationSystems = $this->getDoctrine()->getRepository('KoalamonIntegrationBundle:IntegrationSystem')->findBy(['system' => $system]);
     foreach ($integrationSystems as $integrationSystem) {
         $newIntegrationSystem = new IntegrationSystem();
         $newIntegrationSystem->setProject($integrationSystem->getProject());
         $newIntegrationSystem->setInherit($integrationSystem->getInherit());
         $newIntegrationSystem->setOptions($integrationSystem->getOptions());
         $newIntegrationSystem->setSystem($clone);
         $newIntegrationSystem->setIntegration($integrationSystem->getIntegration());
         $em->persist($newIntegrationSystem);
         $dispatcherEvent = new IntegrationSystemStoreEvent($newIntegrationSystem);
         $this->get('event_dispatcher')->dispatch('leankoala.integration.store', $dispatcherEvent);
     }
     $em->flush();
     // missing request
     $collectionSystems = $this->getDoctrine()->getRepository('LeanKoalaIntegrationMissingRequestBundle:Collection')->findBySystem($system);
     foreach ($collectionSystems as $collectionSystem) {
         $collectionSystem->addSystem($clone);
         $em->persist($collectionSystem);
     }
     $em->flush();
     $dispatcherEvent = new MissingRequestStoreEvent($system, $collectionSystems);
     $this->get('event_dispatcher')->dispatch('leankoala.integration.missingrequest.store', $dispatcherEvent);
     $this->addFlash('success', 'Component "' . $system->getName() . '" successfully cloned and ready to edit.');
     return $this->redirectToRoute('koalamon_default_admin_system_subsystems_edit', ['currentSystem' => $clone->getId()]);
 }