bitrix24 / b24phpsdk

Bitrix24 PHP SDK for REST API
MIT License
15 stars 4 forks source link

Add composite batch call support #14

Open mesilov opened 1 month ago

mesilov commented 1 month ago

Description

User feature requests

Read mode

within one entity, if more than 1 request is planned, then always a batch. If different entities, then different batches - each entity has its own batch. I understand that this way the developer has to think less, and the solution can be made faster

Several entities too. Right now the project: a Case is taken and then - a Contact, a Company and a Deal, possibly related to it. Then, perhaps, Contacts and a Company related to the received Deal will be added. Since it's all the same one hit - pull as much as possible

Example

$batch = new \Bitrix24\SDK\Core\Batch($core, $log);
$batch->addCommand('crm.deal.get', ['ID' => $dealId],'deal');
$batch->addCommand('crm.deal.productrows.get', ['ID' => $dealId],'products');
$batch->addCommand('user.current', [],'user');
$cdArr = $batch->getCompositeResultAsArray();

array(3) {
  ["deal"]=>
  array(40) {
    ["ID"]=> string(3) "713"
    ["TITLE"]=> string(29) "тестовая сделка"
     ...
  ["products"]=>
  array(2) {
    [0]=>
    array(22) { 
      ["ID"]=> string(3) "325"
      ["OWNER_ID"]=>  string(3) "713"
       ...
    }
  }
  ["user"]=>
  array(40) {
    ["ID"]=> string(1) "1"
    ["ACTIVE"]=> 'Y'
    ...
  }
}

Write mode

foreach ($this->serviceBuilder->getCRMScope()->deal()->batch->add($rawDeals) as $addDealResult) {
   $dealIdList[] = $addDealResult->getId();
}

via a generator? And how are the added transactions and their ids compared? i.e. if I add data via REST, and then in the local system I need to link the transaction id (for some reason) to each individual entity that I added, then how?

good question, I solve it like this: this is the developer's area of ​​responsibility, in the client code let him decide what he needs there. if we are talking about the connection of entities in two systems, then you should have a field by which the connection goes, some kind of UUID, well, actually you have: there is system A in which there is data and uuid you sent an array of transactions to B24 that have these uuid in the user field they returned their id (added) to you by id you selected and compared of course you can use the keys of the array with transactions as identifiers and pass them along, for example

I haven't tried your library, maybe you can implement the adding method in a different way, and this is additional "sugar" for a private case off the top of my head there are many options: allow you to set a request code and get a response/callback using it (with passing custom data/request to the method, along with the result)/return the request and response in an iterator

Example

No response