• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/tradingplatform/vk/api/photouploader.php
  • Класс: BitrixSaleTradingPlatformVkApiPhotoUploader
  • Вызов: PhotoUploader::upload
public function upload($data)
{
//		todo: this is a little kostyl. In cool variant we must separately do http-upload,
//		todo: and photo save run through execute method
//		todo: but now VK can't run savePhotoMethod through execute. Sadness ((

//		PARAMS set
	$photoSaveResults = array();
	

//		PROCESSED
	foreach ($data as $item)
	{
//			check EXISTING photo
		if (!array_key_exists($this->params['keyPhotoBx'], $item) || empty($item[$this->params['keyPhotoBx']]))
		{
			continue;
		}

//			GET upload server by type
		$getServerParams = array("group_id" => str_replace("-", "", $this->vkGroupId));
		if ($this->type == 'PRODUCT_MAIN_PHOTO')
		{
			$getServerParams += self::setUploadServerMainPhotoParams($item[$this->params['keyPhotoBx']]);
		}
		
		$uploadServer = $this->api->run($this->params['uploadServerMethod'], $getServerParams);
//			todo: may be this error in upload server response
		$this->logger->addLog("Get photo upload server", [
			'PARAMS' => $getServerParams,
			'RESULT' => $uploadServer,
		]);
		$uploadServer = $uploadServer["upload_url"];


//			UPLOAD photo by http
		$this->logger->addLog("Upload photo HTTP before", array(
			"UPLOAD_TYPE" => $this->type,
			"ITEM" => array_key_exists("BX_ID", $item) ?
				$item["BX_ID"] . ': ' . $item["NAME"] :
				$item["SECTION_ID"] . ': ' . $item["TITLE"],
			"PHOTO_BX_ID" => array_key_exists("PHOTO_MAIN_BX_ID",
				$item) ? $item["PHOTO_MAIN_BX_ID"] : $item["PHOTO_BX_ID"],
			"PHOTO_URL" => array_key_exists("PHOTO_MAIN_URL", $item) ? $item["PHOTO_MAIN_URL"] : $item["PHOTO_URL"],
			"PHOTOS" => $item["PHOTOS"]    //only for products
		));
		$uploadHttpResult = $this->uploadHttp($item, $uploadServer);
//			if not response - was be ERROR in http upload. SKIP saving
		if($uploadHttpResult === false)
		{
			if(!$photoSaveResults['errors'])
			{
				$photoSaveResults['errors'] = [];
			}
			$photoSaveResults['errors'][] = $item[$this->params['keyReference']];
			continue;
		}
		
		$savePhotoResult = $this->savePhoto($uploadHttpResult);
//			RESULT
		$photoSaveResults[$item[$this->params['keyReference']]] = array(
			$this->params['keyReference'] => $item[$this->params['keyReference']],
			$this->params['keyPhotoVk'] => $savePhotoResult[0]["id"],
		);
//			todo: photo mapping. po odnomu, navernoe, ved timer
	}
	
	return $photoSaveResults;
}