示例#1
0
 public function load(ObjectManager $manager)
 {
     $data = array(array('ip_mask' => '192.168.0.0/16', 'academic_unit_name' => 'Test', 'admin_name' => 'Support Test', 'admin_email' => '*****@*****.**'));
     $NetworkAdminRepository = $manager->getRepository('CertUnlpNgenBundle:NetworkAdmin');
     $AcademicUnitRepository = $manager->getRepository('CertUnlpNgenBundle:AcademicUnit');
     foreach ($data as $network_data) {
         $Network = new Network();
         $Network->setIp($network_data['ip_mask']);
         $na = $NetworkAdminRepository->findOneByName($network_data['admin_name']);
         $au = $AcademicUnitRepository->findOneByName($network_data['academic_unit_name']);
         if ($na) {
             $Network->setNetworkAdmin($na);
         } else {
             $Network->setNetworkAdmin(new NetworkAdmin($network_data['admin_name'], $network_data['admin_email']));
         }
         if ($au) {
             $Network->setAcademicUnit($au);
         } else {
             $Network->setAcademicUnit(new AcademicUnit($network_data['academic_unit_name']));
         }
         $manager->persist($Network);
         $manager->flush();
         $this->addReference('network-' . $network_data['ip_mask'], $Network);
     }
 }
示例#2
0
 /**
  * Update existing network from the submitted data or create a new network at a specific location.
  *
  * @ApiDoc(
  *   resource = true,
  *   input = "CertUnlp\NgenBundle\Form\NetworkType",
  *   statusCodes = {
  *     204 = "Returned when successful",
  *     400 = "Returned when the form has errors"
  *   }
  * )
  *
  * @FOS\View(
  *  template = "CertUnlpNgenBundle:Network:editNetwork.html.twig",
  *  templateVar = "form"
  * )
  *
  * @param Request $request the request object
  * @param int     $id      the network id
  *
  * @return FormTypeInterface|View
  *
  * @throws NotFoundHttpException when network not exist
  * @FOS\Patch("/networks/{ip}/{ipMask}")
  *
  * @ParamConverter("network", class="CertUnlpNgenBundle:Network", options={"repository_method" = "findOneBy"})
  * @FOS\QueryParam(name="ip",strict=true ,requirements="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", description="An IP.")
  * @FOS\QueryParam(name="ipMask",strict=true ,requirements="[0-32]", description="A decimal ip mask.")
  */
 public function patchNetworkAction(Request $request, Network $network)
 {
     try {
         $parameters = $request->request->all();
         unset($parameters['_method'], $parameters['force_edit'], $parameters['reactivate']);
         $DBnetwork = $this->container->get('cert_unlp.ngen.network.handler')->get(['ip' => $request->request->get('ip'), 'ipMask' => $request->request->get('ipMask')]);
         if ($request->get('reactivate')) {
             $network->setIsActive(TRUE);
         }
         if (!$network->equals($DBnetwork)) {
             if ($request->get('force_edit')) {
                 $statusCode = Codes::HTTP_NO_CONTENT;
                 $network = $this->container->get('cert_unlp.ngen.network.handler')->patch($network, $parameters);
             } else {
                 $statusCode = Codes::HTTP_CREATED;
                 $this->container->get('cert_unlp.ngen.network.handler')->delete($network);
                 $network = $this->container->get('cert_unlp.ngen.network.handler')->post($parameters);
             }
         } else {
             $statusCode = Codes::HTTP_NO_CONTENT;
             $network = $this->container->get('cert_unlp.ngen.network.handler')->patch($network, $parameters);
         }
         $routeOptions = array('ip' => $network->getIp(), 'ipMask' => $network->getIpMask(), '_format' => $request->get('_format'));
         return $this->routeRedirectView('api_1_get_network', $routeOptions, $statusCode);
     } catch (InvalidFormException $exception) {
         return $exception->getForm();
     }
 }