Documentation

Command

Description

abstract class Bitrix\Rpa\Command - base class for updating items.

To avoid excessive and redundant logic for elements, all checks, preparations, launch of automation rules and etc. are moved to to this class.

Its an abstract class that has three descendants:

Constants

  • public const ERROR_CODE_ITEM_MOVE_PERMISSION = 'RPA_ITEM_MOVE_ACCESS_DENIED';
  • public const ERROR_CODE_ITEM_MODIFY_PERMISSION = 'RPA_ITEM_MODIFY_ACCESS_DENIED';
  • public const ERROR_CODE_WRONG_STAGE = 'RPA_ITEM_WRONG_STAGE';
  • public const ERROR_CODE_MANDATORY_FIELD_EMPTY = 'RPA_MANDATORY_FIELD_EMPTY';
  • public const ERROR_CODE_ITEM_USER_HAS_TASKS = 'RPA_ITEM_USER_HAS_TASKS';
  • public const ERROR_CODE_ITEM_TASKS_NOT_COMPLETED = 'RPA_ITEM_TASKS_NOT_COMPLETED';
  • public const ERROR_CODE_ITEM_DELETE_PERMISSION = 'RPA_ITEM_DELETE_PERMISSION'.

These constants contain error codes that can be returned during command execution

Methods

Method Description Available from version
public function __construct(Item $item, array $data = []) Constructor.

Receives an item and array of parameters $data

$data can contain the following:

  • userId user ID that launches the command. When not passed, current user is sourced;
  • scope string ID for updated scope. Accepts value as in Bitrix\Rpa\Model\ItemHistoryTable;
  • taskId task ID that launched the command.

All this data has getters and setters. Passing to constructor is optional:

  • setUserId(int $userId): Command
  • getUserId(): int
  • setScope(string $scope): Command
  • getScope(): ?string
  • setTaskId(int $taskId): Command
  • getTaskId(): ?int
  • getItem(): Item
public function run(): Result Main command method.

This method performs the following:

  1. Checks access permissions;
  2. Checks if specified stage is correct;
  3. Checks fields are updated correctly;
  4. Checks item's tasks existence;
  5. Saves changes;
  6. Saves data in revision history;
  7. Creates a timeline record;
  8. Sends push on creation of timeline record;
  9. Sends push on item's modifications;
  10. Launches automation rules.

During the moment of launching the automation rules other actions can be performed with the item that will raise new command instance.

All checks are enabled by default

All checks are executed sequentially, if they were not disabled. When an error occurs during one of checks, command interruption is terminated.

Separate set of methods is available for enabling/disabling

  • disableAllChecks(): Command disables all checks;
  • enableCheckAccess(): Command enables access permission check;
  • disableCheckAccess(): Command disables access permission;
  • isCheckAccessEnabled(): bool returns true when access permission check is enabled;
  • enableCheckTasks(): Command enables task check;
  • disableCheckTasks(): Command disables task check;
  • isCheckTasksEnabled(): bool returns true when task check is enabled;
  • enableCheckStage(): Command enables stage check;
  • disableCheckStage(): Command disables stage check;
  • isCheckStageEnabled(): bool returns true when stage check is enabled;
  • enableCheckFields(): Command enables field check;
  • disableCheckFields(): Command disables field check;
  • isCheckFieldsEnabled(): bool returns true when field check is enabled.

Additionally, you can disable automatic actions executed after modification are saved:

  • enableSaveToHistory(): Command enables saving in revision history;
  • disableSaveToHistory(): Command disables saving in revision history;
  • isSaveToHistoryEnabled(): bool returns true, when saving in revision history is enabled;
  • enableAutomation(): Command enables start of automation;
  • disableAutomation(): Command disables start of automation;
  • isAutomationEnabled(): bool returns true when automation is enabled.
public function setPullEventId(string $eventId): Command Allows specifying event ID for \Bitrix\Rpa\Integration\PullManager.
abstract public function checkStage(): Result; Executes stage check. Defined in descendants.
abstract public function checkAccess(): Result; Executes access permission check. Defined in descendants.
public function checkTasks(): Result Executes check of launched tasks. Does nothing by default, defined only in Bitrix\Rpa\Command\Update.
public function saveToHistory(ItemHistory $historyRecord): Result Saves data into revision history table.
public function checkFields(): Result Executes field check. In Bitrix\Rpa\Command\Add this method is empty and fields are not changed when deleting.
public function checkRequiredFields(UserFieldCollection $userFieldCollection): Result Checks if all required fields from collection $userFieldCollection are filled.
public function resetNotEditableFields(UserFieldCollection $userFieldCollection): Result Resets item's user field values from collection $userFieldCollection that cannot be edited.
public function isTerminated(): bool Automatic task completion mode can be triggered during execution of method checkTasks in [link=11338782]Bitrix\Rpa\Command\Update[/link].

In this case, further command execution does not have sense, because item was updated and modified again. And command execution must be terminated.

This method returns true when command was terminated.



© «Bitrix24», 2001-2024