Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

376 add bizproc scope support in services #377

Merged
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7acaf7a
Add workflow services and update changelog
mesilov Mar 31, 2024
bca3649
Add Workflow service and associated classes
mesilov Mar 31, 2024
b23306f
Add workflow start methods and related classes
mesilov Apr 1, 2024
7cefd11
Add enum `DealSemanticStage` and update property types in `DealItemRe…
mesilov Apr 3, 2024
e752709
Merge branch 'refs/heads/371-publish-b24-php-sdk-beta-2' into 376-add…
mesilov Apr 11, 2024
acb3775
Add new specific workflow exceptions
mesilov Apr 20, 2024
7a74bcd
Add automation rule support for workflows
mesilov Apr 20, 2024
be9013c
Add functionality to handle Workflow Events
mesilov Apr 21, 2024
35d07bf
Update CHANGELOG.md for 2.0-beta.3 release
mesilov Apr 21, 2024
0be7858
Added new workflows and activities service functionalities
mesilov May 1, 2024
67f0abe
Update dependencies and enhance workflows in CHANGELOG
mesilov May 1, 2024
c90817a
Add workflow termination feature
mesilov May 1, 2024
7a18a3f
Add handling for 'access_denied' case in ErrorHandler
mesilov May 3, 2024
1f71b1a
Removed the integration.yml workflow
mesilov May 3, 2024
3ff8abf
Refactor Workflows services and add new features
mesilov May 3, 2024
1508d13
Add exception handling for empty updates and update service descriptions
mesilov May 4, 2024
ecb19e1
Add nesbot/carbon dependency
mesilov May 4, 2024
6a37629
Add workflow task service and related classes
mesilov May 4, 2024
5e5a7c4
Update PHPStan configuration and refactor Task service
mesilov May 5, 2024
2319b7c
Add support for completing workflow tasks
mesilov May 5, 2024
19feebe
Add Rector for static code analysis
mesilov May 23, 2024
0e2e38a
Refactor code for clarity and robustness
mesilov May 23, 2024
757a805
Add Rector to improve code quality and speed up releases
mesilov May 23, 2024
a46897b
Add new scope
mesilov May 23, 2024
fe37bee
Add workflow auth
mesilov May 24, 2024
0f9e84c
Fix type errors
mesilov May 24, 2024
248016c
Add IncomingRobotRequest.php and IncomingWorkflowRequest.php
mesilov May 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add automation rule support for workflows
This update introduces a new Robot service to the Workflows, which adds support for automation rules in the application. It includes functionalities for registration, deletion and updating of these rules, along with related result reporting features and work property enumeration.

Signed-off-by: mesilov <mesilov.maxim@gmail.com>
mesilov committed Apr 20, 2024
commit 7a74bcd3952ab4a3e4bd037c5c1d519001326232
18 changes: 18 additions & 0 deletions src/Services/Workflows/Common/WorkflowPropertyType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Workflows\Common;

enum WorkflowPropertyType: string
{
case bool = 'bool';
case date = 'date';
case datetime = 'datetime';
case double = 'double';
case int = 'int';
case select = 'select';
case string = 'string';
case text = 'text';
case user = 'user';
}
15 changes: 15 additions & 0 deletions src/Services/Workflows/Robot/Result/AddedRobotResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Workflows\Robot\Result;

use Bitrix24\SDK\Core\Result\AbstractResult;

class AddedRobotResult extends AbstractResult
{
public function isSuccess(): bool
{
return $this->getCoreResponse()->getResponseData()->getResult()[0];
}
}
15 changes: 15 additions & 0 deletions src/Services/Workflows/Robot/Result/UpdateRobotResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Workflows\Robot\Result;

use Bitrix24\SDK\Core\Result\AbstractResult;

class UpdateRobotResult extends AbstractResult
{
public function isSuccess(): bool
{
return $this->getCoreResponse()->getResponseData()->getResult()[0];
}
}
19 changes: 19 additions & 0 deletions src/Services/Workflows/Robot/Result/WorkflowRobotsResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Workflows\Robot\Result;

use Bitrix24\SDK\Core\Exceptions\BaseException;
use Bitrix24\SDK\Core\Result\AbstractResult;

class WorkflowRobotsResult extends AbstractResult
{
/**
* @throws BaseException
*/
public function getRobots(): array
{
return $this->getCoreResponse()->getResponseData()->getResult();
}
}
159 changes: 159 additions & 0 deletions src/Services/Workflows/Robot/Service/Robot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Workflows\Robot\Service;

use Bitrix24\SDK\Core\Contracts\CoreInterface;
use Bitrix24\SDK\Core\Exceptions\BaseException;
use Bitrix24\SDK\Core\Exceptions\TransportException;
use Bitrix24\SDK\Core\Result\DeletedItemResult;
use Bitrix24\SDK\Services\AbstractService;
use Bitrix24\SDK\Services\Workflows;
use Bitrix24\SDK\Services\Workflows\Robot\Result\AddedRobotResult;
use Bitrix24\SDK\Services\Workflows\Robot\Result\UpdateRobotResult;
use Bitrix24\SDK\Services\Workflows\Template\Service\Batch;
use Psr\Log\LoggerInterface;


class Robot extends AbstractService
{
public Batch $batch;

public function __construct(
Batch $batch,
CoreInterface $core,
LoggerInterface $log
)
{
parent::__construct($core, $log);
$this->batch = $batch;
}

/**
* Registers new automation rule.
*
* @param string $code
* @param string $handlerUrl
* @param int $b24AuthUserId
* @param array $localizedRobotName
* @param bool $isUseSubscription
* @param array $properties
* @param bool $isUsePlacement
* @param array $returnProperties
*
* @return AddedRobotResult
* @throws BaseException
* @throws TransportException
* @see https://training.bitrix24.com/rest_help/workflows/app_automation_rules/bizproc_robot_add.php
*/
public function add(
string $code,
string $handlerUrl,
int $b24AuthUserId,
array $localizedRobotName,
bool $isUseSubscription,
array $properties,
bool $isUsePlacement,
array $returnProperties
): Workflows\Robot\Result\AddedRobotResult
{
return new Workflows\Robot\Result\AddedRobotResult($this->core->call('bizproc.robot.add', [
'CODE' => $code,
'HANDLER' => $handlerUrl,
'AUTH_USER_ID' => $b24AuthUserId,
'NAME' => $localizedRobotName,
'USE_SUBSCRIPTION' => $isUseSubscription ? 'Y' : 'N',
'PROPERTIES' => $properties,
'USE_PLACEMENT' => $isUsePlacement ? 'Y' : 'N',
'RETURN_PROPERTIES' => $returnProperties
]));
}

/**
* This method returns list of automation rules, registered by the application.
*
* @throws BaseException
* @throws TransportException
* @see https://training.bitrix24.com/rest_help/workflows/app_automation_rules/bizproc_robot_list.php
*/
public function list(): Workflows\Robot\Result\WorkflowRobotsResult
{
return new Workflows\Robot\Result\WorkflowRobotsResult($this->core->call('bizproc.robot.list'));
}

/**
* This method deletes registered automation rule.
*
* @param string $robotCode
* @return DeletedItemResult
* @throws BaseException
* @throws TransportException
* @see https://training.bitrix24.com/rest_help/workflows/app_automation_rules/bizproc_robot_delete.php
*/
public function delete(string $robotCode): DeletedItemResult
{
return new DeletedItemResult(
$this->core->call('bizproc.robot.delete', [
'CODE' => $robotCode
]));
}

/**
* updates fields of automation rules
*
* @param string $code
* @param string|null $handlerUrl
* @param int|null $b24AuthUserId
* @param array|null $localizedRobotName
* @param bool $isUseSubscription
* @param array|null $properties
* @param bool $isUsePlacement
* @param array|null $returnProperties
* @return UpdateRobotResult
* @throws BaseException
* @throws TransportException
* @see https://training.bitrix24.com/rest_help/workflows/app_automation_rules/bizproc_robot_update.php
*/
public function update(
string $code,
?string $handlerUrl = null,
?int $b24AuthUserId = null,
?array $localizedRobotName = null,
?bool $isUseSubscription = null,
?array $properties = null,
?bool $isUsePlacement = null,
?array $returnProperties = null
): Workflows\Robot\Result\UpdateRobotResult
{
$fieldsToUpdate = [];
if ($handlerUrl !== null) {
$fieldsToUpdate['HANDLER'] = $handlerUrl;
}
if ($b24AuthUserId !== null) {
$fieldsToUpdate['AUTH_USER_ID'] = $b24AuthUserId;
}
if ($localizedRobotName !== null) {
$fieldsToUpdate['NAME'] = $localizedRobotName;
}
if ($isUseSubscription !== null) {
$fieldsToUpdate['USE_SUBSCRIPTION'] = $isUseSubscription ? 'Y' : 'N';
}
if ($properties !== null) {
$fieldsToUpdate['PROPERTIES'] = $properties;
}
if ($isUsePlacement !== null) {
$fieldsToUpdate['USE_PLACEMENT'] = $isUsePlacement ? 'Y' : 'N';
}
if ($returnProperties !== null) {
$fieldsToUpdate['RETURN_PROPERTIES'] = $returnProperties;
}

return new Workflows\Robot\Result\UpdateRobotResult($this->core->call(
'bizproc.robot.update',
[
'CODE' => $code,
'FIELDS' => $fieldsToUpdate
]));
}
}
13 changes: 13 additions & 0 deletions src/Services/Workflows/WorkflowsServiceBuilder.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,19 @@

class WorkflowsServiceBuilder extends AbstractServiceBuilder
{
public function robot(): Workflows\Robot\Service\Robot
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new Workflows\Robot\Service\Robot(
new Workflows\Template\Service\Batch($this->batch, $this->log),
$this->core,
$this->log
);
}

return $this->serviceCache[__METHOD__];
}

public function template(): Workflows\Template\Service\Template
{
if (!isset($this->serviceCache[__METHOD__])) {

Unchanged files with check annotations Beta

'bizproc.workflow.start',
[
'TEMPLATE_ID' => $bizProcTemplateId,
'DOCUMENT_ID' => $documentId,

Check failure on line 85 in src/Services/Workflows/Workflow/Service/Workflow.php

GitHub Actions / PHPStan (8.3, highest, ubuntu-latest)

Variable $documentId might not be defined.

Check failure on line 85 in src/Services/Workflows/Workflow/Service/Workflow.php

GitHub Actions / PHPStan (8.3, highest, ubuntu-latest)

Variable $documentId might not be defined.

Check failure on line 85 in src/Services/Workflows/Workflow/Service/Workflow.php

GitHub Actions / PHPStan (8.2, highest, ubuntu-latest)

Variable $documentId might not be defined.

Check failure on line 85 in src/Services/Workflows/Workflow/Service/Workflow.php

GitHub Actions / PHPStan (8.2, highest, ubuntu-latest)

Variable $documentId might not be defined.

Check failure on line 85 in src/Services/Workflows/Workflow/Service/Workflow.php

GitHub Actions / PHPStan (8.2, highest, windows-latest)

Variable $documentId might not be defined.

Check failure on line 85 in src/Services/Workflows/Workflow/Service/Workflow.php

GitHub Actions / PHPStan (8.3, highest, windows-latest)

Variable $documentId might not be defined.

Check failure on line 85 in src/Services/Workflows/Workflow/Service/Workflow.php

GitHub Actions / PHPStan (8.2, highest, windows-latest)

Variable $documentId might not be defined.

Check failure on line 85 in src/Services/Workflows/Workflow/Service/Workflow.php

GitHub Actions / PHPStan (8.3, highest, windows-latest)

Variable $documentId might not be defined.
'PARAMETERS' => $callParameters
]
));