Current Path : /var/www/axolotl/data/www/arhangelsk.axolotls.ru/a537b/ |
Current File : /var/www/axolotl/data/www/arhangelsk.axolotls.ru/a537b/command.tar |
delete.php 0000664 00000002222 14773647335 0006542 0 ustar 00 <?php namespace Bitrix\Rpa\Command; use Bitrix\Main\Result; use Bitrix\Rpa\Command; use Bitrix\Rpa\Driver; use Bitrix\Rpa\Integration\Bizproc; class Delete extends Command { protected $historyItem; public function checkAccess(): Result { $result = new Result(); $userPermissions = Driver::getInstance()->getUserPermissions($this->userId); if(!$userPermissions->canDeleteItem($this->item)) { $result->addError($this->getDeletePermissionDeniedError($this->item->getName())); } return $result; } public function checkStage(): Result { return new Result(); } protected function save(): Result { $this->historyItem = clone $this->item; return $this->item->delete(); } protected function sendPullEvent(): bool { return Driver::getInstance()->getPullManager()->sendItemDeletedEvent($this->historyItem); } protected function runAutomation(): Result { return Bizproc\Listener::onItemDelete($this->historyItem ?? $this->item); } /** * There is not need to save to history because it will be purged right after deleting element * * @return bool */ public function isSaveToHistoryEnabled(): bool { return false; } } add.php 0000664 00000004671 14773647335 0006042 0 ustar 00 <?php namespace Bitrix\Rpa\Command; use Bitrix\Main\Error; use Bitrix\Main\Localization\Loc; use Bitrix\Main\Result; use Bitrix\Main\Type\DateTime; use Bitrix\Rpa\Command; use Bitrix\Rpa\Driver; use Bitrix\Rpa\Integration\Bizproc; class Add extends Command { public const ERROR_CODE_FIRST_STAGE_NOT_FOUND = 'RPA_FIRST_STAGE_NOT_FOUND'; public function checkFields(): Result { // we do not check fields during creating return new Result(); } public function checkAccess(): Result { $result = new Result(); $userPermissions = Driver::getInstance()->getUserPermissions($this->userId); if(!$userPermissions->canAddItemsToType($this->item->getType()->getId())) { $result->addError($this->getModifyAccessDeniedError($this->item->getStage()->getName())); } return $result; } public function checkStage(): Result { $result = new Result(); $firstStage = $this->item->getType()->getFirstStage(); if(!$firstStage) { $result->addError($this->getEmptyStageError()); } elseif($this->item->getStageId() !== $firstStage->getId()) { $result->addError($this->getWrongStageError($firstStage->getName())); } return $result; } protected function getWrongStageError(string $stageName): Error { return new Error(Loc::getMessage('RPA_COMMAND_ADD_ITEM_WRONG_STAGE', [ '#STAGE#' => $stageName, ]), static::ERROR_CODE_WRONG_STAGE); } protected function getEmptyStageError(): Error { return new Error(Loc::getMessage('RPA_COMMAND_ADD_ITEM_EMPTY_STAGE', [ ]), static::ERROR_CODE_FIRST_STAGE_NOT_FOUND); } protected function save(): Result { if (Driver::getInstance()->getBitrix24Manager()->isCreateItemRestricted($this->item->getType()->getId())) { return ((new Result())->addError(new Error(Loc::getMessage('RPA_LIMIT_CREATE_ITEM_ERROR')))); } if ($this->userId > 0) { $this->item->setCreatedBy($this->userId); //$this->item->setMovedBy($this->userId); } $this->item->setCreatedTime(new DateTime()); //$this->item->setMovedTime(new DateTime()); return $this->item->save(); } protected function sendPullEvent(): bool { return Driver::getInstance()->getPullManager()->sendItemAddedEvent($this->item, $this->pullEventId); } protected function runAutomation(): Result { if($this->pullEventId) { Driver::getInstance()->getPullManager()->addItemUpdateEventId($this->item->getType()->getId(), $this->item->getId(), $this->pullEventId); } return Bizproc\Listener::onItemAdd($this->item); } } update.php 0000664 00000011431 14773647335 0006564 0 ustar 00 <?php namespace Bitrix\Rpa\Command; use Bitrix\Main\Error; use Bitrix\Main\Localization\Loc; use Bitrix\Main\Result; use Bitrix\Main\Type\DateTime; use Bitrix\Rpa\Command; use Bitrix\Rpa\Driver; use Bitrix\Rpa\Integration\Bizproc; use Bitrix\Rpa\Model\ItemHistory; class Update extends Command { protected $isItemChanged; protected $historyItem; public function checkAccess(): Result { $result = new Result(); $userPermissions = Driver::getInstance()->getUserPermissions($this->userId); if($this->item->isChanged('STAGE_ID')) { if(!$userPermissions->canMoveItem($this->item, $this->item->remindActualStageId(), $this->item->getStageId())) { $actualStage = $this->item->getType()->getStage($this->item->remindActualStageId()); if($actualStage) { $actualStageName = $actualStage->getName(); } else { $actualStageName = $this->item->remindActualStageId(); } $result->addError($this->getMoveAccessDeniedError($actualStageName)); } elseif(!$userPermissions->canModifyItemsInStage($this->item->getType(), $this->item->remindActualStageId())) { $userFields = $this->item->getType()->getUserFieldCollection(); foreach($userFields as $userField) { if($this->item->isChanged($userField->getName())) { $result->addError($this->getModifyAccessDeniedError($this->item->getStage()->getName())); break; } } } } elseif(!$userPermissions->canModifyItemsInStage($this->item->getType(), $this->item->getStageId())) { $result->addError($this->getModifyAccessDeniedError($this->item->getStage()->getName())); } return $result; } public function checkStage(): Result { $result = new Result(); if($this->item->isChanged('STAGE_ID')) { $userPermissions = Driver::getInstance()->getUserPermissions($this->userId); if(!$userPermissions->canMoveItem($this->item, $this->item->remindActualStageId(), $this->item->getStageId())) { $result->addError($this->getWrongStageError($this->item->getStage()->getName())); } } return $result; } protected function save(): Result { if(!$this->isItemChanged()) { return new Result(); } if($this->userId > 0) { $this->item->setUpdatedBy($this->userId); if($this->item->isChanged('STAGE_ID')) { $this->item->setMovedBy($this->userId); } } $this->item->setUpdatedTime(new DateTime()); if($this->item->isChanged('STAGE_ID')) { $this->item->setMovedTime(new DateTime()); } return $this->item->save(); } protected function sendPullEvent(): bool { if($this->isItemChanged()) { return Driver::getInstance()->getPullManager()->sendItemUpdatedEvent( $this->item, $this->pullEventId, $this->historyItem ); } return true; } protected function isItemChanged(): bool { if($this->isItemChanged === null) { $this->isItemChanged = ( $this->item->isChanged('STAGE_ID') || !empty($this->item->getChangedUserFieldNames()) ); if ($this->isItemChanged) { $this->historyItem = clone $this->item; } } return $this->isItemChanged; } public function saveToHistory(ItemHistory $historyRecord): Result { // skip history if item is not changed if($this->taskId > 0 || $this->isItemChanged()) { parent::saveToHistory($historyRecord); } return new Result(); } protected function runAutomation(): Result { if($this->isItemChanged()) { if($this->pullEventId) { Driver::getInstance()->getPullManager()->addItemUpdateEventId( $this->item->getType()->getId(), $this->item->getId(), $this->pullEventId ); } return Bizproc\Listener::onItemUpdate($this->item, $this->historyItem); } return new Result(); } public function checkTasks(): Result { $result = new Result(); // do not check tasks for update on the same stage. if(!$this->item->isChanged('STAGE_ID')) { return $result; } if (!Bizproc\Automation\Factory::canUseAutomation()) { return $result; } $taskManager = Driver::getInstance()->getTaskManager(); if(!$taskManager) { return $result; } $stageChanged = $taskManager->onItemStageUpdate($this->item, $this->item->getStageId(), $this->userId); if ($stageChanged) { $this->terminate(); return $result; } $participants = $taskManager->getItemTaskParticipants($this->item); // check tasks for actual stage. $this->item->remindActualStageId(); //if current user has tasks for this item if(in_array($this->userId, $participants, true)) { $result->addError(new Error(Loc::getMessage('RPA_COMMAND_ITEM_USER_HAS_TASKS'), static::ERROR_CODE_ITEM_USER_HAS_TASKS)); } //if any user has tasks for this item elseif($participants) { $result->addError(new Error(Loc::getMessage('RPA_COMMAND_ITEM_TASKS_NOT_COMPLETED'), static::ERROR_CODE_ITEM_TASKS_NOT_COMPLETED)); } return $result; } }