Ejemplo n.º 1
0
/**
 * Sets the supplied array of custom field values to the specified issue id.
 *
 * @param integer $p_issue_id       Issue id to apply custom field values to.
 * @param array   &$p_custom_fields The array of custom field values as described in the webservice complex types.
 * @param boolean $p_log_insert     Create history logs for new values.
 * @return mixed
 */
function mci_issue_set_custom_fields($p_issue_id, array &$p_custom_fields = null, $p_log_insert)
{
    # set custom field values on the submitted issue
    if (isset($p_custom_fields) && is_array($p_custom_fields)) {
        foreach ($p_custom_fields as $t_custom_field) {
            $t_custom_field = SoapObjectsFactory::unwrapObject($t_custom_field);
            # Verify validity of custom field specification
            $t_msg = 'Invalid Custom field specification';
            $t_valid_cf = isset($t_custom_field['field']) && isset($t_custom_field['value']);
            if ($t_valid_cf) {
                $t_field = get_object_vars($t_custom_field['field']);
                if ((!isset($t_field['id']) || $t_field['id'] == 0) && !isset($t_field['name'])) {
                    $t_valid_cf = false;
                    $t_msg .= ", either 'name' or 'id' != 0 or must be given.";
                }
            }
            if (!$t_valid_cf) {
                return SoapObjectsFactory::newSoapFault('Client', $t_msg);
            }
            # get custom field id from object ref
            $t_custom_field_id = mci_get_custom_field_id_from_objectref($t_custom_field['field']);
            if ($t_custom_field_id == 0) {
                return SoapObjectsFactory::newSoapFault('Client', "Custom field '" . $t_field['name'] . "' not found.");
            }
            # skip if current user doesn't have login access.
            if (!custom_field_has_write_access($t_custom_field_id, $p_issue_id)) {
                continue;
            }
            $t_value = $t_custom_field['value'];
            if (!custom_field_validate($t_custom_field_id, $t_value)) {
                return SoapObjectsFactory::newSoapFault('Client', 'Invalid custom field value for field id ' . $t_custom_field_id . ' .');
            }
            if (!custom_field_set_value($t_custom_field_id, $p_issue_id, $t_value, $p_log_insert)) {
                return SoapObjectsFactory::newSoapFault('Server', 'Unable to set custom field value for field id ' . $t_custom_field_id . ' to issue ' . $p_issue_id . ' .');
            }
        }
    }
}
Ejemplo n.º 2
0
/**
 * Sets the supplied array of custom field values to the specified issue id.
 *
 * @param $p_issue_id   Issue id to apply custom field values to.
 * @param $p_custom_fields  The array of custom field values as described in the webservice complex types.
 * @param boolean $p_log_insert create history logs for new values
 */
function mci_issue_set_custom_fields( $p_issue_id, &$p_custom_fields, $p_log_insert ) {
	# set custom field values on the submitted issue
	if( isset( $p_custom_fields ) && is_array( $p_custom_fields ) ) {
		foreach( $p_custom_fields as $t_custom_field ) {
			# get custom field id from object ref
			$t_custom_field_id = mci_get_custom_field_id_from_objectref( $t_custom_field['field'] );

			if( $t_custom_field_id == 0 ) {
				return new soap_fault( 'Client', '', 'Custom field ' . $t_custom_field['field']['name'] . ' not found.' );
			}

			# skip if current user doesn't have login access.
			if( !custom_field_has_write_access( $t_custom_field_id, $p_issue_id ) ) {
				continue;
			}

			$t_value = $t_custom_field['value'];

			if( !custom_field_validate( $t_custom_field_id, $t_value ) ) {
				return new soap_fault( 'Client', '', 'Invalid custom field value for field id ' . $t_custom_field_id . ' .');
			}

			if( !custom_field_set_value( $t_custom_field_id, $p_issue_id, $t_value, $p_log_insert  ) ) {
				return new soap_fault( 'Server', '', 'Unable to set custom field value for field id ' . $t_custom_field_id . ' to issue ' . $p_issue_id. ' .' );
			}
		}
	}
}