Protects against too long strings when logging web services events

SVN:1.2[1961]
This commit is contained in:
Denis Flaven
2012-04-19 11:17:20 +00:00
parent 6b526ba455
commit 7a8ee0353a

View File

@@ -283,12 +283,26 @@ abstract class WebServicesBase
$oLog->Set('userinfo', UserRights::GetUser());
$oLog->Set('verb', $sVerb);
$oLog->Set('result', $oRes->IsOk());
$oLog->Set('log_info', $oRes->GetInfoAsText());
$oLog->Set('log_warning', $oRes->GetWarningsAsText());
$oLog->Set('log_error', $oRes->GetErrorsAsText());
$oLog->Set('data', $oRes->GetReturnedDataAsText());
$this->TrimAndSetValue($oLog, 'log_info', $oRes->GetInfoAsText());
$this->TrimAndSetValue($oLog, 'log_warning', $oRes->GetWarningsAsText());
$this->TrimAndSetValue($oLog, 'log_error', $oRes->GetErrorsAsText());
$this->TrimAndSetValue($oLog, 'data', $oRes->GetReturnedDataAsText());
$oLog->DBInsertNoReload();
}
protected function TrimAndSetValue($oLog, $sAttCode, $sValue)
{
$oAttDef = MetaModel::GetAttributeDef(get_class($oLog), $sAttCode);
if (is_object($oAttDef))
{
$iMaxSize = $oAttDef->GetMaxSize();
if ($iMaxSize)
{
$sValue = substr($sValue, 0, $iMaxSize);
}
$oLog->Set($sAttCode, $sValue);
}
}
/**
* Helper to set a scalar attribute