/** * @param CWebDavTmpFile $file * @param $startRange * @param $endRange * @param $fileSize * @return bool * @throws WebDavTmpFileErrorException */ private function internalAppendCloud(CWebDavTmpFile $file, $startRange, $endRange, $fileSize) { $isLastChunk = $endRange + 1 == $fileSize; if (!CModule::IncludeModule("clouds")) { throw new WebDavTmpFileErrorException('Could not include clouds module'); } $bucket = $this->getBucket(); if ($endRange - $startRange + 1 != $bucket->getService()->getMinUploadPartSize() && !$isLastChunk) { throw new WebDavTmpFileErrorException('Error in size chunk. Must be equals ' . $bucket->getService()->getMinUploadPartSize() . ' if not last chunk'); } $upload = new CCloudStorageUpload($this->path . '/' . $this->filename); if (!$upload->isStarted()) { if (!$upload->start($bucket->ID, $fileSize)) { throw new WebDavTmpFileErrorException('Could not start cloud upload'); } } $success = false; $fileContent = $file->getContent(); if ($fileContent === false) { throw new WebDavTmpFileErrorException('Could not get contents file'); } $fails = 0; while ($upload->hasRetries()) { if ($upload->next($fileContent)) { $success = true; break; } $fails++; } if (!$success) { throw new WebDavTmpFileErrorException('Could not upload part of file for ' . $fails . ' times'); } elseif ($success && $isLastChunk) { if ($upload->finish()) { //we don't inc and don't dec //$bucket->incFileCounter($fileSize); } else { throw new WebDavTmpFileErrorException('Could not finish resumable upload'); } return true; } elseif ($success) { return true; } }