• Модуль: clouds
  • Путь к файлу: ~/bitrix/modules/clouds/classes/general/storage.php
  • Класс: CCloudStorage
  • Вызов: CCloudStorage::ResizeImageFileDelay
static function ResizeImageFileDelay(&$arDestinationSize, $sourceFile, $destinationFile, $arResizeParams)
{
	global $DB;
	$destinationFile = preg_replace("/^https?:/i", "", $destinationFile);
	$destinationFile = CCloudUtil::URLEncode($destinationFile, "UTF-8", true);
	$q = $DB->Query("
		select
			ID
			,ERROR_CODE
			,PARAMS
			,".$DB->DateToCharFunction("TIMESTAMP_X", "FULL")." TIMESTAMP_X
		from b_clouds_file_resize
		where TO_PATH = '".$DB->ForSql($destinationFile)."'
	");
	if ($resize = $q->Fetch())
	{
		if ($resize["ERROR_CODE"] < 10)
		{
			$arResizeParams = unserialize($resize["PARAMS"], ['allowed_classes' => false]);
			$id = $resize["ID"];
		} //Give it a try
		elseif (
			$resize["ERROR_CODE"] >= 10
			&& $resize["ERROR_CODE"] < 20
			&& (MakeTimeStamp($resize["TIMESTAMP_X"]) + 300/*5min*/) < (time() + CTimeZone::GetOffset())
		)
		{
			$DB->Query("
				UPDATE b_clouds_file_resize
				SET ERROR_CODE='1'
				WHERE ID=".$resize["ID"]."
			");
			$arResizeParams = unserialize($resize["PARAMS"], ['allowed_classes' => false]);
			$id = $resize["ID"];
		}
		else
		{
			return false;
		}
	}
	else
	{
		$id = 0;
	}

	$sourceImageWidth = $sourceFile["WIDTH"];
	$sourceImageHeight = $sourceFile["HEIGHT"];
	$arSize = $arResizeParams[0];
	$resizeType = $arResizeParams[1];
	$arWaterMark = $arResizeParams[2];
	$jpgQuality = $arResizeParams[3];
	$arFilters = $arResizeParams[4];
	$bNeedCreatePicture = false;
	$arSourceSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);
	$arDestinationSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);

	CFile::ScaleImage(
		$sourceImageWidth,
		$sourceImageHeight,
		$arSize,
		$resizeType,
		$bNeedCreatePicture,
		$arSourceSize,
		$arDestinationSize
	);
	$bNeedCreatePicture |= is_array($arWaterMark) && !empty($arWaterMark);
	$bNeedCreatePicture |= is_array($arFilters) && !empty($arFilters);

	if ($bNeedCreatePicture)
	{
		if ($id <= 0)
		{
			$arResizeParams["type"] = $sourceFile["CONTENT_TYPE"];
			$id = $DB->Add("b_clouds_file_resize", array(
				"~TIMESTAMP_X" => $DB->CurrentTimeFunction(),
				"ERROR_CODE" => "2",
				"PARAMS" => serialize($arResizeParams),
				"FROM_PATH" => CCloudUtil::URLEncode($sourceFile["SRC"], "UTF-8", true),
				"TO_PATH" => $destinationFile,
				"FILE_ID" => $sourceFile["ID"],
			));
		}

		return $id > 0;
	}
	else
	{
		return false;
	}
}