require '../../services/ForeignService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { if (array_key_exists("id", $_GET)) { $countryId = $_GET["id"]; $country = countryQuery::create()->findPk($countryId); } $force = false; if (array_key_exists("force", $_GET)) { $force = $_GET["force"]; } if (isset($country)) { try { $databaseName = countryPeer::DATABASE_NAME; $constraints = array("recipes" => "origin"); if ($force == true) { ForeignService::forceForeignConstraints($databaseName, $constraints, $countryId); $country->delete(); http_response_code(204); } else { $result = ForeignService::verifyForeignConstraints($databaseName, $constraints, $countryId); if ($result) { $country->delete(); http_response_code(204); } else { echo json_encode(array("result" => "Ce pays est référencé par des recettes.")); } } } catch (PropelException $ex) { http_response_code(500); } } else {
require '../../services/ForeignService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { if (array_key_exists("id", $_GET)) { $ingredientId = $_GET["id"]; $ingredient = ingredientTypeQuery::create()->findPk($ingredientId); } $force = false; if (array_key_exists("force", $_GET)) { $force = $_GET["force"]; } if (isset($ingredient)) { try { $databaseName = unitPeer::DATABASE_NAME; $constraints = array("ingredient" => "ingredientId"); if ($force == true) { ForeignService::forceForeignConstraints($databaseName, $constraints, $ingredientId, true); $ingredient->delete(); http_response_code(204); } else { $result = ForeignService::verifyForeignConstraints($databaseName, $constraints, $ingredientId); if ($result) { $ingredient->delete(); http_response_code(204); } else { echo json_encode(array("result" => "Cet ingredient est référencée dans les ingredients de recette.")); } } } catch (PropelException $ex) { http_response_code(500); } } else {
require '../../services/ForeignService.php'; UserService::withRole(UserService::$CONTRIBUTOR, function () { if (array_key_exists("id", $_GET)) { $unitId = $_GET["id"]; $unit = unitQuery::create()->findPk($unitId); } $force = false; if (array_key_exists("force", $_GET)) { $force = $_GET["force"]; } if (isset($unit)) { try { $databaseName = unitPeer::DATABASE_NAME; $constraints = array("ingredient" => "unitId"); if ($force == true) { ForeignService::forceForeignConstraints($databaseName, $constraints, $unitId, true); $unit->delete(); http_response_code(204); } else { $result = ForeignService::verifyForeignConstraints($databaseName, $constraints, $unitId); if ($result) { $unit->delete(); http_response_code(204); } else { echo json_encode(array("result" => "Cette unité est référencée dans des ingredients de recette.")); } } } catch (PropelException $ex) { http_response_code(500); } } else {