Ejemplo n.º 1
0
 /**
  * Delete an existing DNS zone, or delete a record from the zone.
  *
  * If an identifier is specified, the entire zone will be deleted.
  *
  * ### Response: ###
  *
  * ~~~
  * true
  * ~~~
  *
  * If a body is specified, but no identifier, the specified entries will be deleted from the zone.
  *
  * ### Request: ###
  *
  * ~~~
  * {
  *     "name": <string>,
  *     "records": [ {
  *             "name": <string>,
  *             "type": <string>,
  *             "content": <string>,
  *             "priority": <int>
  *     },1..n ]
  * }
  * ~~~
  *
  * ### Response: ###
  *
  * ~~~
  * true
  * ~~~
  *
  * ### Errors (request without identifier): ###
  *
  * * 508 - Invalid request, missing required parameters or input validation failed.
  * * 500 - Failed to connect to database or query execution error.
  * * 409 - Cannot delete records from a SLAVE zone.
  * * 404 - Could not find zone.
  *
  * ### Errors (request with identifier): ###
  *
  * * 508 - Invalid request, missing required parameters or input validation failed.
  * * 500 - Failed to connect to database or query execution error.
  * * 404 - Could not find zone.
  *
  * @access public
  * @param mixed $request Request parameters
  * @param string $identifier Zone identifier
  * @return Response True if zone was deleted, error message otherwise.
  */
 public function delete($request, $identifier = null)
 {
     $response = new FormattedResponse($request);
     $data = $request->parseData();
     if (empty($identifier) && (empty($data) || !isset($data->name) || !isset($data->records) || empty($data->records))) {
         $response->code = Response::BADREQUEST;
         $response->error = "Identifier and/or records were missing or invalid. Ensure that the body is in valid format and all required parameters are present.";
         $response->error_detail = "MISSING_REQUIRED_PARAMETERS";
         return $response;
     }
     $validator = new ZoneValidator($data);
     $validator->mode_override = "delete";
     if (!empty($identifier)) {
         $validator->identifier = $identifier;
     }
     if (!$validator->validates()) {
         $response->code = Response::BADREQUEST;
         $response->error = $validator->getFormattedErrors();
         $response->error_detail = $validator->getErrorDetails();
         return $response;
     }
     if (!empty($identifier)) {
         return ZoneFunctions::delete_zone($response, $identifier);
     } else {
         return ZoneFunctions::delete_records($response, $data->name, $data);
     }
 }