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