From 6f31b6b50a91d896c65c3f17b1d84b546b2f050a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A5=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Sun, 19 Mar 2023 11:32:35 +0300 Subject: [PATCH 1/8] =?UTF-8?q?-=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=201=20=D1=87=D0=B0=D1=81=D1=82=D1=8C=20=D0=B3=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=82=D0=B0=D0=BA=D1=82=D0=BE=D0=B2=20=D1=81=20=D0=B4=D0=B2?= =?UTF-8?q?=D1=83=D0=BC=D1=8F=20=D0=B2=D0=B8=D0=B4=D0=B0=D0=BC=D0=B8=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D0=B5=D1=84=D0=BE=D0=BD=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OperatingTimingTest.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/Integration/OperatingTimingTest/OperatingTimingTest.php diff --git a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php new file mode 100644 index 00000000..60cf7dbe --- /dev/null +++ b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php @@ -0,0 +1,70 @@ + sprintf('first_%s', time()), + 'SECOND' => sprintf('second_%s', time()), + 'PHONE' => [ + [ + 'VALUE' => $phoneNumberWork, + 'VALUE_TYPE' => 'WORK' + ], + [ + 'VALUE' => $phoneNumberHome, + 'VALUE_TYPE' => 'HOME' + ] + ] + ]; + + } + foreach ($masContacts as $contact){ + var_dump($contact); + $contactId[] = $this->contactService->add($contact)->getId(); + foreach ($contactId as $id){ + $contactUpdate= $this->contactService->update($id,['PHONE'[0] => '']); + } + + self::assertGreaterThanOrEqual(1,$contactId); + } + var_dump($contactId); + + + } + + public function setUp(): void + { + $this->contactService = Fabric::getServiceBuilder()->getCRMScope()->contact(); + } +} \ No newline at end of file From 9009ce586b1ecde48d8e6d71c4d74079bce6a012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A5=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Wed, 22 Mar 2023 16:55:23 +0300 Subject: [PATCH 2/8] =?UTF-8?q?-=20=D0=90=D0=BF=D0=B4=D0=B5=D0=B9=D1=82=20?= =?UTF-8?q?=D0=B1=D0=B5=D0=B7=20=D0=B1=D0=B0=D1=82=D1=87=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OperatingTimingTest.php | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php index 60cf7dbe..2a676b40 100644 --- a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php +++ b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php @@ -4,6 +4,7 @@ namespace Bitrix24\SDK\Tests\Integration\OperatingTimingTest; +use Bitrix24\SDK\Core\Batch; use Bitrix24\SDK\Core\Exceptions\BaseException; use Bitrix24\SDK\Core\Exceptions\TransportException; use Bitrix24\SDK\Services\CRM\Contact\Service\Contact; @@ -19,52 +20,51 @@ class OperatingTimingTest extends TestCase { protected Contact $contactService; + private Batch $batch; /** * @throws \Bitrix24\SDK\Core\Exceptions\TransportException * @throws \Bitrix24\SDK\Core\Exceptions\BaseException */ - public function testOperatingTiming() + public function testOperatingTiming(): void { - $PhoneNumWorkMas = []; - $PhoneNumHomeMas = []; $masContacts = []; - for($i=0; $i<5; $i++){ + for ($i = 0; $i < 5; $i++) { $phoneNumberWork = sprintf('+7%s', time()); $phoneNumberHome = sprintf('%s', microtime()); - $phoneNumberHome = implode("-",str_split(substr($phoneNumberHome,2,-13),2)); + $phoneNumberHome = implode("-", str_split(substr($phoneNumberHome, 2, -13), 2)); $masContacts[] = [ - 'NAME' => sprintf('first_%s', time()), - 'SECOND' => sprintf('second_%s', time()), - 'PHONE' => [ - [ - 'VALUE' => $phoneNumberWork, - 'VALUE_TYPE' => 'WORK' + 'fields' => [ + 'NAME' => sprintf('first_%s', time()), + 'SECOND' => sprintf('second_%s', time()), + 'PHONE' => [ + [ + 'VALUE' => $phoneNumberWork, + 'VALUE_TYPE' => 'WORK' + ], + [ + 'VALUE' => $phoneNumberHome, + 'VALUE_TYPE' => 'HOME' + ] ], - [ - 'VALUE' => $phoneNumberHome, - 'VALUE_TYPE' => 'HOME' - ] ] ]; } - foreach ($masContacts as $contact){ - var_dump($contact); - $contactId[] = $this->contactService->add($contact)->getId(); - foreach ($contactId as $id){ - $contactUpdate= $this->contactService->update($id,['PHONE'[0] => '']); - } - - self::assertGreaterThanOrEqual(1,$contactId); + $contactsIdList = []; + foreach ($this->batch->addEntityItems('crm.contact.add', $masContacts) as $addContactResult) { + $contactsIdList[] = $addContactResult->getResult(); } - var_dump($contactId); - - + foreach ($contactsIdList as $contactId) { + $contactPhoneId = $this->contactService->get($contactId[0])->contact()->PHONE[0]['ID']; + $contactUpdate = $this->contactService->update((int)$contactId[0],['PHONE' => [['ID' => $contactPhoneId, 'VALUE' => ""]]],[ "REGISTER_SONET_EVENT" => "Y"]); + } + $this->assertCount(5, $contactsIdList); } public function setUp(): void { + $this->batch = Fabric::getBatchService(); $this->contactService = Fabric::getServiceBuilder()->getCRMScope()->contact(); } } \ No newline at end of file From 0d4b2fdcd9ae4caff2344ddb5c5cf7d121cd17d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A5=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Wed, 22 Mar 2023 17:51:00 +0300 Subject: [PATCH 3/8] =?UTF-8?q?-=20=D0=A2=D0=B5=D1=81=D1=82=20=D0=BD=D0=B0?= =?UTF-8?q?=2010=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Integration/OperatingTimingTest/OperatingTimingTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php index 2a676b40..1e35c665 100644 --- a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php +++ b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php @@ -29,7 +29,7 @@ class OperatingTimingTest extends TestCase public function testOperatingTiming(): void { $masContacts = []; - for ($i = 0; $i < 5; $i++) { + for ($i = 0; $i < 10000; $i++) { $phoneNumberWork = sprintf('+7%s', time()); $phoneNumberHome = sprintf('%s', microtime()); $phoneNumberHome = implode("-", str_split(substr($phoneNumberHome, 2, -13), 2)); From f3699426d2c75aebd80a766cf508da2e411dab5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A5=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Thu, 23 Mar 2023 17:43:13 +0300 Subject: [PATCH 4/8] =?UTF-8?q?-=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=B3?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85=20!!!=20-=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=87=D0=B0=D1=81=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=B4=D0=B0=20=D0=B2=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B0=D0=BA=D1=82=D0=BE=D0=B2=20?= =?UTF-8?q?=D1=81=20=D0=BF=D0=BE=D0=BC=D0=BE=D1=89=D1=8C=D1=8E=20=D0=B1?= =?UTF-8?q?=D0=B0=D1=82=D1=87=D0=B0=20=D0=B8=20=D0=BC=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0=20list.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OperatingTimingTest.php | 26 ++++++++++++------- .../CRM/Contacts/GenerateContactsCommand.php | 5 ++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php index 1e35c665..88c1dc06 100644 --- a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php +++ b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php @@ -5,10 +5,8 @@ namespace Bitrix24\SDK\Tests\Integration\OperatingTimingTest; use Bitrix24\SDK\Core\Batch; -use Bitrix24\SDK\Core\Exceptions\BaseException; -use Bitrix24\SDK\Core\Exceptions\TransportException; + use Bitrix24\SDK\Services\CRM\Contact\Service\Contact; -use Bitrix24\SDK\Services\ServiceBuilder; use Bitrix24\SDK\Tests\Integration\Fabric; use PHPUnit\Framework\TestCase; @@ -28,7 +26,7 @@ class OperatingTimingTest extends TestCase */ public function testOperatingTiming(): void { - $masContacts = []; + /* $masContacts = []; for ($i = 0; $i < 10000; $i++) { $phoneNumberWork = sprintf('+7%s', time()); $phoneNumberHome = sprintf('%s', microtime()); @@ -50,16 +48,24 @@ public function testOperatingTiming(): void ] ]; - } - $contactsIdList = []; + }*/ + /* $contactsIdList = []; foreach ($this->batch->addEntityItems('crm.contact.add', $masContacts) as $addContactResult) { $contactsIdList[] = $addContactResult->getResult(); + }*/ + $cnt = 0; + foreach ($this->contactService->batch->list([], ['>ID' => '103575'], ['ID','PHONE'], 5) as $contactList) { + $cnt++; + $contactListId[] = $contactList->ID; + $contactListPhone[] = $contactList->PHONE; + } - foreach ($contactsIdList as $contactId) { - $contactPhoneId = $this->contactService->get($contactId[0])->contact()->PHONE[0]['ID']; - $contactUpdate = $this->contactService->update((int)$contactId[0],['PHONE' => [['ID' => $contactPhoneId, 'VALUE' => ""]]],[ "REGISTER_SONET_EVENT" => "Y"]); + foreach ($contactListId as $contactId) { + $contactPhoneId = $this->contactService->get($contactId)->contact()->PHONE[0]['ID']; + $contactUpdate = $this->contactService->update((int)$contactId,['PHONE' => [['ID' => $contactPhoneId, 'VALUE' => ""]]],[ "REGISTER_SONET_EVENT" => "Y"]); } - $this->assertCount(5, $contactsIdList); + self::assertGreaterThanOrEqual(5, $contactListId); + } public function setUp(): void diff --git a/tools/DemoDataGenerators/CRM/Contacts/GenerateContactsCommand.php b/tools/DemoDataGenerators/CRM/Contacts/GenerateContactsCommand.php index baaa96b4..c983863f 100644 --- a/tools/DemoDataGenerators/CRM/Contacts/GenerateContactsCommand.php +++ b/tools/DemoDataGenerators/CRM/Contacts/GenerateContactsCommand.php @@ -199,10 +199,11 @@ protected function generateContacts(int $contactsCount): array 'SECOND_NAME' => sprintf('second_%s', $i), 'PHONE' => [ ['VALUE' => sprintf('+7978%s', random_int(1000000, 9999999)), 'VALUE_TYPE' => 'MOBILE'], + ['VALUE' => implode("-", str_split(substr( sprintf('%s', microtime()), 2, -13), 2))], ], - 'EMAIL' => [ + /* 'EMAIL' => [ ['VALUE' => sprintf('test-%s@gmail.com', random_int(1000000, 9999999)), 'VALUE_TYPE' => 'WORK'], - ], + ],*/ ]; } From fe616ece0c5eb4282ef1d816d30a6f7128d9d28f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A5=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Thu, 23 Mar 2023 17:43:13 +0300 Subject: [PATCH 5/8] =?UTF-8?q?-=20=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BA=D1=80=D1=83=D1=87=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BD=D0=B0=D1=88=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D0=B0!=20-=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=87=D0=B0=D1=81=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=B4=D0=B0=20=D0=B2=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B0=D0=BA=D1=82=D0=BE=D0=B2=20?= =?UTF-8?q?=D1=81=20=D0=BF=D0=BE=D0=BC=D0=BE=D1=89=D1=8C=D1=8E=20=D0=B1?= =?UTF-8?q?=D0=B0=D1=82=D1=87=D0=B0=20=D0=B8=20=D0=BC=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0=20list.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OperatingTimingTest.php | 26 ++++++++++++------- .../CRM/Contacts/GenerateContactsCommand.php | 5 ++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php index 1e35c665..88c1dc06 100644 --- a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php +++ b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php @@ -5,10 +5,8 @@ namespace Bitrix24\SDK\Tests\Integration\OperatingTimingTest; use Bitrix24\SDK\Core\Batch; -use Bitrix24\SDK\Core\Exceptions\BaseException; -use Bitrix24\SDK\Core\Exceptions\TransportException; + use Bitrix24\SDK\Services\CRM\Contact\Service\Contact; -use Bitrix24\SDK\Services\ServiceBuilder; use Bitrix24\SDK\Tests\Integration\Fabric; use PHPUnit\Framework\TestCase; @@ -28,7 +26,7 @@ class OperatingTimingTest extends TestCase */ public function testOperatingTiming(): void { - $masContacts = []; + /* $masContacts = []; for ($i = 0; $i < 10000; $i++) { $phoneNumberWork = sprintf('+7%s', time()); $phoneNumberHome = sprintf('%s', microtime()); @@ -50,16 +48,24 @@ public function testOperatingTiming(): void ] ]; - } - $contactsIdList = []; + }*/ + /* $contactsIdList = []; foreach ($this->batch->addEntityItems('crm.contact.add', $masContacts) as $addContactResult) { $contactsIdList[] = $addContactResult->getResult(); + }*/ + $cnt = 0; + foreach ($this->contactService->batch->list([], ['>ID' => '103575'], ['ID','PHONE'], 5) as $contactList) { + $cnt++; + $contactListId[] = $contactList->ID; + $contactListPhone[] = $contactList->PHONE; + } - foreach ($contactsIdList as $contactId) { - $contactPhoneId = $this->contactService->get($contactId[0])->contact()->PHONE[0]['ID']; - $contactUpdate = $this->contactService->update((int)$contactId[0],['PHONE' => [['ID' => $contactPhoneId, 'VALUE' => ""]]],[ "REGISTER_SONET_EVENT" => "Y"]); + foreach ($contactListId as $contactId) { + $contactPhoneId = $this->contactService->get($contactId)->contact()->PHONE[0]['ID']; + $contactUpdate = $this->contactService->update((int)$contactId,['PHONE' => [['ID' => $contactPhoneId, 'VALUE' => ""]]],[ "REGISTER_SONET_EVENT" => "Y"]); } - $this->assertCount(5, $contactsIdList); + self::assertGreaterThanOrEqual(5, $contactListId); + } public function setUp(): void diff --git a/tools/DemoDataGenerators/CRM/Contacts/GenerateContactsCommand.php b/tools/DemoDataGenerators/CRM/Contacts/GenerateContactsCommand.php index baaa96b4..c983863f 100644 --- a/tools/DemoDataGenerators/CRM/Contacts/GenerateContactsCommand.php +++ b/tools/DemoDataGenerators/CRM/Contacts/GenerateContactsCommand.php @@ -199,10 +199,11 @@ protected function generateContacts(int $contactsCount): array 'SECOND_NAME' => sprintf('second_%s', $i), 'PHONE' => [ ['VALUE' => sprintf('+7978%s', random_int(1000000, 9999999)), 'VALUE_TYPE' => 'MOBILE'], + ['VALUE' => implode("-", str_split(substr( sprintf('%s', microtime()), 2, -13), 2))], ], - 'EMAIL' => [ + /* 'EMAIL' => [ ['VALUE' => sprintf('test-%s@gmail.com', random_int(1000000, 9999999)), 'VALUE_TYPE' => 'WORK'], - ], + ],*/ ]; } From eacb965c50871e74e478439f8039a138042f8121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A5=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Thu, 23 Mar 2023 20:04:35 +0300 Subject: [PATCH 6/8] =?UTF-8?q?-=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20update=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20batch=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D1=8E=D1=89=D0=B5=D0=B3=D0=BE=20=D1=81=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=82=D0=B0=D0=BA=D1=82=D0=B0=D0=BC=D0=B8.=20-=20=D0=92=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=87=D0=B0=D1=81=D1=82=D1=8C=20=D1=81=20?= =?UTF-8?q?update=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D1=8E?= =?UTF-8?q?=D1=89=D0=B0=D1=8F=20=D0=B1=D0=B0=D1=82=D1=87.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Services/CRM/Contact/Service/Batch.php | 22 +++++++++ .../OperatingTimingTest.php | 47 +++++-------------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/Services/CRM/Contact/Service/Batch.php b/src/Services/CRM/Contact/Service/Batch.php index 696720a2..02cfec3f 100644 --- a/src/Services/CRM/Contact/Service/Batch.php +++ b/src/Services/CRM/Contact/Service/Batch.php @@ -7,6 +7,7 @@ use Bitrix24\SDK\Core\Exceptions\BaseException; use Bitrix24\SDK\Core\Result\AddedItemBatchResult; use Bitrix24\SDK\Core\Result\DeletedItemBatchResult; +use Bitrix24\SDK\Core\Result\UpdatedItemBatchResult; use Bitrix24\SDK\Services\AbstractBatchService; use Bitrix24\SDK\Services\CRM\Contact\Result\ContactItemResult; use Generator; @@ -224,4 +225,25 @@ public function delete(array $contactId): Generator yield $key => new DeletedItemBatchResult($item); } } + + /** + * Update contact + * + * Update elements in array with structure + * element_id => [ // deal id + * 'fields' => [], // deal fields to update + * 'params' => [] + * ] + * + * @param array $entityItems + * + * @return \Generator + * @throws \Bitrix24\SDK\Core\Exceptions\BaseException + */ + public function update(array $entityItems): Generator + { + foreach ($this->batch->updateEntityItems('crm.contact.update', $entityItems) as $key => $item) { + yield $key => new UpdatedItemBatchResult($item); + } + } } \ No newline at end of file diff --git a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php index 88c1dc06..fb928de6 100644 --- a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php +++ b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php @@ -3,9 +3,7 @@ declare(strict_types=1); namespace Bitrix24\SDK\Tests\Integration\OperatingTimingTest; - use Bitrix24\SDK\Core\Batch; - use Bitrix24\SDK\Services\CRM\Contact\Service\Contact; use Bitrix24\SDK\Tests\Integration\Fabric; use PHPUnit\Framework\TestCase; @@ -18,7 +16,7 @@ class OperatingTimingTest extends TestCase { protected Contact $contactService; - private Batch $batch; + protected Batch $batch; /** * @throws \Bitrix24\SDK\Core\Exceptions\TransportException @@ -26,44 +24,23 @@ class OperatingTimingTest extends TestCase */ public function testOperatingTiming(): void { - /* $masContacts = []; - for ($i = 0; $i < 10000; $i++) { - $phoneNumberWork = sprintf('+7%s', time()); - $phoneNumberHome = sprintf('%s', microtime()); - $phoneNumberHome = implode("-", str_split(substr($phoneNumberHome, 2, -13), 2)); - $masContacts[] = [ - 'fields' => [ - 'NAME' => sprintf('first_%s', time()), - 'SECOND' => sprintf('second_%s', time()), - 'PHONE' => [ - [ - 'VALUE' => $phoneNumberWork, - 'VALUE_TYPE' => 'WORK' - ], - [ - 'VALUE' => $phoneNumberHome, - 'VALUE_TYPE' => 'HOME' - ] - ], - ] - ]; - }*/ - /* $contactsIdList = []; - foreach ($this->batch->addEntityItems('crm.contact.add', $masContacts) as $addContactResult) { - $contactsIdList[] = $addContactResult->getResult(); - }*/ $cnt = 0; - foreach ($this->contactService->batch->list([], ['>ID' => '103575'], ['ID','PHONE'], 5) as $contactList) { + $contactsToUpdate = []; + foreach ($this->contactService->batch->list([], ['>ID' => '103595'], ['ID','PHONE'], 30000) as $contactList) { $cnt++; + $contactsToUpdate[$contactList->ID] = [ + 'fields' => [ + 'PHONE' => [['ID' =>$contactList->PHONE[0]['ID']]] + ], + 'params' => [], + ]; $contactListId[] = $contactList->ID; - $contactListPhone[] = $contactList->PHONE; - } - foreach ($contactListId as $contactId) { - $contactPhoneId = $this->contactService->get($contactId)->contact()->PHONE[0]['ID']; - $contactUpdate = $this->contactService->update((int)$contactId,['PHONE' => [['ID' => $contactPhoneId, 'VALUE' => ""]]],[ "REGISTER_SONET_EVENT" => "Y"]); + foreach ($this->contactService->batch->update($contactsToUpdate) as $dealUpdateResult) { + $this->assertTrue($dealUpdateResult->isSuccess()); } + self::assertGreaterThanOrEqual(5, $contactListId); } From 61b2d364238172947aa5b687af2003a395f5112a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A5=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Sat, 25 Mar 2023 01:00:25 +0300 Subject: [PATCH 7/8] =?UTF-8?q?-=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=BF=D0=B5=D1=87=D0=B0=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B2=20=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BA=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Services/CRM/Contact/Service/Batch.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/CRM/Contact/Service/Batch.php b/src/Services/CRM/Contact/Service/Batch.php index 02cfec3f..e75165d3 100644 --- a/src/Services/CRM/Contact/Service/Batch.php +++ b/src/Services/CRM/Contact/Service/Batch.php @@ -230,8 +230,8 @@ public function delete(array $contactId): Generator * Update contact * * Update elements in array with structure - * element_id => [ // deal id - * 'fields' => [], // deal fields to update + * element_id => [ // contact id + * 'fields' => [], // contact fields to update * 'params' => [] * ] * From a966704cf296e1f3b4c808ec50468a9302dba3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A5=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Mon, 3 Apr 2023 17:18:44 +0300 Subject: [PATCH 8/8] =?UTF-8?q?-=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=D0=B0=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=81=D1=83=D0=BC=D0=BC=D0=B0=D1=80=D0=BD=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20operating=20=D0=B2=D0=BE=20=D0=B2=D1=80=D0=B5=D0=BC=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OperatingTimingTest/OperatingTimingTest.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php index fb928de6..d83e6ea3 100644 --- a/tests/Integration/OperatingTimingTest/OperatingTimingTest.php +++ b/tests/Integration/OperatingTimingTest/OperatingTimingTest.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Bitrix24\SDK\Tests\Integration\OperatingTimingTest; + use Bitrix24\SDK\Core\Batch; use Bitrix24\SDK\Services\CRM\Contact\Service\Contact; use Bitrix24\SDK\Tests\Integration\Fabric; @@ -25,21 +26,26 @@ class OperatingTimingTest extends TestCase public function testOperatingTiming(): void { - $cnt = 0; + $timeStart = microtime(true); $contactsToUpdate = []; - foreach ($this->contactService->batch->list([], ['>ID' => '103595'], ['ID','PHONE'], 30000) as $contactList) { - $cnt++; + foreach ($this->contactService->batch->list([], ['>ID' => '12'], ['ID', 'PHONE'], 30000) as $contactList) { $contactsToUpdate[$contactList->ID] = [ 'fields' => [ - 'PHONE' => [['ID' =>$contactList->PHONE[0]['ID']]] + 'PHONE' => [['ID' => $contactList->PHONE[0]['ID']]] ], 'params' => [], ]; $contactListId[] = $contactList->ID; } foreach ($this->contactService->batch->update($contactsToUpdate) as $dealUpdateResult) { - $this->assertTrue($dealUpdateResult->isSuccess()); + $logOperating[] = $dealUpdateResult->getResponseData()->getTime()->getOperating(); + $logOperatingResetAt = $dealUpdateResult->getResponseData()->getTime()->getOperatingResetAt(); + $sumOperating = array_sum($logOperating); + echo "summa operating: " . $sumOperating . PHP_EOL; + echo "operating rest at: " . $logOperatingResetAt . PHP_EOL; } + $timeEnd = microtime(true); + echo sprintf('batch query duration: %s seconds', round($timeEnd - $timeStart, 2)) . PHP_EOL; self::assertGreaterThanOrEqual(5, $contactListId);