public function cloneAction($farmId)
{
$farm = $this->getFarm($farmId, Acl::PERM_FARMS_CLONE);
if (!$this->getUser()->getAccount()->checkLimit(Limit::ACCOUNT_FARMS, 1)) {
throw new ApiErrorException(400, ErrorMessage::ERR_LIMIT_EXCEEDED, "Farms limit for your account exceeded");
}
$object = $this->request->getJsonBody();
if (empty($object->name)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property name");
}
$name = FarmAdapter::convertInputValue('string', $object->name, 'name');
$criteria = $this->getScopeCriteria();
$criteria[] = ['name' => $name];
if (count(Farm::find($criteria))) {
throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, "Farm with name '{$name}' already exists");
}
$clone = $farm->cloneFarm($name, $this->getUser());
return $this->result($this->adapter('farm')->toData($clone));
}