18 private static function getProductEntityCode($exportId)
20 return "VK_PRODUCTS_" . $exportId;
23 private static function getPhotoEntityCode($exportId)
25 return "VK_PHOTOS_" . $exportId;
28 private static function getAlbumEntityCode($exportId)
30 return "VK_ALBUMS_" . $exportId;
33 private static function getSectionsEntityCode($exportId)
35 return "VK_SECTIONS_" . $exportId;
38 private static function getGeneralCodePrefix()
44 private static function getProductEntityId($exportId)
46 $productEntCode = self::getProductEntityCode($exportId);
48 return self::getMapEntityId($productEntCode);
51 private static function getPhotoEntityId($exportId)
53 $photoEntCode = self::getPhotoEntityCode($exportId);
55 return self::getMapEntityId($photoEntCode);
59 private static function getAlbumEntityId($exportId)
61 $albumEntCode = self::getAlbumEntityCode($exportId);
63 return self::getMapEntityId($albumEntCode);
67 private static function getSectionsEntityId($exportId)
69 $sectionsEntCode = self::getSectionsEntityCode($exportId);
71 return self::getMapEntityId($sectionsEntCode);
77 $mapEntityCode = self::getProductEntityCode($exportId);
78 $mapEntityID = self::getMapEntityId($mapEntityCode);
80 return self::addEntityMapping($values, $mapEntityID);
85 $mapEntityCode = self::getProductEntityCode($exportId);
86 $mapEntityID = self::getMapEntityId($mapEntityCode);
88 return self::removeEntityMapping($values, $mapEntityID, $flagKeys);
93 $mapEntityCode = self::getProductEntityCode($exportId);
94 $mapEntityID = self::getMapEntityId($mapEntityCode);
96 return self::updateEntityMapping($values, $mapEntityID, $flagKeys);
102 $mapEntityCode = self::getPhotoEntityCode($exportId);
103 $mapEntityID = self::getMapEntityId($mapEntityCode);
105 return self::addEntityMapping($values, $mapEntityID);
110 $mapEntityCode = self::getPhotoEntityCode($exportId);
111 $mapEntityID = self::getMapEntityId($mapEntityCode);
113 return self::removeEntityMapping($values, $mapEntityID, $flagKeys);
118 $mapEntityCode = self::getPhotoEntityCode($exportId);
119 $mapEntityID = self::getMapEntityId($mapEntityCode);
121 return self::updateEntityMapping($values, $mapEntityID, $flagKeys);
127 $mapEntityCode = self::getAlbumEntityCode($exportId);
128 $mapEntityID = self::getMapEntityId($mapEntityCode);
130 return self::addEntityMapping($values, $mapEntityID);
135 $mapEntityCode = self::getAlbumEntityCode($exportId);
136 $mapEntityID = self::getMapEntityId($mapEntityCode);
138 return self::removeEntityMapping($values, $mapEntityID, $flagKeys);
143 $mapEntityCode = self::getAlbumEntityCode($exportId);
144 $mapEntityID = self::getMapEntityId($mapEntityCode);
146 return self::updateEntityMapping($values, $mapEntityID, $flagKeys);
152 $mapEntityCode = self::getSectionsEntityCode($exportId);
153 $mapEntityID = self::getMapEntityId($mapEntityCode);
155 return self::addEntityMapping($values, $mapEntityID);
160 $mapEntityCode = self::getSectionsEntityCode($exportId);
161 $mapEntityID = self::getMapEntityId($mapEntityCode);
163 return self::removeEntityMapping($values, $mapEntityID, $flagKeys);
168 $mapEntityCode = self::getSectionsEntityCode($exportId);
169 $mapEntityID = self::getMapEntityId($mapEntityCode);
171 return self::updateEntityMapping($values, $mapEntityID, $flagKeys);
182 private static function getMapEntityId($mapEntityCode)
188 "TRADING_PLATFORM_ID" => $vk->getId(),
189 "CODE" => $mapEntityCode,
192 $resMapEntity = MapEntityTable::getList(array(
196 if ($mapEntity = $resMapEntity->fetch())
198 $result = $mapEntity[
"ID"];
202 $resAdd = MapEntityTable::add($fields);
204 if ($resAdd->isSuccess())
205 $result = $resAdd->getId();
209 throw new SystemException(
"Can' t get map entity id for code: " . $mapEntityCode .
".");
223 private static function addEntityMapping($values, $mapEntityID)
227 foreach ($values as $item)
229 $item = array_change_key_case($item, CASE_UPPER);
231 "VALUE_EXTERNAL" => $item[
"VALUE_EXTERNAL"],
232 "VALUE_INTERNAL" => $item[
"VALUE_INTERNAL"],
233 "ENTITY_ID" => $mapEntityID,
237 $fields[
"PARAMS"] = $item[
"PARAMS"];
239 $addRes = MapTable::add($fields);
241 if (!$addRes->isSuccess() || !$result)
259 private static function updateEntityMapping($values, $mapEntityID, $flagKeys)
263 foreach ($values as $item)
265 $fields = array_change_key_case($item, CASE_UPPER);
266 $fields[
"ENTITY_ID"] = intval($mapEntityID);
267 $fields[
"VALUE_EXTERNAL"] = strval($item[
"VALUE_EXTERNAL"]);
268 $fields[
"VALUE_INTERNAL"] = strval($item[
"VALUE_INTERNAL"]);
269 $filterToId = $fields;
271 if ($flagKeys ==
"ONLY_INTERNAL")
272 unset($filterToId[
"VALUE_EXTERNAL"]);
273 if ($flagKeys ==
"ONLY_EXTERNAL")
274 unset($filterToId[
"VALUE_INTERNAL"]);
275 unset($filterToId[
"PARAMS"]);
278 $id = MapTable::getList(
280 "filter" => $filterToId,
281 "select" => array(
"ID"),
289 $upRes = MapTable::update($id, $fields);
290 if (!$upRes->isSuccess())
295 $addRes = MapTable::add($fields);
296 if (!$addRes->isSuccess())
317 private static function removeEntityMapping($values, $mapEntityID, $flagKey =
'')
321 foreach ($values as $item)
328 $item = array_change_key_case($item, CASE_UPPER);
330 if ($flagKey ==
"ONLY_INTERNAL")
331 unset($item[
"VALUE_EXTERNAL"]);
332 elseif ($flagKey ==
"ONLY_EXTERNAL")
333 unset($item["VALUE_INTERNAL"]);
335 $fields = array("ENTITY_ID" => $mapEntityID);
336 $fields = array_merge($fields, $item);
338 $id = MapTable::getList(array(
340 "select" => array("ID"),
347 $delRes = MapTable::delete($id[
"ID"]);
348 if (!$delRes->isSuccess() || !$result)
371 $albumEntityId = self::getAlbumEntityId($exportId);
373 $catRes = MapTable::getList(array(
375 'filter' => array(
'=ENTITY_ID' => $albumEntityId),
378 while ($album = $catRes->fetch())
379 $result[$album[
"VALUE_INTERNAL"]] = array(
380 "SECTION_ID" => $album[
"VALUE_INTERNAL"],
381 "ALBUM_VK_ID" => $album[
"VALUE_EXTERNAL"],
397 $productEntId = self::getProductEntityId($exportId);
399 $catRes = MapTable::getList(array(
401 'filter' => array(
'=ENTITY_ID' => $productEntId),
404 while ($product = $catRes->fetch())
405 $result[$product[
"VALUE_INTERNAL"]] = array(
406 "BX_ID" => $product[
"VALUE_INTERNAL"],
407 "VK_ID" => $product[
"VALUE_EXTERNAL"],
424 $catEntId = self::getSectionsEntityId($exportId);
426 $filter = array(
'=ENTITY_ID' => $catEntId);
428 $filter[
'=VALUE_INTERNAL'] = $sectionId;
431 $catRes = MapTable::getList(array(
435 while ($product = $catRes->fetch())
436 $result[$product[
"VALUE_INTERNAL"]] = array(
437 "BX_ID" => $product[
"VALUE_INTERNAL"],
438 "VK_ID" => $product[
"VALUE_EXTERNAL"],
439 "PARAMS" => $product[
"PARAMS"],
459 public static function checkMappingMatches(array $data, array $dataFromVk, $exportId, $type, $isAgressive)
465 $bxKey =
"SECTION_ID";
466 $vkKey =
"ALBUM_VK_ID";
467 $deleteMapMethod =
"removeAlbumMapping";
474 $deleteMapMethod =
"removeProductMapping";
489 $dataMappedToRemove = array();
490 foreach ($data as &$item)
492 $itemMapped = $dataFromMapping[$item[$bxKey]];
493 if (isset($itemMapped))
495 if (isset($dataFromVk[$itemMapped[$vkKey]]))
500 $item[$vkKey] = $dataFromMapping[$item[$bxKey]][$vkKey];
501 $item[
"FLAG_EDIT"] =
true;
506 unset($data[$item[$bxKey]]);
513 $item[
"FLAG_EDIT"] =
false;
514 $dataMappedToRemove[] = array(
"VALUE_EXTERNAL" => $itemMapped[$vkKey]);
519 $item[
"FLAG_EDIT"] =
false;
523 if (!empty($dataMappedToRemove))
524 self::$deleteMapMethod($dataMappedToRemove, $exportId);
540 $resEntityIds = MapEntityTable::getList(array(
541 "filter" => array(
'%=CODE' => self::getGeneralCodePrefix() .
'%'),
543 $entityIds = array();
544 while ($entityId = $resEntityIds->fetch())
545 $entityIds[] = $entityId[
'ID'];
548 foreach ($entityIds as $entityId)
549 MapEntityTable::delete($entityId);
553 $resMapIds = MapTable::getList(array(
554 "filter" => array(
'=ENTITY_ID' => $entityIds),
557 while ($mapId = $resMapIds->fetch())
558 $mapIds[] = $mapId[
'ID'];
561 foreach ($mapIds as $mapId)
562 MapTable::delete($mapId);
if(!function_exists(__NAMESPACE__.'\\___1034172934'))