public function actionDelete($resource_type, $id)
{
if (!in_array($resource_type, static::$resources)) {
$this->sendErrorResponse(404, "Unrecognised Resource type {$resource_type}");
}
if (!$id) {
$this->sendResponse(404, 'External Resource ID required');
}
$resource_model = $this->getResourceModel($resource_type);
if (!method_exists($resource_model, 'delete')) {
$this->sendResponse(405);
}
try {
if (!($resource = $resource_model::fromResourceId(static::$version, $id))) {
$this->sendResponse(404, 'Could not find resource for external Id');
}
if ($resource->delete()) {
$this->sendResponse(204);
}
} catch (\Exception $e) {
if (YII_DEBUG) {
$errors[] = $e->getMessage();
} else {
$errors = array('Could not delete resource');
}
$this->sendErrorResponse(500, $errors);
}
}