Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
productsdelete.php
1<?php
2
4
9
15{
22 public function process($data = NULL, Timer $timer = NULL)
23 {
24 $apiHelper = new ApiHelper($this->exportId);
25
26 $productsFromVk = $apiHelper->getProductsFromVk($this->vkGroupId);
27 $productsMapped = Vk\Map::getMappedProducts($this->exportId);
28
29// remove from mapping products which not exist in VK
30 $productsMappedToRemove = array();
31 foreach ($productsMapped as $key => $productMapped)
32 {
33 if (!isset($productsFromVk[$productMapped["VK_ID"]]))
34 {
35 $productsMappedToRemove[] = array("VALUE_EXTERNAL" => $productMapped["VK_ID"]);
36 unset($productsMapped[$key]);
37 }
38 }
39// remove not exists in VK items
40 if (!empty($productsMappedToRemove))
41 Vk\Map::removeProductMapping($productsMappedToRemove, $this->exportId);
42
43// In delete procedure we not need http file upload.
44// It means that we can not limit max items by settings and using max possible count.
45 $productsMapped = array_chunk($productsMapped, Vk\Vk::MAX_EXECUTION_ITEMS); // max 25 items in execute()
46 foreach ($productsMapped as $chunk)
47 {
48 $resDelete = $this->executer->executeMarketProductDelete(array(
49 "owner_id" => $this->vkGroupId,
50 "data" => $chunk,
51 "count" => count($chunk),
52 ));
53
54 foreach ($resDelete as $res)
55 {
56 if ($res["flag_product_delete_result"])
57 $productsMappedToRemove[] = array("VALUE_EXTERNAL" => $res["VK_ID"]);
58 }
59
60 // remove success deleted items
61 if (!empty($productsMappedToRemove))
62 Vk\Map::removeProductMapping($productsMappedToRemove, $this->exportId);
63
64// abstract start position - only for continue export, not for rewind to position
65 if ($timer !== NULL && !$timer->check())
66 throw new TimeIsOverException("Timelimit for export is over", '1');
67 }
68
69// remove products from cache
70 $vkExportedData = new Vk\VkExportedData($this->exportId, 'PRODUCTS');
71 $vkExportedData->removeData();
72
73 return true;
74 }
75
76
77}