History::push

  1. Bitrix24 API (v. 23.675.0)
  2. landing
  3. History
  4. push
  • Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/history.php
  • Класс: BitrixLandingHistory
  • Вызов: History::push
public function push(string $actionName, array $params): bool
{
	$actionName = strtoupper($actionName);

	$action = ActionFactory::getAction($actionName);
	if (!$action)
	{
		return false;
		// todo: or err
	}
	$action->setParams($params);

	$fields = [
		'ENTITY_TYPE' => $this->entityType,
		'ENTITY_ID' => $this->entityId,
		'ACTION' => $actionName,
		'ACTION_PARAMS' => $action->getParams(),
		'CREATED_BY_ID' => Manager::getUserId() ?: 1,
		'DATE_CREATE' => new DateTime,
	];

	// check duplicates
	if (
		!empty($this->stack[$this->step])
		&& ActionFactory::compareSteps($this->stack[$this->step], $fields)
	)
	{
		return false;
	}

	if (!$action->isNeedPush())
	{
		return true;
	}

	$stackCount = $this->getStackCount();
	if ($this->step < $stackCount)
	{
		if (!$this->clearAfter($this->step + 1))
		{
			return false;
		}
	}

	$nextStep =
		(self::$multiplyMode && self::$multiplyStep !== null)
			? self::$multiplyStep
			: $this->step + 1
	;

	if (!$this->saveStep($nextStep))
	{
		return false;
	}

	self::$multiplyStep = $nextStep;
	// todo: drop $multiplyStep after last element (when set multiply mode off)

	if (self::$multiplyMode && self::$multiplyId !== null)
	{
		$fields['MULTIPLY_ID'] = self::$multiplyId;
	}

	$resAdd = HistoryTable::add($fields);

	// save MULTIPLY_ID for first element in group
	if (self::$multiplyMode && self::$multiplyId === null)
	{
		self::$multiplyId = $resAdd->getId();
		HistoryTable::update(self::$multiplyId, [
			'MULTIPLY_ID' => self::$multiplyId,
		]);
	}

	return $resAdd->isSuccess();
}

Добавить комментарий