From 88665da96e9f7477d97699410ae208dae927e949 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Tue, 24 Mar 2015 17:08:03 +0000 Subject: [PATCH] Enhancement: allow the API to create entries with a specified user_login. SVN:2.1.1[3515] --- core/ormcaselog.class.inc.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/core/ormcaselog.class.inc.php b/core/ormcaselog.class.inc.php index c96ffbda4f..14aa24b148 100644 --- a/core/ormcaselog.class.inc.php +++ b/core/ormcaselog.class.inc.php @@ -384,7 +384,7 @@ class ormCaseLog { } - public function AddLogEntryFromJSON($oJson) + public function AddLogEntryFromJSON($oJson, $bCheckUserId = true) { $sText = isset($oJson->message) ? $oJson->message : ''; @@ -394,16 +394,24 @@ class ormCaseLog { { throw new Exception("Only administrators can set the user id", RestResult::UNAUTHORIZED); } - try + if ($bCheckUserId) { - $oUser = RestUtils::FindObjectFromKey('User', $oJson->user_id); + try + { + $oUser = RestUtils::FindObjectFromKey('User', $oJson->user_id); + } + catch(Exception $e) + { + throw new Exception('user_id: '.$e->getMessage(), $e->getCode()); + } + $iUserId = $oUser->GetKey(); + $sOnBehalfOf = $oUser->GetFriendlyName(); } - catch(Exception $e) + else { - throw new Exception('user_id: '.$e->getMessage(), $e->getCode()); + $iUserId = $oJson->user_id; + $sOnBehalfOf = $oJson->user_login; } - $iUserId = $oUser->GetKey(); - $sOnBehalfOf = $oUser->GetFriendlyName(); } else {