Exemplo n.º 1
0
	// Step 6: Send to the cloud 
	if($NS["step"] == 6)
	{
		if ($NS['BUCKET_ID'])
		{
			if (haveTime())
			{
				if (!CModule::IncludeModule('clouds'))
					RaiseErrorAndDie(GetMessage("MAIN_DUMP_NO_CLOUDS_MODULE"));

				$file_size = filesize($NS["arc_name"]);
				$obUpload = new CCloudStorageUpload(substr($NS['arc_name'],strlen(DOCUMENT_ROOT)));
				if (!$obUpload->isStarted())
				{
					if (!$obUpload->Start(intval($NS['BUCKET_ID']), $file_size))
					{
						if ($e = $APPLICATION->GetException())
							$strError = $e->GetString();
						else
							$strError = GetMessage('MAIN_DUMP_INT_CLOUD_ERR');
						RaiseErrorAndDie($strError);
					}
				}

				if ($fp = fopen($NS['arc_name'],'rb'))
				{
					fseek($fp, $obUpload->getPos());
					$part = fread($fp, $obUpload->getPartSize());
					fclose($fp);
					while($obUpload->hasRetries())
Exemplo n.º 2
0
         }
     } else {
         $obBucket = unserialize($NS['obBucket']);
     }
     $obBucket->Init();
     $obBucket->GetService()->setPublic(false);
     $bucket_id = $obBucket;
 } else {
     $obBucket = null;
     $bucket_id = $NS['BUCKET_ID'];
 }
 if (!$obUpload->isStarted()) {
     if (is_object($obBucket)) {
         $obBucket->setCheckWordHeader();
     }
     if (!$obUpload->Start($bucket_id, $file_size)) {
         if ($e = $APPLICATION->GetException()) {
             $strError = $e->GetString();
         } else {
             $strError = GetMessage('MAIN_DUMP_INT_CLOUD_ERR');
         }
         unset($NS['obBucket']);
         RaiseErrorAndDie($strError, true);
     }
     if (is_object($obBucket)) {
         $obBucket->unsetCheckWordHeader();
     }
 }
 if ($fp = fopen($NS['arc_name'], 'rb')) {
     fseek($fp, $obUpload->getPos());
     $part = fread($fp, $obUpload->getPartSize());
Exemplo n.º 3
0
     break;
 }
 $bytes = 0;
 $fileSize = $f->GetFileSize();
 if ($fileSize > $obBucket->GetService()->GetMinUploadPartSize()) {
     $obUpload = new CCloudStorageUpload($filePath);
     if (!$obUpload->isStarted()) {
         if ($obBucket->FileExists($filePath)) {
             $message = new CAdminMessage(GetMessage("CLO_STORAGE_FILE_UPLOAD_ERROR"), new CApplicationException(GetMessage("CLO_STORAGE_FILE_EXISTS_ERROR")));
             break;
         }
         $tempFile = CTempFile::GetDirectoryName(6, "clouds_upload") . $f->GetName();
         $tempFileX = $io->GetPhysicalName($tempFile);
         CheckDirPath($tempFileX);
         if (copy($_FILES["upload"]["tmp_name"], $tempFileX)) {
             if ($obUpload->Start($obBucket->ID, $fileSize, CFile::GetContentType($tempFile), $tempFile)) {
                 $moveResult = CCloudStorage::FILE_PARTLY_UPLOADED;
             } else {
                 $strError = GetMessage("CLO_STORAGE_FILE_UNKNOWN_ERROR", array("#CODE#" => "e01"));
             }
         } else {
             $strError = GetMessage("CLO_STORAGE_FILE_UNKNOWN_ERROR", array("#CODE#" => "e04"));
         }
     } else {
         $pos = $obUpload->getPos();
         if ($pos > $fileSize) {
             if ($obUpload->Finish()) {
                 $bytes = $fileSize;
                 $obBucket->IncFileCounter($fileSize);
                 @unlink($io->GetPhysicalName($f->GetPathWithName()));
                 $moveResult = CCloudStorage::FILE_MOVED;
Exemplo n.º 4
0
 public static function MoveFile($arFile, $obTargetBucket)
 {
     $io = CBXVirtualIo::GetInstance();
     //Try to find suitable bucket for the file
     $bucket = CCloudStorage::FindBucketForFile($arFile, $arFile["FILE_NAME"]);
     if (!is_object($bucket)) {
         return CCloudStorage::FILE_SKIPPED;
     }
     if (!$bucket->Init()) {
         return CCloudStorage::FILE_SKIPPED;
     }
     //Check if this is same bucket as the target
     if ($bucket->ID != $obTargetBucket->ID) {
         return CCloudStorage::FILE_SKIPPED;
     }
     if ($bucket->FileExists($bucket->GetFileSRC($arFile))) {
         //TODO rename file
         return CCloudStorage::FILE_SKIPPED;
     }
     $filePath = "/" . $arFile["SUBDIR"] . "/" . $arFile["FILE_NAME"];
     $filePath = preg_replace("#[\\\\\\/]+#", "/", $filePath);
     if ($arFile["FILE_SIZE"] > $bucket->GetService()->GetMinUploadPartSize()) {
         $obUpload = new CCloudStorageUpload($filePath);
         if (!$obUpload->isStarted()) {
             if ($arFile["HANDLER_ID"]) {
                 $ar = array();
                 if (!CCloudStorage::OnMakeFileArray($arFile, $ar)) {
                     return CCloudStorage::FILE_SKIPPED;
                 }
                 if (!isset($ar["tmp_name"])) {
                     return CCloudStorage::FILE_SKIPPED;
                 }
             } else {
                 $ar = CFile::MakeFileArray($arFile["ID"]);
                 if (!isset($ar["tmp_name"])) {
                     return CCloudStorage::FILE_SKIPPED;
                 }
             }
             $temp_file = CTempFile::GetDirectoryName(2, "clouds") . bx_basename($arFile["FILE_NAME"]);
             $temp_fileX = $io->GetPhysicalName($temp_file);
             CheckDirPath($temp_fileX);
             if (!copy($io->GetPhysicalName($ar["tmp_name"]), $temp_fileX)) {
                 return CCloudStorage::FILE_SKIPPED;
             }
             if ($obUpload->Start($bucket->ID, $arFile["FILE_SIZE"], $arFile["CONTENT_TYPE"], $temp_file)) {
                 return CCloudStorage::FILE_PARTLY_UPLOADED;
             } else {
                 return CCloudStorage::FILE_SKIPPED;
             }
         } else {
             $temp_file = $obUpload->getTempFileName();
             $temp_fileX = $io->GetPhysicalName($temp_file);
             $fp = fopen($temp_fileX, "rb");
             if (!is_resource($fp)) {
                 return CCloudStorage::FILE_SKIPPED;
             }
             $pos = $obUpload->getPos();
             if ($pos > filesize($temp_fileX)) {
                 if ($obUpload->Finish()) {
                     $bucket->IncFileCounter(filesize($temp_fileX));
                     if ($arFile["HANDLER_ID"]) {
                         CCloudStorage::OnFileDelete($arFile);
                     } else {
                         $ar = CFile::MakeFileArray($arFile["ID"]);
                         $fileNameX = $io->GetPhysicalName($ar["tmp_name"]);
                         unlink($fileNameX);
                         @rmdir(substr($fileNameX, 0, -strlen(bx_basename($fileNameX))));
                     }
                     return CCloudStorage::FILE_MOVED;
                 } else {
                     return CCloudStorage::FILE_SKIPPED;
                 }
             }
             fseek($fp, $pos);
             self::$part_count = $obUpload->GetPartCount();
             self::$part_size = $obUpload->getPartSize();
             $part = fread($fp, self::$part_size);
             while ($obUpload->hasRetries()) {
                 if ($obUpload->Next($part)) {
                     return CCloudStorage::FILE_PARTLY_UPLOADED;
                 }
             }
             return CCloudStorage::FILE_SKIPPED;
         }
     } else {
         if ($arFile["HANDLER_ID"]) {
             $ar = array();
             if (!CCloudStorage::OnMakeFileArray($arFile, $ar)) {
                 return CCloudStorage::FILE_SKIPPED;
             }
             if (!isset($ar["tmp_name"])) {
                 return CCloudStorage::FILE_SKIPPED;
             }
         } else {
             $ar = CFile::MakeFileArray($arFile["ID"]);
             if (!isset($ar["tmp_name"])) {
                 return CCloudStorage::FILE_SKIPPED;
             }
         }
         $res = $bucket->SaveFile($filePath, $ar);
         if ($res) {
             $bucket->IncFileCounter(filesize($ar["tmp_name"]));
             if (file_exists($ar["tmp_name"])) {
                 unlink($ar["tmp_name"]);
                 @rmdir(substr($ar["tmp_name"], 0, -strlen(bx_basename($ar["tmp_name"]))));
             }
             if ($arFile["HANDLER_ID"]) {
                 CCloudStorage::OnFileDelete($arFile);
             }
         } else {
             //delete temporary copy
             if ($arFile["HANDLER_ID"]) {
                 unlink($ar["tmp_name"]);
                 @rmdir(substr($ar["tmp_name"], 0, -strlen(bx_basename($ar["tmp_name"]))));
             }
         }
         return $res ? CCloudStorage::FILE_MOVED : CCloudStorage::FILE_SKIPPED;
     }
 }
Exemplo n.º 5
0
}

if (IntOption('dump_send_to_bucket_id'))
{
	ShowBackupStatus('Sending backup to the cloud...');
	if (!CModule::IncludeModule('clouds'))
		RaiseErrorAndDie(GetMessage("MAIN_DUMP_NO_CLOUDS_MODULE"));

	while(haveTime())
	{
	xdebug_start_trace();
		$file_size = filesize($NS["arc_name"]);
		$obUpload = new CCloudStorageUpload(substr($NS['arc_name'],strlen(DOCUMENT_ROOT)));
		if (!$obUpload->isStarted())
		{
			if (!$obUpload->Start(IntOption('dump_send_to_bucket_id'), $file_size))
			{
				if ($e = $APPLICATION->GetException())
					$strError = $e->GetString();
				else
					$strError = GetMessage('MAIN_DUMP_INT_CLOUD_ERR');
				RaiseErrorAndDie($strError);
			}
		}

		if (!$fp = fopen($NS['arc_name'],'rb'))
			RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_OPEN_FILE").$NS['arc_name']);

		while($obUpload->getPos() < $file_size)
		{
			$part = fread($fp, $obUpload->getPartSize());