Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

$finder = Finder::create()
->in(__DIR__ . '/src/Infrastructure/Console/Commands/')
->in(__DIR__ . '/src/Services/CRM/Address/')
->in(__DIR__ . '/src/Services/CRM/Item/Service/')
->in(__DIR__ . '/src/Services/CRM/Contact/')
->in(__DIR__ . '/src/Services/CRM/Quote/')
Expand Down
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@
- `get` get localizations
- `fields` get localization fields
- `delete` delete currency, with batch calls support
- Added service `Services\CRM\Address\Service\Address` with support methods,
see [add crm.address REST methods](https://github.com/bitrix24/b24phpsdk/issues/138):
- `list` get item list
- `add` add new item, with batch calls support
- `delete` delete item, with batch calls support
- `update` update item, with batch calls support
- Added enum `Services\CRM\Enum\OwnerType`
- Developer experience: added make command `lint-all` for run all code linters step by step, [see details](https://github.com/bitrix24/b24phpsdk/issues/183)

### Fixed
Expand Down Expand Up @@ -173,8 +180,8 @@ work in progress
see [fix entity.item.* methods](https://github.com/bitrix24/b24phpsdk/issues/53):
- `get` get item, with batch calls support
- `add` add new item, with batch calls support
- `delete` delete item, with batch calls support
- `update` update item, with batch calls support
- `delete` delete item
- `update` update item
- Added service `Services\Entity\Service\Entity` with support methods,
see [fix entity.* methods](https://github.com/bitrix24/b24phpsdk/issues/53):
- `get` get entity
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ test-integration-scope-entity:
.PHONY: test-integration-scope-ai-admin
test-integration-scope-ai-admin:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_ai_admin

.PHONY: test-integration-scope-crm
test-integration-scope-crm:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_crm

.PHONY: integration_tests_scope_crm_address
integration_tests_scope_crm_address:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_crm_address

.PHONY: integration_tests_scope_crm_deal_details
integration_tests_scope_crm_deal_details:
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ parameters:
- tests/Integration/Services/IMOpenLines
- tests/Integration/Services/Main
- tests/Integration/Services/Placement
- tests/Integration/Services/CRM/Address
- tests/Integration/Services/CRM/Deal/Service/DealRecurringTest.php
- tests/Integration/Services/CRM/Lead/Service/LeadContactTest.php
- tests/Integration/Services/CRM/Item/Service/ItemDetailsConfigurationTest.php
Expand Down
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<testsuite name="integration_tests_scope_ai_admin">
<directory>./tests/Integration/Services/AI/</directory>
</testsuite>
<testsuite name="integration_tests_scope_crm">
<directory>./tests/Integration/Services/CRM/</directory>
</testsuite>
<testsuite name="integration_tests_scope_crm_address">
<directory>./tests/Integration/Services/CRM/Address/</directory>
</testsuite>
<testsuite name="integration_tests_scope_crm_deal_details">
<file>./tests/Integration/Services/CRM/Deal/Service/DealDetailsConfigurationTest.php</file>
</testsuite>
Expand Down
4 changes: 2 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
__DIR__ . '/tests/Integration/Services/IM',
__DIR__ . '/src/Services/IMOpenLines',
__DIR__ . '/tests/Integration/Services/IMOpenLines',
__DIR__ . '/src/Services/CRM/Automation',
__DIR__ . '/tests/Integration/Services/CRM/Automation',
__DIR__ . '/src/Services/CRM/Address',
__DIR__ . '/tests/Integration/Services/CRM/Address',
__DIR__ . '/src/Services/Main',
__DIR__ . '/tests/Integration/Services/Main',
__DIR__ . '/src/Services/Placement',
Expand Down
27 changes: 20 additions & 7 deletions src/Core/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,13 @@ public function deleteEntityItems(
'additionalParameters' => $additionalParameters,
]
);

$useFieldsInsteadOfId = $apiMethod === 'crm.address.delete';

try {
$this->clearCommands();
foreach ($entityItemId as $cnt => $itemId) {
if (!is_int($itemId)) {
if (!$useFieldsInsteadOfId && !is_int($itemId)) {
throw new InvalidArgumentException(
sprintf(
'invalid type «%s» of entity id «%s» at position %s, entity id must be integer type',
Expand All @@ -140,7 +142,8 @@ public function deleteEntityItems(
);
}

$parameters = ['ID' => $itemId];
$parameters = $useFieldsInsteadOfId ? ['fields' => $itemId] : ['ID' => $itemId];
// TODO: delete after migration to RestAPI v2
if ($apiMethod === 'entity.item.delete') {
$parameters = array_merge($parameters, $additionalParameters);
}
Expand Down Expand Up @@ -201,8 +204,11 @@ public function updateEntityItems(string $apiMethod, array $entityItems): Genera

try {
$this->clearCommands();

$useFieldsInsteadOfId = $apiMethod === 'crm.address.update';

foreach ($entityItems as $entityItemId => $entityItem) {
if (!is_int($entityItemId)) {
if (!$useFieldsInsteadOfId && !is_int($entityItemId)) {
throw new InvalidArgumentException(
sprintf(
'invalid type «%s» of entity id «%s», entity id must be integer type',
Expand All @@ -219,10 +225,17 @@ public function updateEntityItems(string $apiMethod, array $entityItems): Genera
);
}

$cmdArguments = [
'id' => $entityItemId,
'fields' => $entityItem['fields']
];
if ($useFieldsInsteadOfId) {
$cmdArguments = [
'fields' => $entityItem['fields']
];
} else {
$cmdArguments = [
'id' => $entityItemId,
'fields' => $entityItem['fields']
];
}

if (array_key_exists('params', $entityItem)) {
$cmdArguments['params'] = $entityItem['params'];
}
Expand Down
38 changes: 38 additions & 0 deletions src/Services/CRM/Address/Result/AddressItemResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Vadim Soluyanov <vadimsallee@gmail.com>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Address\Result;

use Bitrix24\SDK\Services\CRM\Common\Result\AbstractCrmItem;

/**
* Class AddressItemResult
*
* @property-read int $TYPE_ID
* @property-read int $ENTITY_TYPE_ID
* @property-read int $ENTITY_ID
* @property-read string|null $ADDRESS_1
* @property-read string|null $ADDRESS_2
* @property-read string|null $CITY
* @property-read string|null $POSTAL_CODE
* @property-read string|null $REGION
* @property-read string|null $PROVINCE
* @property-read string|null $COUNTRY
* @property-read string|null $COUNTRY_CODE
* @property-read int|null $LOC_ADDR_ID
* @property-read int|null $ANCHOR_TYPE_ID
* @property-read int|null $ANCHOR_ID
*/
class AddressItemResult extends AbstractCrmItem
{
}
33 changes: 33 additions & 0 deletions src/Services/CRM/Address/Result/AddressResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Vadim Soluyanov <vadimsallee@gmail.com>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/


declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Address\Result;

use Bitrix24\SDK\Core\Result\AbstractResult;

/**
* Class AddressResult
*
* @package Bitrix24\SDK\Services\CRM\Address\Result
*/
class AddressResult extends AbstractResult
{
/**
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
*/
public function address(): AddressItemResult
{
return new AddressItemResult($this->getCoreResponse()->getResponseData()->getResult());
}
}
40 changes: 40 additions & 0 deletions src/Services/CRM/Address/Result/AddressesResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Vadim Soluyanov <vadimsallee@gmail.com>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/


declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Address\Result;

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

/**
* Class AddressesResult
*
* @package Bitrix24\SDK\Services\CRM\Address\Result
*/
class AddressesResult extends AbstractResult
{
/**
* @return AddressItemResult[]
* @throws BaseException
*/
public function getAddresses(): array
{
$items = [];
foreach ($this->getCoreResponse()->getResponseData()->getResult() as $item) {
$items[] = new AddressItemResult($item);
}

return $items;
}
}
Loading