75 if(!is_array($inputParams))
76 throw new \Bitrix\Main\ArgumentTypeException(
"inputParams",
"array");
78 $retStr = $this->actionParams[
"START_COMMAND_TEMPLATE"];
80 foreach ($this->userParams as $key => $paramValue)
82 if($this->actionParams[
'USER_PARAMS'][$key][
'THROUGH_FILE'] ==
'Y')
87 $tmpFile = $tmpDir.
'/.'.randString();
88 $res = File::putFileContents($tmpFile, $paramValue);
93 $paramValue = $tmpFile;
97 $retStr = str_replace(
'##USER_PARAMS:'.$key.
'##', $paramValue, $retStr);
100 if($this->serverHostname <>
'' && $this->serverHostname !=
"global")
105 if(is_array($serverParams))
107 foreach ($serverParams as $key => $paramValue)
109 if(is_string($paramValue))
111 $retStr = str_replace(
'##SERVER_PARAMS:' . $key .
'##', $paramValue, $retStr);
117 if(!empty($inputParams))
118 foreach ($inputParams as $key => $paramValue)
119 $retStr = str_replace(
'##INPUT_PARAMS:'.$key.
'##', $paramValue, $retStr);
121 if(isset($this->actionParams[
"CODE_PARAMS"]) && is_array($this->actionParams[
"CODE_PARAMS"]))
123 foreach($this->actionParams[
"CODE_PARAMS"] as $paramId => $paramCode)
125 $res = eval($paramCode);
126 $retStr = str_replace(
'##CODE_PARAMS:'.$paramId.
'##', $res, $retStr);
130 foreach ($this->freeParams as $key => $paramValue)
131 $retStr = str_replace(
'##'.$key.
'##', $paramValue, $retStr);
143 public function start(array $inputParams = array())
145 if(!is_array($inputParams))
146 throw new \Bitrix\Main\ArgumentTypeException(
"inputParams",
"array");
148 if(isset($this->actionParams[
"MODIFYERS"]) && is_array($this->actionParams[
"MODIFYERS"]))
150 $needMoreUserInfo =
false;
152 foreach($this->actionParams[
"MODIFYERS"] as $modifyerFunction)
154 if(is_callable($modifyerFunction))
158 $this->actionParams = call_user_func($modifyerFunction, $this->
id, $this->actionParams, $this->serverHostname, $this->userParams);
163 $needMoreUserInfo =
true;
168 if($needMoreUserInfo)
179 $result = $this->shellAdapter->syncExec($command);
180 $output = $this->shellAdapter->getLastOutput();
185 $arOut = json_decode($output,
true);
187 if(is_array($arOut) && !empty($arOut))
192 $error = $this->shellAdapter->getLastError();
195 if(isset($arOutput[
"error"]) && intval($arOutput[
"error"]) > 0 && isset($arOutput[
"message"]) && $arOutput[
"message"] <>
'')
196 $error .=
" ".$arOutput[
"message"];
203 $error =
'Cant\'t create command for action execution';
206 $this->result = array(
208 "NAME" => isset($this->actionParams[
"NAME"]) ? $this->actionParams[
"NAME"] :
"[".$this->id.
"]",
209 "RESULT" =>
$result ?
"OK" :
"ERROR",
276 protected function log($level, $auditType, $actionId, $description)
278 if($this->logLevel < $level)