• Модуль: clouds
  • Путь к файлу: ~/bitrix/modules/clouds/classes/general/storage_bucket.php
  • Класс: CCloudStorageBucket
  • Вызов: CCloudStorageBucket::Delete
function Delete()
{
	global $DB, $APPLICATION, $CACHE_MANAGER;
	$strError = '';

	if($this->Init())
	{
		$isEmptyBucket = $this->service->IsEmptyBucket($this->arBucket);
		$forceDeleteTry = false;
		if (!$isEmptyBucket && is_object($APPLICATION->GetException()))
		{
			// The bucket was created within wrong s3 region
			if (
				$this->service->GetLastRequestStatus() == 301
				&& $this->service->GetLastRequestHeader('x-amz-bucket-region') != ''
			)
			{
				$forceDeleteTry = true;
			}
		}

		if ($isEmptyBucket || $forceDeleteTry)
		{
			$isDeleted = $this->service->DeleteBucket($this->arBucket);
			$forceDelete = false;
			if (!$isDeleted && is_object($APPLICATION->GetException()))
			{
				// The bucket was created within wrong s3 region
				if (
					$this->service->GetLastRequestStatus() == 301
					&& $this->service->GetLastRequestHeader('x-amz-bucket-region') != ''
				)
				{
					$forceDelete = true;
				}
			}

			if($isDeleted || $forceDelete)
			{
				$res = $DB->Query("DELETE FROM b_clouds_file_bucket WHERE ID = ".$this->_ID);
				if(CACHED_b_clouds_file_bucket !== false)
					$CACHE_MANAGER->CleanDir("b_clouds_file_bucket");
				if(is_object($res))
				{
					$this->arBucket = null;
					$this->_ID = 0;
					return true;
				}
				else
				{
					$strError = GetMessage("CLO_STORAGE_DB_DELETE_ERROR");
				}
			}
			else
			{
				$e = $APPLICATION->GetException();
				$strError = GetMessage("CLO_STORAGE_CLOUD_DELETE_ERROR", array("#error_msg#" => is_object($e)? $e->GetString(): ''));
			}
		}
		else
		{
			$e = $APPLICATION->GetException();
			if(is_object($e))
				$strError = GetMessage("CLO_STORAGE_CLOUD_DELETE_ERROR", array("#error_msg#" => $e->GetString()));
			else
				$strError = GetMessage("CLO_STORAGE_CLOUD_BUCKET_NOT_EMPTY");
		}
	}
	else
	{
		$strError = GetMessage("CLO_STORAGE_CLOUD_DELETE_ERROR", array("#error_msg#" => GetMessage("CLO_STORAGE_UNKNOWN_SERVICE")));
	}

	$APPLICATION->ResetException();
	$e = new CApplicationException($strError);
	$APPLICATION->ThrowException($e);
	return false;
}