403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/cvetdv.ru/bitrix/modules/lists/lib/Workflow/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/cvetdv.ru/bitrix/modules/lists/lib/Workflow/Starter.php
<?php

namespace Bitrix\Lists\Workflow;

use Bitrix\Bizproc\Api\Response\Error;
use Bitrix\Lists\Api\Request\WorkflowService\StartWorkflowsRequest;
use Bitrix\Lists\Api\Service\WorkflowService;
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Result;

final class Starter
{
	private WorkflowService $workflowService;
	private int $currentUserId;
	private bool $isEnabled;
	private int $elementId = 0;
	private array $parameters = [];
	private array $changedFields = [];
	private ?int $timeToStart = null;

	private ?bool $hasTemplatesOnStartup = null;

	public function __construct(array $iBlockInfo, int $currentUserId)
	{
		$this->isEnabled = (
			Loader::includeModule('bizproc')
			&& \CLists::isBpFeatureEnabled($iBlockInfo['IBLOCK_TYPE_ID'])
			&& (isset($iBlockInfo['BIZPROC']) && $iBlockInfo['BIZPROC'] === 'Y') // $iBlockInfo['BIZPROC'] != 'N'
		);

		$this->workflowService = new WorkflowService($iBlockInfo);
		$this->currentUserId = max($currentUserId, 0);
	}

	public function setElementId(int $elementId): void
	{
		if ($elementId > 0)
		{
			$this->elementId = $elementId;
			$this->hasTemplatesOnStartup = null;
		}
	}

	public function setTimeToStart(?int $timeToStart = null): self
	{
		$this->timeToStart = $timeToStart;

		return $this;
	}

	public function setParameters(array $parameters): Result
	{
		$result = new Result();

		$parameterValuesResponse = $this->workflowService->getParameterValuesFromRequest($parameters, $this->elementId);
		if ($parameterValuesResponse->isSuccess())
		{
			$this->parameters = $parameterValuesResponse->getParameters();
			$this->hasTemplatesOnStartup = $this->elementId > 0 && $parameterValuesResponse->hasTemplatesOnStartup();
		}

		return (
			$result
				->addErrors($parameterValuesResponse->getErrors())
				->setData(['parameters' => $parameterValuesResponse->getParameters()])
		);
	}

	public function hasTemplatesOnStartup(): bool
	{
		if ($this->hasTemplatesOnStartup === null)
		{
			$this->hasTemplatesOnStartup = $this->workflowService->hasTemplatesOnStartup(
				$this->workflowService->getComplexDocumentId($this->elementId)
			);
		}

		return $this->hasTemplatesOnStartup;
	}

	public function setChangedFields(array $changedFields): void
	{
		$this->changedFields = $changedFields;
	}

	public function isEnabled(): bool
	{
		return $this->isEnabled;
	}

	public function isRunnable(int $createdBy): Result
	{
		$result = new Result();

		if (!$this->isEnabled())
		{
			return $result->addError(
				new Error(Loc::getMessage('LISTS_LIB_WORKFLOW_STARTER_BP_NOT_AVAILABLE') ?? '')
			);
		}

		$currentUserGroups = $this->getCurrentUserGroups($this->currentUserId > 0 && $this->currentUserId === $createdBy);
		if (!$this->workflowService->canUserWriteDocument($this->elementId, $this->currentUserId, $currentUserGroups))
		{
			return $result->addError(
				new Error(Loc::getMessage('LISTS_LIB_WORKFLOW_STARTER_USER_CANT_WRITE_DOCUMENT') ?? '')
			);
		}

		if (!$this->workflowService->isConstantsTuned())
		{
			return $result->addError(
				new Error(Loc::getMessage('LISTS_LIB_WORKFLOW_STARTER_CONSTANTS_NOT_CONFIGURED') ?? '')
			);
		}

		return $result;
	}

	private function getCurrentUserGroups(bool $isAuthor = false): array
	{
		$userGroups = $this->currentUserId ? \CUser::GetUserGroup($this->currentUserId) : [];
		if ($isAuthor && is_array($userGroups))
		{
			$userGroups[] = 'author';
		}

		return is_array($userGroups) ? $userGroups : [];
	}

	public function run(bool $isNewElement = false): Result
	{
		$result = new Result();

		$startWorkflowResponse = $this->workflowService->startWorkflows(
			new StartWorkflowsRequest(
				$this->elementId,
				$this->currentUserId,
				$this->parameters,
				!$isNewElement && $this->hasTemplatesOnStartup() ? $this->changedFields : [],
				$isNewElement,
				$this->timeToStart,
			)
		);

		return (
			$result
				->addErrors($startWorkflowResponse->getErrors())
				->setData(['workflowIds' => $startWorkflowResponse->getWorkflowIds()])
		);
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit