Skip to content

Commit

Permalink
Ticket unacms#4711 - Automations. Todo for test evaluation.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Jul 8, 2024
1 parent a2ec6e4 commit 9fef952
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
26 changes: 17 additions & 9 deletions ai/BxDolAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,16 @@ protected function _callAutomatorScheduler($aParams = [])

$this->evalCode($aParams['automator'], true);
}



public function evalCode($aAutomator, $isWriteLog = true, $aParams = null)
{
/*
* TODO: Improve code evaluation.
*
ob_start();
set_error_handler("evalErrorHandler");
try{
*/
try {
$sCode = '';
if ($aAutomator['type'] == 'scheduler'){
$sCode = $aAutomator['code'] . '; onCron();';
Expand All @@ -187,18 +190,23 @@ public function evalCode($aAutomator, $isWriteLog = true, $aParams = null)
$this->writeLog($oException->getFile() . ':' . $oException->getLine() . ' ' . $oException->getMessage());
}
return $oException->getMessage();
} finally {
$sOutput = ob_get_clean();
if ($sOutput != '')
}
finally {
/*
* TODO: Improve code evaluation.
*
$sOutput = ob_get_clean();
if ($sOutput != '')
return "Eval error: " . $sOutput;
restore_error_handler();
*/
}
}

private function writeLog($sString)
{
{
bx_log('sys_agents', $sString);
}
}
}

class EvalException extends Exception {}
Expand Down
8 changes: 5 additions & 3 deletions studio/classes/BxDolStudioAgentsAutomatorsCmts.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ public function actionApproveCode()

$aAutomator = $this->_oAI->getAutomator($iObjId, true);
$aAutomator['code'] = $aCmt['cmt_text'];


/*
* TODO: Improve code evaluation.
*
$oAlert = new BxDolAlerts('test', 'test', -1, -1, []);
$sRv = $this->_oAI->evalCode($aAutomator, false, ['alert' => $oAlert]);


if ($sRv != ''){
return echoJson(['msg' => 'Error in code: ' . $sRv]);
}
*/

if(!$this->_oQueryAgents->updateAutomators(['code' => $aCmt['cmt_text'], 'status' => 'ready'], ['id' => (int)$this->getId()]))
return echoJson([]);
Expand Down

0 comments on commit 9fef952

Please sign in to comment.