X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FGeneric%2FSetvalue.php;h=ff3e6011873f3eb15d67bf990da33fd934294b30;hb=6238501eb59e8f3f540c6feef0315a4beacc95f4;hp=471e700acae2c76136cd78d76bac4d732c11f203;hpb=ec9bb041d5407d659b30d3ecd00b5db60d71ad52;p=civicrm-core.git diff --git a/api/v3/Generic/Setvalue.php b/api/v3/Generic/Setvalue.php index 471e700aca..ff3e601187 100644 --- a/api/v3/Generic/Setvalue.php +++ b/api/v3/Generic/Setvalue.php @@ -26,19 +26,21 @@ function civicrm_api3_generic_setValue($apiRequest) { } $def = $fields[$field]; - if (array_key_exists('required', $def) && empty($value)) { + // Disallow empty values except for the number zero. + // TODO: create a utility for this since it's needed in many places + // if (array_key_exists('required', $def) && CRM_Utils_System::isNull($value)) { + if (array_key_exists('required', $def) && empty($value) && $value !== '0' && $value !== 0) { return civicrm_api3_create_error(ts("This can't be empty, please provide a value"), array("error_code" => "required", "field" => $field)); } switch ($def['type']) { - case 1: - //int + case CRM_Utils_Type::T_INT: if (!is_numeric($value)) { return civicrm_api3_create_error("Param '$field' must be a number", array('error_code' => 'NaN')); } - case 2: - //string + case CRM_Utils_Type::T_STRING: + case CRM_Utils_Type::T_TEXT: if (!CRM_Utils_Rule::xssString($value)) { return civicrm_api3_create_error(ts('Illegal characters in input (potential scripting attack)'), array('error_code' => 'XSS')); } @@ -47,15 +49,13 @@ function civicrm_api3_generic_setValue($apiRequest) { } break; - case 12: - //date + case CRM_Utils_Type::T_DATE: $value = CRM_Utils_Type::escape($value,"Date",false); if (!$value) return civicrm_api3_create_error("Param '$field' is not a date. format YYYYMMDD or YYYYMMDDHHMMSS"); break; - case 16: - //boolean + case CRM_Utils_Type::T_BOOLEAN: $value = (boolean) $value; break; @@ -63,13 +63,15 @@ function civicrm_api3_generic_setValue($apiRequest) { return civicrm_api3_create_error("Param '$field' is of a type not managed yet (".$def['type']."). Join the API team and help us implement it", array('error_code' => 'NOT_IMPLEMENTED')); } - if (CRM_Core_DAO::setFieldValue(_civicrm_api3_get_DAO($entity), $id, $field, $value)) { - $entity = array('id' => $id, $field => $value); - CRM_Utils_Hook::post('edit', $entity, $id, $entity); - return civicrm_api3_create_success($entity); + $dao_name = _civicrm_api3_get_DAO($entity); + if (CRM_Core_DAO::setFieldValue($dao_name, $id, $field, $value)) { + $params = array('id' => $id, $field => $value); + $entityDAO = new $dao_name(); + $entityDAO->copyValues($params); + CRM_Utils_Hook::post('edit', $entity, $entityDAO->id, $entityDAO); + return civicrm_api3_create_success($params); } else { return civicrm_api3_create_error("error assigning $field=$value for $entity (id=$id)"); } } -