/** * Updates the SOA record of the domain. see the documentation for details. * * @ApiDoc( * description="Updates soa record for the given domain", * input="SysEleven\PowerDnsBundle\Form\SoaType", * requirements={ * {"name" = "domain", "dataType" = "integer", "requirement" = "\d+", "description" = "Id of the domain"}, * {"name" = "_format", "dataType" = "string", "pattern" = "(json|xml)", "description" = "Output Format"} * }, * * output={ * "class"="SysEleven\PowerDnsBundle\Entity\Records", * "groups"="details" * } * ) * * @param Request $request * @param int $domain * * @return \FOS\RestBundle\View\View|\Symfony\Component\HttpFoundation\Response * @Rest\Put("soa.{_format}", name="syseleven_powerdns_api_domains_soa_update") */ public function soaUpdateAction(Request $request, $domain) { try { /** * @type DomainWorkflow $workflow; */ $workflow = $this->get('syseleven.pdns.workflow.domains'); /** * @type Domains $domainObj */ $domainObj = $workflow->get($domain); if (!($recordObj = $domainObj->getSoa())) { $data = array('status' => 'error', 'errors' => array('soa' => 'Not found')); return $this->returnView($data, 200, array()); } /** * @type Soa $soa */ $soa = $recordObj->getContent(); $oldSerial = $soa->getSerial(); $form = $this->createForm(new SoaType(), $soa, array('method' => 'PUT')); $form->submit($request, false); if ($oldSerial == $soa->getSerial()) { $soa->setSerial(strtotime('now')); } /** * @type RecordWorkflow $recordWorkflow; */ $recordWorkflow = $this->get('syseleven.pdns.workflow.records'); $recordObj = $recordWorkflow->update($recordObj); $recordWorkflow->createHistory($recordObj); $data = array('status' => 'success', 'data' => $recordObj); } catch (NotFoundException $nf) { $data = array('status' => 'error', 'errors' => array('domain' => 'Not found')); } catch (ValidationException $ve) { $data = array('status' => 'error', 'errors' => Tools::prepareSymfonyErrorArray($ve->getErrors())); } return $this->returnView($data, 200, array(), array('details')); }
/** * Updates the domain specified by domain, despite the fact that PUT is * used it performs a Patch Operation. See the documentation for details * on the parameters. * * @ApiDoc( * description="Updates the given domain object", * input="SysEleven\PowerDnsBundle\Form\DomainsType", * requirements={ * {"name" = "id", "dataType" = "integer", "requirement" = "\d+", "description" = "Id of the domain"}, * {"name" = "_format", "dataType" = "string", "pattern" = "(json|xml)", "description" = "Output Format"} * }, * * output={ * "class"="SysEleven\PowerDnsBundle\Entity\Domains", * "groups"="details" * } * ) * * @param Request $request * @param $id * * @return \Symfony\Component\HttpFoundation\Response * * @Rest\Put("/{id}.{_format}", name="syseleven_powerdns_api_domains_update") */ public function updateAction(Request $request, $id) { try { /** * @type DomainWorkflow $workflow */ $workflow = $this->get('syseleven.pdns.workflow.domains'); $domainObj = $workflow->get($id); $form = $this->createForm(new DomainsType(), $domainObj, array('method' => 'PUT', 'error_bubbling' => true)); $form->submit($request, false); $domainObj = $workflow->update($domainObj); $data = array('status' => 'success', 'data' => $domainObj); } catch (NotFoundException $nf) { $data = array('status' => 'error', 'errors' => array('id' => 'Not found')); } catch (ValidationException $ve) { $data = array('status' => 'error', 'errors' => Tools::prepareSymfonyErrorArray($ve->getErrors())); } return $this->returnView($data, 200, array(), array('details')); }
/** * Updates the given record with the submitted data. * * @ApiDoc( * description="Updates the given record", * input="SysEleven\PowerDnsBundle\Form\RecordsType", * requirements={ * {"name" = "domain", "dataType" = "integer", "requirement" = "\d+", "description" = "Id of the domain"}, * {"name" = "record", "dataType" = "integer", "requirement" = "\d+", "description" = "Id of the record to update"}, * {"name" = "_format", "dataType" = "string", "pattern" = "(json|xml)", "description" = "Output Format"} * }, * * output={ * "class"="SysEleven\PowerDnsBundle\Entity\Records", * "groups"="details" * } * ) * * @param Request $request * @param int $domain * @param int $record * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response * @Rest\Patch("/records/{record}.{_format}", name="syseleven_powerdns_api_domains_records_patch") * @throws \SysEleven\PowerDnsBundle\Lib\Exceptions\NotFoundException */ public function patchAction(Request $request, $domain, $record) { try { /** * @type DomainWorkflow $workflow */ $workflow = $this->get('syseleven.pdns.workflow.domains'); $domainObj = $workflow->get($domain); /** * @type RecordWorkflow $recordWorkflow */ $recordWorkflow = $this->get('syseleven.pdns.workflow.records'); /** * @type Records $recordObj */ $recordObj = $recordWorkflow->get($record); if ($recordObj->getDomain() != $domainObj) { throw new NotFoundException('Cannot find record with id: ' . $record . ' in domain: ' . $domain); } $form = $this->createForm(new RecordsType(), $recordObj, array('method' => 'PATCH')); $form->remove('domain'); $form->submit($request, false); /** * @type RecordWorkflow $recordWorkflow */ $recordWorkflow = $this->get('syseleven.pdns.workflow.records'); $force = $request->get('force', false); /** * @type Records $recordObj */ $recordObj = $recordWorkflow->update($recordObj, array(), $force); $data = array('status' => 'success', 'data' => $recordObj); return $this->returnView($data, 200, array(), array('details')); } catch (NotFoundException $e) { $data = array('status' => 'error', 'errors' => array('id' => 'Not found')); return $this->returnView($data, 200); } catch (ValidationException $ve) { $data = array('status' => 'error', 'errors' => Tools::prepareSymfonyErrorArray($ve->getErrors())); return $this->returnView($data, 200); } }