• Модуль: clouds
  • Путь к файлу: ~/bitrix/modules/clouds/classes/general/storage_service_amazon.php
  • Класс: CCloudStorageService_AmazonS3
  • Вызов: CCloudStorageService_AmazonS3::CreateBucket
function CreateBucket($arBucket)
{
	global $APPLICATION;

	$arFiles = $this->ListFiles($arBucket, '/', false, 1);
	if(is_array($arFiles))
		return true;

	// The bucket already exists and user has specified wrong location
	if (
		$this->status == 301
		&& $arBucket["LOCATION"] != ""
		&& $this->GetLastRequestHeader('x-amz-bucket-region') != ''
		&& $this->GetLastRequestHeader('x-amz-bucket-region') != $arBucket["LOCATION"]
	)
	{
		return false;
	}

	if($arBucket["LOCATION"] != "")
		$content =
			''.
			''.$arBucket["LOCATION"].''.
			'';
	else
		$content = '';

	$this->SetLocation($arBucket["LOCATION"]);
	$response = $this->SendRequest(
		$arBucket["SETTINGS"],
		'PUT',
		$arBucket["BUCKET"],
		'/',
		'',
		$content,
		['x-amz-object-ownership' => 'ObjectWriter']
	);

	if($this->status == 409/*Already exists*/)
	{
		$APPLICATION->ResetException();
		return true;
	}
	elseif ($this->status == 200)
	{
		$response = $this->SendRequest(
			$arBucket["SETTINGS"],
			'DELETE',
			$arBucket["BUCKET"],
			'/',
			'?publicAccessBlock='
		);
		if ($this->status == 204)
		{
			return true;
		}

		if (defined("BX_CLOUDS_ERROR_DEBUG"))
		{
			AddMessage2Log($this);
		}
		return false;
	}
	elseif (is_array($response))
	{
		return true;
	}
	else
	{
		if (defined("BX_CLOUDS_ERROR_DEBUG"))
		{
			AddMessage2Log($this);
		}
		return false;
	}
}