webservices.class.inc.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Implementation of iTop SOAP services
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. require_once(APPROOT.'/webservices/itopsoaptypes.class.inc.php');
  25. /**
  26. * Generic response of iTop SOAP services
  27. *
  28. * @package iTopORM
  29. */
  30. class WebServiceResult
  31. {
  32. /**
  33. * Overall status
  34. *
  35. * @var m_bStatus
  36. */
  37. public $m_bStatus;
  38. /**
  39. * Error log
  40. *
  41. * @var m_aErrors
  42. */
  43. public $m_aErrors;
  44. /**
  45. * Warning log
  46. *
  47. * @var m_aWarnings
  48. */
  49. public $m_aWarnings;
  50. /**
  51. * Information log
  52. *
  53. * @var m_aInfos
  54. */
  55. public $m_aInfos;
  56. /**
  57. * Constructor
  58. *
  59. * @param status $bStatus
  60. */
  61. public function __construct()
  62. {
  63. $this->m_bStatus = true;
  64. $this->m_aResult = array();
  65. $this->m_aErrors = array();
  66. $this->m_aWarnings = array();
  67. $this->m_aInfos = array();
  68. }
  69. public function ToSoapStructure()
  70. {
  71. $aResults = array();
  72. foreach($this->m_aResult as $sLabel => $aData)
  73. {
  74. $aValues = array();
  75. foreach($aData as $sKey => $value)
  76. {
  77. $aValues[] = new SoapResultData($sKey, $value);
  78. }
  79. $aResults[] = new SoapResultMessage($sLabel, $aValues);
  80. }
  81. $aInfos = array();
  82. foreach($this->m_aInfos as $sMessage)
  83. {
  84. $aInfos[] = new SoapLogMessage($sMessage);
  85. }
  86. $aWarnings = array();
  87. foreach($this->m_aWarnings as $sMessage)
  88. {
  89. $aWarnings[] = new SoapLogMessage($sMessage);
  90. }
  91. $aErrors = array();
  92. foreach($this->m_aErrors as $sMessage)
  93. {
  94. $aErrors[] = new SoapLogMessage($sMessage);
  95. }
  96. $oRet = new SOAPResult(
  97. $this->m_bStatus,
  98. $aResults,
  99. new SOAPResultLog($aErrors),
  100. new SOAPResultLog($aWarnings),
  101. new SOAPResultLog($aInfos)
  102. );
  103. return $oRet;
  104. }
  105. /**
  106. * Did the current processing encounter a stopper issue ?
  107. *
  108. * @return bool
  109. */
  110. public function IsOk()
  111. {
  112. return $this->m_bStatus;
  113. }
  114. /**
  115. * Add result details - object reference
  116. *
  117. * @param string sLabel
  118. * @param object oObject
  119. */
  120. public function AddResultObject($sLabel, $oObject)
  121. {
  122. $this->m_aResult[$sLabel] = array(
  123. 'id' => $oObject->GetKey(),
  124. 'name' => $oObject->GetName(),
  125. 'url' => $oObject->GetHyperlink(),
  126. );
  127. }
  128. /**
  129. * Log an error
  130. *
  131. * @param string sDescription
  132. */
  133. public function LogError($sDescription)
  134. {
  135. $this->m_aErrors[] = $sDescription;
  136. // Note: SOAP do transform false into null
  137. $this->m_bStatus = 0;
  138. }
  139. /**
  140. * Log a warning
  141. *
  142. * @param string sDescription
  143. */
  144. public function LogWarning($sDescription)
  145. {
  146. $this->m_aWarnings[] = $sDescription;
  147. }
  148. /**
  149. * Log an error or a warning
  150. *
  151. * @param string sDescription
  152. * @param boolean bIsStopper
  153. */
  154. public function LogIssue($sDescription, $bIsStopper = true)
  155. {
  156. if ($bIsStopper) $this->LogError($sDescription);
  157. else $this->LogWarning($sDescription);
  158. }
  159. /**
  160. * Log operation details
  161. *
  162. * @param description $sDescription
  163. */
  164. public function LogInfo($sDescription)
  165. {
  166. $this->m_aInfos[] = $sDescription;
  167. }
  168. protected static function LogToText($aLog)
  169. {
  170. return implode("\n", $aLog);
  171. }
  172. public function GetInfoAsText()
  173. {
  174. return self::LogToText($this->m_aInfos);
  175. }
  176. public function GetWarningsAsText()
  177. {
  178. return self::LogToText($this->m_aWarnings);
  179. }
  180. public function GetErrorsAsText()
  181. {
  182. return self::LogToText($this->m_aErrors);
  183. }
  184. public function GetReturnedDataAsText()
  185. {
  186. $sRet = '';
  187. foreach ($this->m_aResult as $sKey => $value)
  188. {
  189. $sRet .= "===== $sKey =====\n";
  190. $sRet .= print_r($value, true);
  191. }
  192. return $sRet;
  193. }
  194. }
  195. /**
  196. * Generic response of iTop SOAP services - failed login
  197. *
  198. * @package iTopORM
  199. */
  200. class WebServiceResultFailedLogin extends WebServiceResult
  201. {
  202. public function __construct($sLogin)
  203. {
  204. parent::__construct();
  205. $this->LogError("Wrong credentials: '$sLogin'");
  206. }
  207. }
  208. /**
  209. * Implementation of the Services
  210. *
  211. * @package iTopORM
  212. */
  213. class WebServices
  214. {
  215. /**
  216. * Helper to log a service delivery
  217. *
  218. * @param string sVerb
  219. * @param array aArgs
  220. * @param WebServiceResult oRes
  221. *
  222. */
  223. protected function LogUsage($sVerb, $oRes)
  224. {
  225. if (!MetaModel::IsLogEnabledWebService()) return;
  226. $oLog = new EventWebService();
  227. if ($oRes->IsOk())
  228. {
  229. $oLog->Set('message', $sVerb.' was successfully invoked');
  230. }
  231. else
  232. {
  233. $oLog->Set('message', $sVerb.' returned errors');
  234. }
  235. $oLog->Set('userinfo', UserRights::GetUser());
  236. $oLog->Set('verb', $sVerb);
  237. $oLog->Set('result', $oRes->IsOk());
  238. $oLog->Set('log_info', $oRes->GetInfoAsText());
  239. $oLog->Set('log_warning', $oRes->GetWarningsAsText());
  240. $oLog->Set('log_error', $oRes->GetErrorsAsText());
  241. $oLog->Set('data', $oRes->GetReturnedDataAsText());
  242. $oLog->DBInsertNoReload();
  243. }
  244. /**
  245. * Helper to set a scalar attribute
  246. *
  247. * @param string sAttCode
  248. * @param scalar value
  249. * @param DBObject oTargetObj
  250. * @param WebServiceResult oRes
  251. *
  252. */
  253. protected function MyObjectSetScalar($sAttCode, $sParamName, $value, &$oTargetObj, &$oRes)
  254. {
  255. $res = $oTargetObj->CheckValue($sAttCode, $value);
  256. if ($res === true)
  257. {
  258. $oTargetObj->Set($sAttCode, $value);
  259. }
  260. else
  261. {
  262. // $res contains the error description
  263. $oRes->LogError("Unexpected value for parameter $sParamName: $res");
  264. }
  265. }
  266. /**
  267. * Helper to set an external key
  268. *
  269. * @param string sAttCode
  270. * @param array aExtKeyDesc
  271. * @param DBObject oTargetObj
  272. * @param WebServiceResult oRes
  273. *
  274. */
  275. protected function MyObjectSetExternalKey($sAttCode, $sParamName, $aExtKeyDesc, &$oTargetObj, &$oRes)
  276. {
  277. $oExtKey = MetaModel::GetAttributeDef(get_class($oTargetObj), $sAttCode);
  278. $bIsMandatory = !$oExtKey->IsNullAllowed();
  279. if (is_null($aExtKeyDesc))
  280. {
  281. if ($bIsMandatory)
  282. {
  283. $oRes->LogError("Parameter $sParamName: found null for a mandatory key");
  284. }
  285. else
  286. {
  287. // skip silently
  288. return;
  289. }
  290. }
  291. if (count($aExtKeyDesc) == 0)
  292. {
  293. $oRes->LogIssue("Parameter $sParamName: no search condition has been specified", $bIsMandatory);
  294. return;
  295. }
  296. $sKeyClass = $oExtKey->GetTargetClass();
  297. $oReconFilter = new CMDBSearchFilter($sKeyClass);
  298. foreach ($aExtKeyDesc as $sForeignAttCode => $value)
  299. {
  300. if (!MetaModel::IsValidFilterCode($sKeyClass, $sForeignAttCode))
  301. {
  302. $aCodes = array_keys(MetaModel::GetClassFilterDefs($sKeyClass));
  303. $sMsg = "Parameter $sParamName: '$sForeignAttCode' is not a valid filter code for class '$sKeyClass', expecting a value in {".implode(', ', $aCodes)."}";
  304. $oRes->LogIssue($sMsg, $bIsMandatory);
  305. }
  306. // The foreign attribute is one of our reconciliation key
  307. $oReconFilter->AddCondition($sForeignAttCode, $value, '=');
  308. }
  309. $oExtObjects = new CMDBObjectSet($oReconFilter);
  310. switch($oExtObjects->Count())
  311. {
  312. case 0:
  313. $sMsg = "Parameter $sParamName: no match (searched: '".$oReconFilter->ToOQL(true)."')";
  314. $oRes->LogIssue($sMsg, $bIsMandatory);
  315. break;
  316. case 1:
  317. // Do change the external key attribute
  318. $oForeignObj = $oExtObjects->Fetch();
  319. $oTargetObj->Set($sAttCode, $oForeignObj->GetKey());
  320. // Report it (no need to report if the object already had this value
  321. if (array_key_exists($sAttCode, $oTargetObj->ListChanges()))
  322. {
  323. $oRes->LogInfo("Parameter $sParamName: found match ".get_class($oForeignObj)."::".$oForeignObj->GetKey()." '".$oForeignObj->GetName()."'");
  324. }
  325. break;
  326. default:
  327. $sMsg = "Parameter $sParamName: Found ".$oExtObjects->Count()." matches (searched: '".$oReconFilter->ToOQL(true)."')";
  328. $oRes->LogIssue($sMsg, $bIsMandatory);
  329. }
  330. }
  331. /**
  332. * Helper to link objects
  333. *
  334. * @param string sLinkAttCode
  335. * @param string sLinkedClass
  336. * @param array $aLinkList
  337. * @param DBObject oTargetObj
  338. * @param WebServiceResult oRes
  339. *
  340. * @return array List of objects that could not be found
  341. */
  342. protected function AddLinkedObjects($sLinkAttCode, $sParamName, $sLinkedClass, $aLinkList, &$oTargetObj, &$oRes)
  343. {
  344. $oLinkAtt = MetaModel::GetAttributeDef(get_class($oTargetObj), $sLinkAttCode);
  345. $sLinkClass = $oLinkAtt->GetLinkedClass();
  346. $sExtKeyToItem = $oLinkAtt->GetExtKeyToRemote();
  347. $aItemsFound = array();
  348. $aItemsNotFound = array();
  349. if (is_null($aLinkList))
  350. {
  351. return $aItemsNotFound;
  352. }
  353. foreach ($aLinkList as $aItemData)
  354. {
  355. if (!array_key_exists('class', $aItemData))
  356. {
  357. $oRes->LogWarning("Parameter $sParamName: missing 'class' specification");
  358. continue; // skip
  359. }
  360. $sTargetClass = $aItemData['class'];
  361. if (!MetaModel::IsValidClass($sTargetClass))
  362. {
  363. $oRes->LogError("Parameter $sParamName: invalid class '$sTargetClass'");
  364. continue; // skip
  365. }
  366. if (!MetaModel::IsParentClass($sLinkedClass, $sTargetClass))
  367. {
  368. $oRes->LogError("Parameter $sParamName: '$sTargetClass' is not a child class of '$sLinkedClass'");
  369. continue; // skip
  370. }
  371. $oReconFilter = new CMDBSearchFilter($sTargetClass);
  372. $aCIStringDesc = array();
  373. foreach ($aItemData['search'] as $sAttCode => $value)
  374. {
  375. if (!MetaModel::IsValidFilterCode($sTargetClass, $sAttCode))
  376. {
  377. $aCodes = array_keys(MetaModel::GetClassFilterDefs($sTargetClass));
  378. $oRes->LogError("Parameter $sParamName: '$sAttCode' is not a valid filter code for class '$sTargetClass', expecting a value in {".implode(', ', $aCodes)."}");
  379. continue 2; // skip the entire item
  380. }
  381. $aCIStringDesc[] = "$sAttCode: $value";
  382. // The attribute is one of our reconciliation key
  383. $oReconFilter->AddCondition($sAttCode, $value, '=');
  384. }
  385. if (count($aCIStringDesc) == 1)
  386. {
  387. // take the last and unique value to describe the object
  388. $sItemDesc = $value;
  389. }
  390. else
  391. {
  392. // describe the object by the given keys
  393. $sItemDesc = $sTargetClass.'('.implode('/', $aCIStringDesc).')';
  394. }
  395. $oExtObjects = new CMDBObjectSet($oReconFilter);
  396. switch($oExtObjects->Count())
  397. {
  398. case 0:
  399. $oRes->LogWarning("Parameter $sParamName: object to link $sLinkedClass / $sItemDesc could not be found (searched: '".$oReconFilter->ToOQL(true)."')");
  400. $aItemsNotFound[] = $sItemDesc;
  401. break;
  402. case 1:
  403. $aItemsFound[] = array (
  404. 'object' => $oExtObjects->Fetch(),
  405. 'link_values' => @$aItemData['link_values'],
  406. 'desc' => $sItemDesc,
  407. );
  408. break;
  409. default:
  410. $oRes->LogWarning("Parameter $sParamName: Found ".$oExtObjects->Count()." matches for item '$sItemDesc' (searched: '".$oReconFilter->ToOQL(true)."')");
  411. $aItemsNotFound[] = $sItemDesc;
  412. }
  413. }
  414. if (count($aItemsFound) > 0)
  415. {
  416. $aLinks = array();
  417. foreach($aItemsFound as $aItemData)
  418. {
  419. $oLink = MetaModel::NewObject($sLinkClass);
  420. $oLink->Set($sExtKeyToItem, $aItemData['object']->GetKey());
  421. foreach($aItemData['link_values'] as $sKey => $value)
  422. {
  423. if(!MetaModel::IsValidAttCode($sLinkClass, $sKey))
  424. {
  425. $oRes->LogWarning("Parameter $sParamName: Attaching item '".$aItemData['desc']."', the attribute code '$sKey' is not valid ; check the class '$sLinkClass'");
  426. }
  427. else
  428. {
  429. $oLink->Set($sKey, $value);
  430. }
  431. }
  432. $aLinks[] = $oLink;
  433. }
  434. $oImpactedInfraSet = DBObjectSet::FromArray($sLinkClass, $aLinks);
  435. $oTargetObj->Set($sLinkAttCode, $oImpactedInfraSet);
  436. }
  437. return $aItemsNotFound;
  438. }
  439. protected function MyObjectInsert($oTargetObj, $sResultLabel, $oChange, &$oRes)
  440. {
  441. if ($oRes->IsOk())
  442. {
  443. list($bRes, $aIssues) = $oTargetObj->CheckToWrite();
  444. if ($bRes)
  445. {
  446. $iId = $oTargetObj->DBInsertTrackedNoReload($oChange);
  447. $oRes->LogInfo("Created object ".get_class($oTargetObj)."::$iId");
  448. $oRes->AddResultObject($sResultLabel, $oTargetObj);
  449. }
  450. else
  451. {
  452. $oRes->LogError("The ticket could not be created due to forbidden values (or inconsistent values)");
  453. foreach($aIssues as $iIssue => $sIssue)
  454. {
  455. $oRes->LogError("Issue #$iIssue: $sIssue");
  456. }
  457. }
  458. }
  459. }
  460. static protected function SoapStructToExternalKeySearch($oExternalKeySearch)
  461. {
  462. if (is_null($oExternalKeySearch)) return null;
  463. if ($oExternalKeySearch->IsVoid()) return null;
  464. $aRes = array();
  465. foreach($oExternalKeySearch->conditions as $oSearchCondition)
  466. {
  467. $aRes[$oSearchCondition->attcode] = $oSearchCondition->value;
  468. }
  469. return $aRes;
  470. }
  471. static protected function SoapStructToLinkCreationSpec(SoapLinkCreationSpec $oLinkCreationSpec)
  472. {
  473. $aRes = array
  474. (
  475. 'class' => $oLinkCreationSpec->class,
  476. 'search' => array(),
  477. 'link_values' => array(),
  478. );
  479. foreach($oLinkCreationSpec->conditions as $oSearchCondition)
  480. {
  481. $aRes['search'][$oSearchCondition->attcode] = $oSearchCondition->value;
  482. }
  483. foreach($oLinkCreationSpec->attributes as $oAttributeValue)
  484. {
  485. $aRes['link_values'][$oAttributeValue->attcode] = $oAttributeValue->value;
  486. }
  487. return $aRes;
  488. }
  489. /**
  490. * Get the server version (TODO: get it dynamically, where ?)
  491. *
  492. * @return WebServiceResult
  493. */
  494. static public function GetVersion()
  495. {
  496. if (ITOP_REVISION == '$WCREV$')
  497. {
  498. $sVersionString = ITOP_VERSION.' [dev]';
  499. }
  500. else
  501. {
  502. // This is a build made from SVN, let display the full information
  503. $sVersionString = ITOP_VERSION."-".ITOP_REVISION." ".ITOP_BUILD_DATE;
  504. }
  505. return $sVersionString;
  506. }
  507. public function CreateIncidentTicket($sLogin, $sPassword, $sTitle, $sDescription, $oCallerDesc, $oCustomerDesc, $oServiceDesc, $oServiceSubcategoryDesc, $sProduct, $oWorkgroupDesc, $aSOAPImpactedCIs, $sImpact, $sUrgency)
  508. {
  509. if (!UserRights::CheckCredentials($sLogin, $sPassword))
  510. {
  511. $oRes = new WebServiceResultFailedLogin($sLogin);
  512. $this->LogUsage(__FUNCTION__, $oRes);
  513. return $oRes->ToSoapStructure();
  514. }
  515. UserRights::Login($sLogin);
  516. $aCallerDesc = self::SoapStructToExternalKeySearch($oCallerDesc);
  517. $aCustomerDesc = self::SoapStructToExternalKeySearch($oCustomerDesc);
  518. $aServiceDesc = self::SoapStructToExternalKeySearch($oServiceDesc);
  519. $aServiceSubcategoryDesc = self::SoapStructToExternalKeySearch($oServiceSubcategoryDesc);
  520. $aWorkgroupDesc = self::SoapStructToExternalKeySearch($oWorkgroupDesc);
  521. $aImpactedCIs = array();
  522. if (is_null($aSOAPImpactedCIs)) $aSOAPImpactedCIs = array();
  523. foreach($aSOAPImpactedCIs as $oImpactedCIs)
  524. {
  525. $aImpactedCIs[] = self::SoapStructToLinkCreationSpec($oImpactedCIs);
  526. }
  527. $oRes = $this->_CreateIncidentTicket
  528. (
  529. $sTitle,
  530. $sDescription,
  531. $aCallerDesc,
  532. $aCustomerDesc,
  533. $aServiceDesc,
  534. $aServiceSubcategoryDesc,
  535. $sProduct,
  536. $aWorkgroupDesc,
  537. $aImpactedCIs,
  538. $sImpact,
  539. $sUrgency
  540. );
  541. return $oRes->ToSoapStructure();
  542. }
  543. /**
  544. * Create an incident ticket from a monitoring system
  545. * Some CIs might be specified (by their name/IP)
  546. *
  547. * @param string sTitle
  548. * @param string sDescription
  549. * @param array aCallerDesc
  550. * @param array aCustomerDesc
  551. * @param array aServiceDesc
  552. * @param array aServiceSubcategoryDesc
  553. * @param string sProduct
  554. * @param array aWorkgroupDesc
  555. * @param array aImpactedCIs
  556. * @param string sImpact
  557. * @param string sUrgency
  558. *
  559. * @return WebServiceResult
  560. */
  561. protected function _CreateIncidentTicket($sTitle, $sDescription, $aCallerDesc, $aCustomerDesc, $aServiceDesc, $aServiceSubcategoryDesc, $sProduct, $aWorkgroupDesc, $aImpactedCIs, $sImpact, $sUrgency)
  562. {
  563. $oRes = new WebServiceResult();
  564. try
  565. {
  566. $oMyChange = MetaModel::NewObject("CMDBChange");
  567. $oMyChange->Set("date", time());
  568. $oMyChange->Set("userinfo", "Administrator");
  569. $iChangeId = $oMyChange->DBInsertNoReload();
  570. $oNewTicket = MetaModel::NewObject('Incident');
  571. $this->MyObjectSetScalar('title', 'title', $sTitle, $oNewTicket, $oRes);
  572. $this->MyObjectSetScalar('description', 'description', $sDescription, $oNewTicket, $oRes);
  573. $this->MyObjectSetExternalKey('org_id', 'customer', $aCustomerDesc, $oNewTicket, $oRes);
  574. $this->MyObjectSetExternalKey('caller_id', 'caller', $aCallerDesc, $oNewTicket, $oRes);
  575. $this->MyObjectSetExternalKey('service_id', 'service', $aServiceDesc, $oNewTicket, $oRes);
  576. $this->MyObjectSetExternalKey('servicesubcategory_id', 'servicesubcategory', $aServiceSubcategoryDesc, $oNewTicket, $oRes);
  577. $this->MyObjectSetScalar('product', 'product', $sProduct, $oNewTicket, $oRes);
  578. $this->MyObjectSetExternalKey('workgroup_id', 'workgroup', $aWorkgroupDesc, $oNewTicket, $oRes);
  579. $aDevicesNotFound = $this->AddLinkedObjects('ci_list', 'impacted_cis', 'FunctionalCI', $aImpactedCIs, $oNewTicket, $oRes);
  580. if (count($aDevicesNotFound) > 0)
  581. {
  582. $this->MyObjectSetScalar('description', 'n/a', $sDescription.' - Related CIs: '.implode(', ', $aDevicesNotFound), $oNewTicket, $oRes);
  583. }
  584. else
  585. {
  586. $this->MyObjectSetScalar('description', 'n/a', $sDescription, $oNewTicket, $oRes);
  587. }
  588. $this->MyObjectSetScalar('impact', 'impact', $sImpact, $oNewTicket, $oRes);
  589. $this->MyObjectSetScalar('urgency', 'urgency', $sUrgency, $oNewTicket, $oRes);
  590. $this->MyObjectInsert($oNewTicket, 'created', $oMyChange, $oRes);
  591. }
  592. catch (CoreException $e)
  593. {
  594. $oRes->LogError($e->getMessage());
  595. }
  596. catch (Exception $e)
  597. {
  598. $oRes->LogError($e->getMessage());
  599. }
  600. $this->LogUsage(__FUNCTION__, $oRes);
  601. return $oRes;
  602. }
  603. }
  604. ?>