6use \Bitrix\Main\Localization\Loc;
25 throw new \Bitrix\Main\ArgumentNullException(
"actionId");
27 $actionsDefinitions = static::getList();
31 if(isset($actionsDefinitions[$actionId]))
32 $result = $actionsDefinitions[$actionId];
51 array $userParams = [],
52 array $freeParams = [],
53 array $actionParams = []
57 throw new \Bitrix\Main\ArgumentNullException(
"actionId");
59 if(!is_array($userParams))
60 throw new \Bitrix\Main\ArgumentTypeException(
"userParams",
"array");
62 if(!is_array($userParams))
63 throw new \Bitrix\Main\ArgumentTypeException(
"freeParams",
"array");
65 if(!is_array($actionParams))
66 throw new \Bitrix\Main\ArgumentTypeException(
"actionParams",
"array");
70 if(!isset($actionParams[
"TYPE"]) || $actionParams[
"TYPE"] !==
"MODIFYED")
71 $actionParams = static::getAction($actionId);
73 if(empty($actionParams))
74 throw new \Exception(
"Can't find params of action ".$actionId);
76 if(isset($actionParams[
"TYPE"]) && $actionParams[
"TYPE"] ===
"CHAIN")
77 $action =
new ActionsChain($actionId, $actionParams, $serverHostname, $userParams, $freeParams);
78 else if(!empty($actionParams))
79 $action =
new Action($actionId, $actionParams, $serverHostname, $userParams, $freeParams);
93 $execRes = $shellAdapter->syncExec(
"sudo -u root /opt/webdir/bin/bx-process -a status -t ".$bid.
" -o json");
94 $data = $shellAdapter->getLastOutput();
98 $arData = json_decode($data,
true);
100 if(isset($arData[
"params"][$bid]))
102 $result = $arData[
"params"][$bid];
105 if($result[
"status"] ===
"finished")
109 "SCALE_ACTION_CHECK_STATE",
114 elseif($result[
"status"] ===
"error")
118 "SCALE_ACTION_CHECK_STATE",
139 public static function getList($checkConditions =
false)
145 $filename = \Bitrix\Main\Application::getDocumentRoot().
"/bitrix/modules/scale/include/actionsdefinitions.php";
146 $file = new \Bitrix\Main\IO\File($filename);
147 $actionsDefinitions = [];
149 if($file->isExists())
150 require_once($filename);
152 throw new \Bitrix\Main\IO\FileNotFoundException($filename);
154 if(isset($actionsDefinitions))
156 $def = $actionsDefinitions;
158 if(is_array($def) && $checkConditions)
160 foreach($def as $actionId => $action)
162 if(isset($action[
"CONDITION"]) && !self::isConditionSatisfied($action[
"CONDITION"]))
164 unset($def[$actionId]);
169 if(getenv(
'BITRIX_ENV_TYPE') ===
'crm')
172 $def[
'MONITORING_ENABLE'],
174 $def[
'SITE_CREATE_LINK'],
175 $def[
'SITE_CREATE_KERNEL'],
177 $def[
'MEMCACHED_ADD_ROLE'],
178 $def[
'MEMCACHED_DEL_ROLE'],
179 $def[
'SPHINX_ADD_ROLE'],
180 $def[
'PUSH_DEL_ROLE']
201 if(!isset($condition[
"COMMAND"], $condition[
"PARAMS"]) || !is_array($condition[
"PARAMS"]))
206 if(!isset($condition[
"PARAMS"][0], $condition[
"PARAMS"][1], $condition[
"PARAMS"][2]))
211 $actRes = static::getConditionActionResult($condition[
"COMMAND"]);
213 if(isset($actRes[
"condition"][
"OUTPUT"][
"DATA"][
"params"]))
215 $conditionValue = static::extractConditionValue(
216 $condition[
"PARAMS"][0],
217 $actRes[
"condition"][
"OUTPUT"][
"DATA"][
"params"]
222 $result = static::checkCondition(
224 $condition[
"PARAMS"][1],
225 $condition[
"PARAMS"][2]
241 $params = explode(
":", $paramName);
243 if(!is_array($params) || count($params) !== 2)
248 if(isset($paramsValues[$params[0]][$params[1]]))
250 $result = (string)$paramsValues[$params[0]][$params[1]];
266 $action =
new Action(
"condition", [
267 "START_COMMAND_TEMPLATE" => $command,
274 $result = $action->getResult();
277 catch(\Exception $excpt)
291 protected static function checkCondition(
string $operand1,
string $operator,
string $operand2): bool
293 $allowedOperators = [
'==='];
295 if(!in_array($operator, $allowedOperators))
300 $allowedOperandRegex =
'/^[0-9a-zA-Z_:\-\'\"]+$/i';
302 if(!preg_match($allowedOperandRegex, $operand1))
307 if(!preg_match($allowedOperandRegex, $operand2))
312 return eval(
"return ('{$operand1}' {$operator} '{$operand2}');");
333 $execRes = $shellAdapter->syncExec(
"sudo -u root /opt/webdir/bin/bx-process -a list -o json");
334 $data = $shellAdapter->getLastOutput();
338 $arData = json_decode($data,
true);
341 if(isset($arData[
"params"]) && is_array($arData[
"params"]))
343 foreach($arData[
"params"] as $bid => $actionParams)
345 if(mb_strpos($bid,
'common_') === 0)
348 if($actionParams[
"status"] ===
"running")
350 $result = [$bid => $actionParams];
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static getActionState($bid)
static checkCondition(string $operand1, string $operator, string $operand2)
static getActionObject( $actionId, $serverHostname="", array $userParams=[], array $freeParams=[], array $actionParams=[])
static extractConditionValue(string $paramName, array $paramsValues)
static setLogLevel($logLevel)
static isConditionSatisfied($condition)
static getConditionActionResult(string $command)
static getAction($actionId)
static getList($checkConditions=false)
static checkRunningAction()
static addRecord($level, $auditType, $itemId, $description)